Split 401

This commit is contained in:
Kilian committed 2024-07-28 03:04:26 +02:00
1 parent 73c7dc1b5e
commit 96bdbfc62a
15 files changed
+76 -74

No files matched your search

+1
View File
@@ -0,0 +1 @@
import{j as e,M as ce,a as U,T as y,u as K,b as _,D as q,c as P,G as g,d as we,e as V,B as v,f as G,g as w,C as O,h as b,L as k,A as Pe,i as ae,I as W,k as Se,l as L,P as I,m as Fe,n as Ae,o as ue,p as de,q as Ee,r as he,s as me,t as Te,S as N,v as De,w as ne,x as ke,y as $e,z as Le,E as Ie,F as Ue,H as qe,J as Oe}from"./mui-C4H8cxTH.js";import{u as M,a as B,b as se,c as H,d as Me,e as Be,L as $,f as ze,O as Re,g as z,q as J,h as re,i as Q,r as ee,Q as We,j as Ne,k as Qe,R as Ke,l as _e}from"./tanstack-C0csOcmc.js";import{c as Ve,r as f}from"./react-C_FdcE2X.js";import{i as R,B as Ge,a as He,b as Je,u as F,t as j,T as Xe}from"./i18n-DyW0LrNj.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))s(r);new MutationObserver(r=>{for(const l of r)if(l.type==="childList")for(const a of l.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&s(a)}).observe(document,{childList:!0,subtree:!0});function o(r){const l={};return r.integrity&&(l.integrity=r.integrity),r.referrerPolicy&&(l.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?l.credentials="include":r.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function s(r){if(r.ep)return;r.ep=!0;const l=o(r);fetch(r.href,l)}})();var te={},ie=Ve;te.createRoot=ie.createRoot,te.hydrateRoot=ie.hydrateRoot;const Y=15,Ze=3,A="https://khofmann.userpage.fu-berlin.de/phpCourse/exam/api/";let oe;class Ye{constructor(){if(this.userListeners=[],this.hasAuth=()=>this.token!==void 0,this.isAdmin=()=>{var n;return this.hasAuth()&&((n=this.self)==null?void 0:n.isAdmin)},this.getAuthenticatedUser=()=>this.self,this.getCurrentSession=()=>[this.token,this.refreshToken],this.subscribeToAuthenticatedUser=n=>(this.userListeners.push(n),()=>{this.userListeners=this.userListeners.filter(o=>o!==n)}),this.logIn=async(n,o)=>{const{user:s,token:r}=await(await this.post("login",{email:n,password:o})).json();this.self=s,this.token=r,this.userListeners.forEach(l=>l(s))},this.logOut=async()=>{try{return this.token?await(await this.postAuth("logout")).json():!0}catch{return!1}finally{this.self=void 0,this.token=void 0,this.userListeners.forEach(n=>n())}},this.posts=async n=>{const o=`posts?p=${n??0}&l=${Y}`;return this.token?await(await this.getAuth(o)).json():await(await this.get(o)).json()},this.deletePost=async n=>await(await this.delete(`posts/${n}?l=${Y}`)).json(),this.user=async n=>{var o;return await(await this.getAuth(`users/${n??((o=this.self)==null?void 0:o.id)}`)).json()},this.updateUser=async(n,o)=>{const s=await(await this.patch(`users/${o??"self"}`,n)).json();return this.self=s,this.userListeners.forEach(r=>r(s)),s},this.updateUserImage=async(n,o)=>{const s=new FormData;n.image&&s.append("image",n.image),!n.image&&n.predefined&&s.append("predefined",n.predefined);const r=await(await this.postAuthRaw(`users/${o??"self"}/image`,s)).json();return this.self=r,this.userListeners.forEach(l=>l(r)),r},this.newPost=async n=>await(await this.postAuth(`posts?l=${Y}`,n)).json(),this.updatePost=async(n,o)=>await(await this.patch(`posts/${o}`,n)).json(),this.userPosts=async n=>await(await this.getAuth(`users/${n}/posts?l=${Ze}&s=desc`)).json(),this.createUser=async n=>await(await this.post("register",n)).json(),this.post=async(n,o,s)=>{const r=await fetch(`${A}${n}`,{mode:"cors",method:"post",headers:s,body:JSON.stringify(o)});if(r.ok)return r;throw await r.json()},this.postAuth=async(n,o,s)=>{const r=await fetch(`${A}${n}`,{mode:"cors",method:"post",headers:{token:this.token??"",...s},body:JSON.stringify(o)});if(r.ok)return r;throw await r.json()},this.postAuthRaw=async(n,o,s)=>{const r=await fetch(`${A}${n}`,{mode:"cors",method:"post",headers:{token:this.token??"",...s},body:o});if(r.ok)return r;throw await r.json()},this.get=async(n,o)=>{const s=await fetch(`${A}${n}`,{mode:"cors",method:"get",headers:o});if(s.ok)return s;throw await s.json()},this.getAuth=async(n,o)=>{const s=await fetch(`${A}${n}`,{mode:"cors",method:"get",headers:{token:this.token??"",...o}});if(s.ok)return s;throw await s.json()},this.delete=async(n,o)=>{const s=await fetch(`${A}${n}`,{mode:"cors",method:"delete",headers:{token:this.token??"",...o}});if(s.ok)return s;throw await s.json()},this.patch=async(n,o,s)=>{const r=await fetch(`${A}${n}`,{mode:"cors",method:"patch",headers:{token:this.token??"",...s},body:JSON.stringify(o)});if(r.ok)return r;throw await r.json()},oe)throw new Error("New instance cannot be created!!");oe=this}}const p=new Ye;var E=(t=>(t.NOT_FOUND="NotFound",t.UNAUTHORIZED="Unauthorized",t.NOT_ALLOWED="NotAllowed",t.FAILED_UPDATE="FailedUpdate",t.MISSING_FIELD="MissingField",t.DUPLICATE="Duplicate",t))(E||{});R.use(Ge).use(He).use(Je).init({fallbackLng:"en",debug:!1,interpolation:{escapeValue:!1},backend:{loadPath:"/phpCourse/exam/dist/locales/{{lng}}/{{ns}}.json"}});const et=({anchorEl:t,handleClose:n})=>e.jsxs(ce,{anchorEl:t,anLine truncated
-1
View File
@@ -1 +0,0 @@
import{j as e,M as ce,a as L,T as y,u as N,b as K,D as q,c as S,G as g,d as we,e as _,B as v,f as V,g as b,C as M,h as w,L as k,A as Pe,i as ae,I as z,k as Se,l as $,P as U,m as Fe,n as Ae,o as ue,p as de,q as Ee,r as he,s as me,t as Te,S as Q,v as De,w as ne,x as ke,y as Ie,z as $e,E as Ue,F as Le,H as qe,J as Me}from"./mui-C4H8cxTH.js";import{u as O,a as B,b as se,c as X,d as Oe,e as Be,L as I,f as Re,O as ze,g as Qe,r as G,h as H,q as J,i as re,j as W,Q as We,k as Ne,l as Ke,R as _e,m as Ve}from"./tanstack-Duf7jkFs.js";import{c as He,r as f}from"./react-C_FdcE2X.js";import{i as R,B as Ge,a as Xe,b as Je,u as F,t as j,T as Ze}from"./i18n-DyW0LrNj.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const l of s)if(l.type==="childList")for(const a of l.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&r(a)}).observe(document,{childList:!0,subtree:!0});function o(s){const l={};return s.integrity&&(l.integrity=s.integrity),s.referrerPolicy&&(l.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?l.credentials="include":s.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function r(s){if(s.ep)return;s.ep=!0;const l=o(s);fetch(s.href,l)}})();var te={},ie=He;te.createRoot=ie.createRoot,te.hydrateRoot=ie.hydrateRoot;const ee=15,Ye=3,A="https://khofmann.userpage.fu-berlin.de/phpCourse/exam/api/";let oe;class et{constructor(){if(this.userListeners=[],this.hasAuth=()=>this.token!==void 0,this.isAdmin=()=>{var n;return this.hasAuth()&&((n=this.self)==null?void 0:n.isAdmin)},this.getAuthenticatedUser=()=>this.self,this.getCurrentSession=()=>[this.token,this.refreshToken],this.subscribeToAuthenticatedUser=n=>(this.userListeners.push(n),()=>{this.userListeners=this.userListeners.filter(o=>o!==n)}),this.logIn=async(n,o)=>{const{user:r,token:s}=await(await this.post("login",{email:n,password:o})).json();this.self=r,this.token=s,this.userListeners.forEach(l=>l(r))},this.logOut=async()=>{try{return await(await this.postAuth("logout")).json()}catch{return!1}finally{this.self=void 0,this.token=void 0,this.userListeners.forEach(n=>n())}},this.posts=async n=>{const o=`posts?p=${n??0}&l=${ee}`;return this.token?await(await this.getAuth(o)).json():await(await this.get(o)).json()},this.deletePost=async n=>await(await this.delete(`posts/${n}?l=${ee}`)).json(),this.user=async n=>{var o;return await(await this.getAuth(`users/${n??((o=this.self)==null?void 0:o.id)}`)).json()},this.updateUser=async(n,o)=>{const r=await(await this.patch(`users/${o??"self"}`,n)).json();return this.self=r,this.userListeners.forEach(s=>s(r)),r},this.updateUserImage=async(n,o)=>{const r=new FormData;n.image&&r.append("image",n.image),!n.image&&n.predefined&&r.append("predefined",n.predefined);const s=await(await this.postAuthRaw(`users/${o??"self"}/image`,r)).json();return this.self=s,this.userListeners.forEach(l=>l(s)),s},this.newPost=async n=>await(await this.postAuth(`posts?l=${ee}`,n)).json(),this.updatePost=async(n,o)=>await(await this.patch(`posts/${o}`,n)).json(),this.userPosts=async n=>await(await this.getAuth(`users/${n}/posts?l=${Ye}&s=desc`)).json(),this.createUser=async n=>await(await this.post("register",n)).json(),this.post=async(n,o,r)=>{const s=await fetch(`${A}${n}`,{mode:"cors",method:"post",headers:r,body:JSON.stringify(o)});if(s.ok)return s;throw await s.json()},this.postAuth=async(n,o,r)=>{const s=await fetch(`${A}${n}`,{mode:"cors",method:"post",headers:{token:this.token??"",...r},body:JSON.stringify(o)});if(s.ok)return s;throw await s.json()},this.postAuthRaw=async(n,o,r)=>{const s=await fetch(`${A}${n}`,{mode:"cors",method:"post",headers:{token:this.token??"",...r},body:o});if(s.ok)return s;throw await s.json()},this.get=async(n,o)=>{const r=await fetch(`${A}${n}`,{mode:"cors",method:"get",headers:o});if(r.ok)return r;throw await r.json()},this.getAuth=async(n,o)=>{const r=await fetch(`${A}${n}`,{mode:"cors",method:"get",headers:{token:this.token??"",...o}});if(r.ok)return r;throw await r.json()},this.delete=async(n,o)=>{const r=await fetch(`${A}${n}`,{mode:"cors",method:"delete",headers:{token:this.token??"",...o}});if(r.ok)return r;throw await r.json()},this.patch=async(n,o,r)=>{const s=await fetch(`${A}${n}`,{mode:"cors",method:"patch",headers:{token:this.token??"",...r},body:JSON.stringify(o)});if(s.ok)return s;throw await s.json()},oe)throw new Error("New instance cannot be created!!");oe=this}}const p=new et;var E=(t=>(t.NOT_FOUND="NotFound",t.UNAUTHORIZED="Unauthorized",t.FAILED_UPDATE="FailedUpdate",t.MISSING_FIELD="MissingField",t.DUPLICATE="Duplicate",t))(E||{});R.use(Ge).use(Xe).use(Je).init({fallbackLng:"en",debug:!1,interpolation:{escapeValue:!1},backend:{loadPath:"/phpCourse/exam/dist/locales/{{lng}}/{{ns}}.json"}});const tt=({anchorEl:t,handleClose:n})=>e.jsxs(ce,{anchorEl:t,anchorOrigin:{vertical:"bottom",Line truncated
@@ -14,4 +14,4 @@ var ws=e=>{throw TypeError(e)};var ze=(e,t,s)=>t.has(e)||ws("Cannot "+s);var l=(
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var $e=C,Rr=Cr;function Er(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var xr=typeof Object.is=="function"?Object.is:Er,Or=Rr.useSyncExternalStore,Lr=$e.useRef,Ar=$e.useEffect,Tr=$e.useMemo,Ir=$e.useDebugValue;Si.useSyncExternalStoreWithSelector=function(e,t,s,i,r){var n=Lr(null);if(n.current===null){var o={hasValue:!1,value:null};n.current=o}else o=n.current;n=Tr(function(){function h(p){if(!u){if(u=!0,c=p,p=i(p),r!==void 0&&o.hasValue){var v=o.value;if(r(v,p))return d=v}return d=p}if(v=d,xr(c,p))return v;var m=i(p);return r!==void 0&&r(v,m)?v:(c=p,d=m)}var u=!1,c,d,f=s===void 0?null:s;return[function(){return h(t())},f===null?void 0:function(){return h(f())}]},[t,s,i,r]);var a=Or(e,n[0],n[1]);return Ar(function(){o.hasValue=!0,o.value=a},[a]),Ir(a),a};bi.exports=Si;var Vr=bi.exports;class bs{constructor(t,s){this.listeners=new Set,this._batching=!1,this._flushing=0,this.subscribe=i=>{var r,n;this.listeners.add(i);const o=(n=(r=this.options)==null?void 0:r.onSubscribe)==null?void 0:n.call(r,i,this);return()=>{this.listeners.delete(i),o==null||o()}},this.setState=i=>{var r,n,o;const a=this.state;this.state=(r=this.options)!=null&&r.updateFn?this.options.updateFn(a)(i):i(a),(o=(n=this.options)==null?void 0:n.onUpdate)==null||o.call(n),this._flush()},this._flush=()=>{if(this._batching)return;const i=++this._flushing;this.listeners.forEach(r=>{this._flushing===i&&r()})},this.batch=i=>{if(this._batching)return i();this._batching=!0,i(),this._batching=!1,this._flush()},this.state=t,this.options=s}}function Ve(e,t=s=>s){return Vr.useSyncExternalStoreWithSelector(e.subscribe,()=>e.state,()=>e.state,t,jr)}function jr(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;const s=Object.keys(e);if(s.length!==Object.keys(t).length)return!1;for(let i=0;i<s.length;i++)if(!Object.prototype.hasOwnProperty.call(t,s[i])||!Object.is(e[s[i]],t[s[i]]))return!1;return!0}const rt="__root__";function Dr(e,t){let s,i,r,n="";for(s in e)if((r=e[s])!==void 0)if(Array.isArray(r))for(i=0;i<r.length;i++)n&&(n+="&"),n+=encodeURIComponent(s)+"="+encodeURIComponent(r[i]);else n&&(n+="&"),n+=encodeURIComponent(s)+"="+encodeURIComponent(r);return""+n}function Ts(e){if(!e)return"";const t=decodeURIComponent(e);return t==="false"?!1:t==="true"?!0:+t*0===0&&+t+""===t?+t:t}function kr(e,t){let s,i;const r={},n=e.split("&");for(;s=n.shift();){const o=s.indexOf("=");if(o!==-1){i=s.slice(0,o);const a=s.slice(o+1);r[i]!==void 0?r[i]=[].concat(r[i],Ts(a)):r[i]=Ts(a)}else i=s,r[i]=""}return r}const Br=Ur(JSON.parse),$r=Qr(JSON.stringify,JSON.parse);function Ur(e){return t=>{t.substring(0,1)==="?"&&(t=t.substring(1));const s=kr(t);for(const i in s){const r=s[i];if(typeof r=="string")try{s[i]=e(r)}catch{}}return s}}function Qr(e,t){function s(i){if(typeof i=="object"&&i!==null)try{return e(i)}catch{}else if(typeof i=="string"&&typeof t=="function")try{return t(i),e(i)}catch{}return i}return i=>{i={...i},Object.keys(i).forEach(n=>{const o=i[n];typeof o>"u"||o===void 0?delete i[n]:i[n]=s(o)});const r=Dr(i).toString();return r?`?${r}`:""}}function je(e){return e[e.length-1]}function Kr(e){return typeof e=="function"}function Jt(e,t){return Kr(e)?e(t):e}function be(e,t){return t.reduce((s,i)=>(s[i]=e[i],s),{})}function pt(e,t){if(e===t)return e;const s=t,i=Vs(e)&&Vs(s);if(i||De(e)&&De(s)){const r=i?e:Object.keys(e),n=r.length,o=i?s:Object.keys(s),a=o.length,h=i?[]:{};let u=0;for(let c=0;c<a;c++){const d=i?c:o[c];(!i&&r.includes(d)||i)&&e[d]===void 0&&s[d]===void 0?(h[d]=void 0,u++):(h[d]=pt(e[d],s[d]),h[d]===e[d]&&e[d]!==void 0&&u++)}return n===a&&u===n?e:h}return s}function De(e){if(!Is(e))return!1;const t=e.constructor;if(typeof t>"u")return!0;const s=t.prototype;return!(!Is(s)||!s.hasOwnProperty("isPrototypeOf"))}function Is(e){return Object.prototype.toString.call(e)==="[object Object]"}function Vs(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function Yt(e,t,s=!1){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(De(e)&&De(t)){const i=Object.keys(e).filter(n=>e[n]!==void 0),r=Object.keys(t).filter(n=>t[n]!==void 0);return!s&&i.length!==r.length?!1:!r.some(n=>!(n in e)||!Yt(e[n],t[n],s))}return Array.isArray(e)&&Array.isArray(t)?e.length!==t.length?!1:!e.some((i,r)=>!Yt(i,t[r],s)):!1}const Je=typeof window<"u"?C.useLayoutEffect:C.useEffect;function Gt(e){let t,s;const i=new Promise((r,n)=>{t=r,s=n});return i.status="pending",i.resolve=r=>{i.status="resolved",i.value=r,t(r),e==null||e(r)},i.reject=r=>{i.status="rejected",s(r)},i}function js(e){const t=C.useRef({value:e,prev:null}),s=t.current.value;return e!==s&&(t.current={value:e,prev:s}),t.current.prev}function Vt(e){return Ue(e.filter(Boolean).join("/"))}function Ue(e){return e.replace(/\/{2,}/g,"/")}function Ss(e){return e==="/"?e:e.replace(/^\/{1,}/,"")}function Bt(e){return e==="/"?e:e.replace(/\/{1,}$/,"")}function Nr(e){return Bt(Ss(e))}function ke(e,t){return e.endsWith("/")&&e!=="/"&&e!==`${t}/`?e.slice(0,-1):e}functLine truncated
*/var $e=C,Rr=Cr;function Er(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var xr=typeof Object.is=="function"?Object.is:Er,Or=Rr.useSyncExternalStore,Lr=$e.useRef,Ar=$e.useEffect,Tr=$e.useMemo,Ir=$e.useDebugValue;Si.useSyncExternalStoreWithSelector=function(e,t,s,i,r){var n=Lr(null);if(n.current===null){var o={hasValue:!1,value:null};n.current=o}else o=n.current;n=Tr(function(){function h(p){if(!u){if(u=!0,c=p,p=i(p),r!==void 0&&o.hasValue){var v=o.value;if(r(v,p))return d=v}return d=p}if(v=d,xr(c,p))return v;var m=i(p);return r!==void 0&&r(v,m)?v:(c=p,d=m)}var u=!1,c,d,f=s===void 0?null:s;return[function(){return h(t())},f===null?void 0:function(){return h(f())}]},[t,s,i,r]);var a=Or(e,n[0],n[1]);return Ar(function(){o.hasValue=!0,o.value=a},[a]),Ir(a),a};bi.exports=Si;var Vr=bi.exports;class bs{constructor(t,s){this.listeners=new Set,this._batching=!1,this._flushing=0,this.subscribe=i=>{var r,n;this.listeners.add(i);const o=(n=(r=this.options)==null?void 0:r.onSubscribe)==null?void 0:n.call(r,i,this);return()=>{this.listeners.delete(i),o==null||o()}},this.setState=i=>{var r,n,o;const a=this.state;this.state=(r=this.options)!=null&&r.updateFn?this.options.updateFn(a)(i):i(a),(o=(n=this.options)==null?void 0:n.onUpdate)==null||o.call(n),this._flush()},this._flush=()=>{if(this._batching)return;const i=++this._flushing;this.listeners.forEach(r=>{this._flushing===i&&r()})},this.batch=i=>{if(this._batching)return i();this._batching=!0,i(),this._batching=!1,this._flush()},this.state=t,this.options=s}}function Ve(e,t=s=>s){return Vr.useSyncExternalStoreWithSelector(e.subscribe,()=>e.state,()=>e.state,t,jr)}function jr(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;const s=Object.keys(e);if(s.length!==Object.keys(t).length)return!1;for(let i=0;i<s.length;i++)if(!Object.prototype.hasOwnProperty.call(t,s[i])||!Object.is(e[s[i]],t[s[i]]))return!1;return!0}const rt="__root__";function Dr(e,t){let s,i,r,n="";for(s in e)if((r=e[s])!==void 0)if(Array.isArray(r))for(i=0;i<r.length;i++)n&&(n+="&"),n+=encodeURIComponent(s)+"="+encodeURIComponent(r[i]);else n&&(n+="&"),n+=encodeURIComponent(s)+"="+encodeURIComponent(r);return""+n}function Ts(e){if(!e)return"";const t=decodeURIComponent(e);return t==="false"?!1:t==="true"?!0:+t*0===0&&+t+""===t?+t:t}function kr(e,t){let s,i;const r={},n=e.split("&");for(;s=n.shift();){const o=s.indexOf("=");if(o!==-1){i=s.slice(0,o);const a=s.slice(o+1);r[i]!==void 0?r[i]=[].concat(r[i],Ts(a)):r[i]=Ts(a)}else i=s,r[i]=""}return r}const Br=Ur(JSON.parse),$r=Qr(JSON.stringify,JSON.parse);function Ur(e){return t=>{t.substring(0,1)==="?"&&(t=t.substring(1));const s=kr(t);for(const i in s){const r=s[i];if(typeof r=="string")try{s[i]=e(r)}catch{}}return s}}function Qr(e,t){function s(i){if(typeof i=="object"&&i!==null)try{return e(i)}catch{}else if(typeof i=="string"&&typeof t=="function")try{return t(i),e(i)}catch{}return i}return i=>{i={...i},Object.keys(i).forEach(n=>{const o=i[n];typeof o>"u"||o===void 0?delete i[n]:i[n]=s(o)});const r=Dr(i).toString();return r?`?${r}`:""}}function je(e){return e[e.length-1]}function Kr(e){return typeof e=="function"}function Jt(e,t){return Kr(e)?e(t):e}function be(e,t){return t.reduce((s,i)=>(s[i]=e[i],s),{})}function pt(e,t){if(e===t)return e;const s=t,i=Vs(e)&&Vs(s);if(i||De(e)&&De(s)){const r=i?e:Object.keys(e),n=r.length,o=i?s:Object.keys(s),a=o.length,h=i?[]:{};let u=0;for(let c=0;c<a;c++){const d=i?c:o[c];(!i&&r.includes(d)||i)&&e[d]===void 0&&s[d]===void 0?(h[d]=void 0,u++):(h[d]=pt(e[d],s[d]),h[d]===e[d]&&e[d]!==void 0&&u++)}return n===a&&u===n?e:h}return s}function De(e){if(!Is(e))return!1;const t=e.constructor;if(typeof t>"u")return!0;const s=t.prototype;return!(!Is(s)||!s.hasOwnProperty("isPrototypeOf"))}function Is(e){return Object.prototype.toString.call(e)==="[object Object]"}function Vs(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function Yt(e,t,s=!1){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(De(e)&&De(t)){const i=Object.keys(e).filter(n=>e[n]!==void 0),r=Object.keys(t).filter(n=>t[n]!==void 0);return!s&&i.length!==r.length?!1:!r.some(n=>!(n in e)||!Yt(e[n],t[n],s))}return Array.isArray(e)&&Array.isArray(t)?e.length!==t.length?!1:!e.some((i,r)=>!Yt(i,t[r],s)):!1}const Je=typeof window<"u"?C.useLayoutEffect:C.useEffect;function Gt(e){let t,s;const i=new Promise((r,n)=>{t=r,s=n});return i.status="pending",i.resolve=r=>{i.status="resolved",i.value=r,t(r),e==null||e(r)},i.reject=r=>{i.status="rejected",s(r)},i}function js(e){const t=C.useRef({value:e,prev:null}),s=t.current.value;return e!==s&&(t.current={value:e,prev:s}),t.current.prev}function Vt(e){return Ue(e.filter(Boolean).join("/"))}function Ue(e){return e.replace(/\/{2,}/g,"/")}function Ss(e){return e==="/"?e:e.replace(/^\/{1,}/,"")}function Bt(e){return e==="/"?e:e.replace(/\/{1,}$/,"")}function Nr(e){return Bt(Ss(e))}function ke(e,t){return e.endsWith("/")&&e!=="/"&&e!==`${t}/`?e.slice(0,-1):e}functLine truncated
+2 -2
View File
@@ -5,10 +5,10 @@
<link rel="icon" type="image/svg+xml" href="/phpCourse/exam/dist/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<script type="module" crossorigin src="/phpCourse/exam/dist/assets/index-tFNBNNKb.js"></script>
<script type="module" crossorigin src="/phpCourse/exam/dist/assets/index-B93xlZhH.js"></script>
<link rel="modulepreload" crossorigin href="/phpCourse/exam/dist/assets/react-C_FdcE2X.js">
<link rel="modulepreload" crossorigin href="/phpCourse/exam/dist/assets/mui-C4H8cxTH.js">
<link rel="modulepreload" crossorigin href="/phpCourse/exam/dist/assets/tanstack-Duf7jkFs.js">
<link rel="modulepreload" crossorigin href="/phpCourse/exam/dist/assets/tanstack-C0csOcmc.js">
<link rel="modulepreload" crossorigin href="/phpCourse/exam/dist/assets/i18n-DyW0LrNj.js">
<link rel="stylesheet" crossorigin href="/phpCourse/exam/dist/assets/mui-CKDNpdid.css">
<link rel="stylesheet" crossorigin href="/phpCourse/exam/dist/assets/index-D83Ey19k.css">
+5 -5
View File
@@ -1,23 +1,23 @@
{
"Unauthorized": "Keine Berechtigung",
"Unauthorized_login": "Ungültige E-Mail oder Passwort",
"NotAllowed_login": "Ungültige E-Mail oder Passwort",
"NotFound_user:login": "Benutzer existiert nicht",
"MissingField_email:login": "E-Mail darf nicht leer sein",
"MissingField_password:login": "Passwort darf nicht leer sein",
"Unauthorized_deletePost": "Keine Berechtigung",
"NotAllowed_deletePost": "Keine Berechtigung",
"NotFound_post:deletePost": "Post nicht gefunden",
"Unauthorized_userUpdate": "Keine Berechtigung",
"NotAllowed_userUpdate": "Keine Berechtigung",
"NotFound_user:userUpdate": "Benutzer nicht gefunden",
"FailedUpdate_Duplicate:username:userUpdate": "Ein Benutzer mit diesem Benutzernamen existiert schon",
"FailedUpdate_Duplicate:email:userUpdate": "Ein Benutzer mit dieser E-Mail existiert schon",
"Unauthorized_newPost": "Keine Berechtigung",
"NotAllowed_newPost": "Keine Berechtigung",
"MissingField_content:newPost": "Beitrag darf nicht leer sein",
"Unauthorized_postUpdate": "Keine Berechtigung",
"NotAllowed_postUpdate": "Keine Berechtigung",
"NotFound_post:postUpdate": "Post nicht gefunden",
"Duplicate_user:register": "Ein Benutzer mit diesem Benutzernamen oder E-Mail existiert schon",
+6 -6
View File
@@ -1,23 +1,23 @@
{
"Unauthorized": "Unauthorized",
"Unauthorized": "NotAllowed",
"Unauthorized_login": "Invalid email or password",
"NotAllowed_login": "Invalid email or password",
"NotFound_user:login": "User does not exist",
"MissingField_email:login": "E-Mail required",
"MissingField_password:login": "Password required",
"Unauthorized_deletPost": "Unauthorized",
"NotAllowed_deletPost": "NotAllowed",
"NotFound_post:deletePost": "Post not found",
"Unauthorized_userUpdate": "Unauthorized",
"NotAllowed_userUpdate": "NotAllowed",
"NotFound_user:userUpdate": "User not found",
"FailedUpdate_Duplicate:userUpdate": "A user with this username already exists",
"FailedUpdate_Duplicate:email:userUpdate": "A user with this email already exists",
"Unauthorized_newPost": "Unauthorized",
"NotAllowed_newPost": "NotAllowed",
"MissingField_content:newPost": "Content required",
"Unauthorized_postUpdate": "Unauthorized",
"NotAllowed_postUpdate": "NotAllowed",
"NotFound_post:postUpdate": "Post not found",
"Duplicate_user:register": "A user with this username or email already exists",
+1 -1
View File
@@ -4822,7 +4822,7 @@ var drawChart = (function (exports) {
</script>
<script>
/*<!--*/
const data = {"version":2,"tree":{"name":"root","children":[{"name":"assets/zustand-DA8f69qW.js","children":[{"name":"\u0000/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.3.1/node_modules/use-sync-external-store","children":[{"name":"cjs","children":[{"uid":"7073d250-1","name":"use-sync-external-store-shim.production.min.js?commonjs-exports"},{"uid":"7073d250-5","name":"use-sync-external-store-shim.production.min.js?commonjs-proxy"},{"name":"use-sync-external-store-shim","children":[{"uid":"7073d250-13","name":"with-selector.production.min.js?commonjs-exports"},{"uid":"7073d250-17","name":"with-selector.production.min.js?commonjs-proxy"}]}]},{"name":"shim","children":[{"uid":"7073d250-7","name":"index.js?commonjs-module"},{"uid":"7073d250-11","name":"index.js?commonjs-proxy"},{"uid":"7073d250-19","name":"with-selector.js?commonjs-module"}]}]},{"name":"node_modules/.pnpm","children":[{"name":"use-sync-external-store@1.2.0_react@18.3.1/node_modules/use-sync-external-store","children":[{"name":"cjs","children":[{"uid":"7073d250-3","name":"use-sync-external-store-shim.production.min.js"},{"name":"use-sync-external-store-shim/with-selector.production.min.js","uid":"7073d250-15"}]},{"name":"shim","children":[{"uid":"7073d250-9","name":"index.js"},{"uid":"7073d250-21","name":"with-selector.js"}]}]},{"name":"zustand@4.5.4_@types+react@18.3.3_react@18.3.1/node_modules/zustand/esm","children":[{"uid":"7073d250-23","name":"vanilla.mjs"},{"uid":"7073d250-25","name":"index.mjs"}]}]}]},{"name":"assets/index-tFNBNNKb.js","children":[{"name":"\u0000vite/modulepreload-polyfill.js","uid":"7073d250-27"},{"name":"\u0000/node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/client.js?commonjs-exports","uid":"7073d250-29"},{"name":"node_modules/.pnpm","children":[{"name":"react-dom@18.3.1_react@18.3.1/node_modules/react-dom/client.js","uid":"7073d250-31"},{"name":"@fontsource+roboto@5.0.13/node_modules/@fontsource/roboto","children":[{"uid":"7073d250-83","name":"300.css"},{"uid":"7073d250-85","name":"400.css"},{"uid":"7073d250-87","name":"500.css"},{"uid":"7073d250-89","name":"700.css"}]}]},{"name":"src","children":[{"uid":"7073d250-33","name":"constanst.ts"},{"name":"api/Api.ts","uid":"7073d250-35"},{"name":"components","children":[{"name":"Error","children":[{"uid":"7073d250-37","name":"Errors.ts"},{"uid":"7073d250-45","name":"ErrorComponent.tsx"}]},{"name":"Menus","children":[{"name":"Language/LanguageMenu.tsx","uid":"7073d250-41"},{"name":"User/UserMenu.tsx","uid":"7073d250-51"}]},{"name":"Dialogs","children":[{"name":"Register/RegisterDialog.tsx","uid":"7073d250-47"},{"name":"PostEdit/PostEditDialog.tsx","uid":"7073d250-61"},{"name":"UserEdit/UserEditDialog.tsx","uid":"7073d250-69"},{"name":"UserImage/UserImageDialog.tsx","uid":"7073d250-71"}]},{"name":"Forms","children":[{"name":"Login/LoginForm.tsx","uid":"7073d250-49"},{"name":"Post/PostForm.tsx","uid":"7073d250-57"}]},{"name":"Header/Header.tsx","uid":"7073d250-53"},{"name":"Post/Post.tsx","uid":"7073d250-63"},{"name":"Profile/Profile.tsx","uid":"7073d250-73"}]},{"uid":"7073d250-39","name":"i18n.ts"},{"name":"types/Routes.ts","uid":"7073d250-43"},{"name":"routes","children":[{"uid":"7073d250-55","name":"__root.tsx"},{"uid":"7073d250-67","name":"index.tsx"},{"name":"profile","children":[{"uid":"7073d250-77","name":"index.tsx"},{"uid":"7073d250-79","name":"$id.tsx"}]}]},{"name":"utils/date.ts","uid":"7073d250-59"},{"name":"queries","children":[{"uid":"7073d250-65","name":"postsQuery.ts"},{"uid":"7073d250-75","name":"profileQuery.ts"}]},{"uid":"7073d250-81","name":"routeTree.gen.ts"},{"uid":"7073d250-91","name":"main.tsx"}]},{"uid":"7073d250-93","name":"index.html"}]},{"name":"assets/i18n-DyW0LrNj.js","children":[{"name":"node_modules/.pnpm","children":[{"name":"void-elements@3.1.0/node_modules/void-elements/index.js","uid":"7073d250-95"},{"name":"html-parse-stringify@3.0.1/node_modules/html-parse-stringify/dist/html-parse-stringify.module.js","uid":"7073d250-97"},{"name":"react-i18next@15.0.0_i18next@23.12.2_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-i18next/dist/es","children":[{"uid":"7073d250-99","name":"utils.js"},{"uid":"7073d250-101","name":"unescape.js"},{"uid":"7073d250-103","name":"defaults.js"},{"uid":"7073d250-105","name":"i18nInstance.js"},{"uid":"7073d250-107","name":"TransWithoutContext.js"},{"uid":"7073d250-109","name":"initReactI18next.js"},{"uid":"7073d250-111","name":"context.js"},{"uid":"7073d250-113","name":"Trans.js"},{"uid":"7073d250-115","name":"useTranslation.js"},{"uid":"7073d250-117","name":"withTranslation.js"},{"uid":"7073d250-119","name":"Translation.js"},{"uid":"7073d250-121","name":"I18nextProvider.js"},{"uid":"7073d250-123","name":"useSSR.js"},{"uid":"7073d250-125","name":"withSSR.js"},{"uid":"7073d250-127","name":"index.js"}]},{"name":"i18next@23.12.2/node_modules/i18next/dist/esm/i18next.js","uid":"7073d250-129"},{"name":"i18next-browser-languagedetector@8.0.0/node_modules/i18next-broLine truncated
const data = {"version":2,"tree":{"name":"root","children":[{"name":"assets/zustand-DA8f69qW.js","children":[{"name":"\u0000/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.3.1/node_modules/use-sync-external-store","children":[{"name":"cjs","children":[{"uid":"fcf8be1e-1","name":"use-sync-external-store-shim.production.min.js?commonjs-exports"},{"uid":"fcf8be1e-5","name":"use-sync-external-store-shim.production.min.js?commonjs-proxy"},{"name":"use-sync-external-store-shim","children":[{"uid":"fcf8be1e-13","name":"with-selector.production.min.js?commonjs-exports"},{"uid":"fcf8be1e-17","name":"with-selector.production.min.js?commonjs-proxy"}]}]},{"name":"shim","children":[{"uid":"fcf8be1e-7","name":"index.js?commonjs-module"},{"uid":"fcf8be1e-11","name":"index.js?commonjs-proxy"},{"uid":"fcf8be1e-19","name":"with-selector.js?commonjs-module"}]}]},{"name":"node_modules/.pnpm","children":[{"name":"use-sync-external-store@1.2.0_react@18.3.1/node_modules/use-sync-external-store","children":[{"name":"cjs","children":[{"uid":"fcf8be1e-3","name":"use-sync-external-store-shim.production.min.js"},{"name":"use-sync-external-store-shim/with-selector.production.min.js","uid":"fcf8be1e-15"}]},{"name":"shim","children":[{"uid":"fcf8be1e-9","name":"index.js"},{"uid":"fcf8be1e-21","name":"with-selector.js"}]}]},{"name":"zustand@4.5.4_@types+react@18.3.3_react@18.3.1/node_modules/zustand/esm","children":[{"uid":"fcf8be1e-23","name":"vanilla.mjs"},{"uid":"fcf8be1e-25","name":"index.mjs"}]}]}]},{"name":"assets/index-B93xlZhH.js","children":[{"name":"\u0000vite/modulepreload-polyfill.js","uid":"fcf8be1e-27"},{"name":"\u0000/node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/client.js?commonjs-exports","uid":"fcf8be1e-29"},{"name":"node_modules/.pnpm","children":[{"name":"react-dom@18.3.1_react@18.3.1/node_modules/react-dom/client.js","uid":"fcf8be1e-31"},{"name":"@fontsource+roboto@5.0.13/node_modules/@fontsource/roboto","children":[{"uid":"fcf8be1e-83","name":"300.css"},{"uid":"fcf8be1e-85","name":"400.css"},{"uid":"fcf8be1e-87","name":"500.css"},{"uid":"fcf8be1e-89","name":"700.css"}]}]},{"name":"src","children":[{"uid":"fcf8be1e-33","name":"constanst.ts"},{"name":"api/Api.ts","uid":"fcf8be1e-35"},{"name":"components","children":[{"name":"Error","children":[{"uid":"fcf8be1e-37","name":"Errors.ts"},{"uid":"fcf8be1e-45","name":"ErrorComponent.tsx"}]},{"name":"Menus","children":[{"name":"Language/LanguageMenu.tsx","uid":"fcf8be1e-41"},{"name":"User/UserMenu.tsx","uid":"fcf8be1e-51"}]},{"name":"Dialogs","children":[{"name":"Register/RegisterDialog.tsx","uid":"fcf8be1e-47"},{"name":"PostEdit/PostEditDialog.tsx","uid":"fcf8be1e-61"},{"name":"UserEdit/UserEditDialog.tsx","uid":"fcf8be1e-69"},{"name":"UserImage/UserImageDialog.tsx","uid":"fcf8be1e-71"}]},{"name":"Forms","children":[{"name":"Login/LoginForm.tsx","uid":"fcf8be1e-49"},{"name":"Post/PostForm.tsx","uid":"fcf8be1e-57"}]},{"name":"Header/Header.tsx","uid":"fcf8be1e-53"},{"name":"Post/Post.tsx","uid":"fcf8be1e-63"},{"name":"Profile/Profile.tsx","uid":"fcf8be1e-73"}]},{"uid":"fcf8be1e-39","name":"i18n.ts"},{"name":"types/Routes.ts","uid":"fcf8be1e-43"},{"name":"routes","children":[{"uid":"fcf8be1e-55","name":"__root.tsx"},{"uid":"fcf8be1e-67","name":"index.tsx"},{"name":"profile","children":[{"uid":"fcf8be1e-77","name":"index.tsx"},{"uid":"fcf8be1e-79","name":"$id.tsx"}]}]},{"name":"utils/date.ts","uid":"fcf8be1e-59"},{"name":"queries","children":[{"uid":"fcf8be1e-65","name":"postsQuery.ts"},{"uid":"fcf8be1e-75","name":"profileQuery.ts"}]},{"uid":"fcf8be1e-81","name":"routeTree.gen.ts"},{"uid":"fcf8be1e-91","name":"main.tsx"}]},{"uid":"fcf8be1e-93","name":"index.html"}]},{"name":"assets/i18n-DyW0LrNj.js","children":[{"name":"node_modules/.pnpm","children":[{"name":"void-elements@3.1.0/node_modules/void-elements/index.js","uid":"fcf8be1e-95"},{"name":"html-parse-stringify@3.0.1/node_modules/html-parse-stringify/dist/html-parse-stringify.module.js","uid":"fcf8be1e-97"},{"name":"react-i18next@15.0.0_i18next@23.12.2_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-i18next/dist/es","children":[{"uid":"fcf8be1e-99","name":"utils.js"},{"uid":"fcf8be1e-101","name":"unescape.js"},{"uid":"fcf8be1e-103","name":"defaults.js"},{"uid":"fcf8be1e-105","name":"i18nInstance.js"},{"uid":"fcf8be1e-107","name":"TransWithoutContext.js"},{"uid":"fcf8be1e-109","name":"initReactI18next.js"},{"uid":"fcf8be1e-111","name":"context.js"},{"uid":"fcf8be1e-113","name":"Trans.js"},{"uid":"fcf8be1e-115","name":"useTranslation.js"},{"uid":"fcf8be1e-117","name":"withTranslation.js"},{"uid":"fcf8be1e-119","name":"Translation.js"},{"uid":"fcf8be1e-121","name":"I18nextProvider.js"},{"uid":"fcf8be1e-123","name":"useSSR.js"},{"uid":"fcf8be1e-125","name":"withSSR.js"},{"uid":"fcf8be1e-127","name":"index.js"}]},{"name":"i18next@23.12.2/node_modules/i18next/dist/esm/i18next.js","uid":"fcf8be1e-129"},{"name":"i18next-browser-languagedetector@8.0.0/node_modules/i18next-broLine truncated
const run = () => {
const width = window.innerWidth;
@@ -1,23 +1,23 @@
{
"Unauthorized": "Keine Berechtigung",
"Unauthorized_login": "Ungültige E-Mail oder Passwort",
"NotAllowed_login": "Ungültige E-Mail oder Passwort",
"NotFound_user:login": "Benutzer existiert nicht",
"MissingField_email:login": "E-Mail darf nicht leer sein",
"MissingField_password:login": "Passwort darf nicht leer sein",
"Unauthorized_deletePost": "Keine Berechtigung",
"NotAllowed_deletePost": "Keine Berechtigung",
"NotFound_post:deletePost": "Post nicht gefunden",
"Unauthorized_userUpdate": "Keine Berechtigung",
"NotAllowed_userUpdate": "Keine Berechtigung",
"NotFound_user:userUpdate": "Benutzer nicht gefunden",
"FailedUpdate_Duplicate:username:userUpdate": "Ein Benutzer mit diesem Benutzernamen existiert schon",
"FailedUpdate_Duplicate:email:userUpdate": "Ein Benutzer mit dieser E-Mail existiert schon",
"Unauthorized_newPost": "Keine Berechtigung",
"NotAllowed_newPost": "Keine Berechtigung",
"MissingField_content:newPost": "Beitrag darf nicht leer sein",
"Unauthorized_postUpdate": "Keine Berechtigung",
"NotAllowed_postUpdate": "Keine Berechtigung",
"NotFound_post:postUpdate": "Post nicht gefunden",
"Duplicate_user:register": "Ein Benutzer mit diesem Benutzernamen oder E-Mail existiert schon",
@@ -1,23 +1,23 @@
{
"Unauthorized": "Unauthorized",
"Unauthorized": "NotAllowed",
"Unauthorized_login": "Invalid email or password",
"NotAllowed_login": "Invalid email or password",
"NotFound_user:login": "User does not exist",
"MissingField_email:login": "E-Mail required",
"MissingField_password:login": "Password required",
"Unauthorized_deletPost": "Unauthorized",
"NotAllowed_deletPost": "NotAllowed",
"NotFound_post:deletePost": "Post not found",
"Unauthorized_userUpdate": "Unauthorized",
"NotAllowed_userUpdate": "NotAllowed",
"NotFound_user:userUpdate": "User not found",
"FailedUpdate_Duplicate:userUpdate": "A user with this username already exists",
"FailedUpdate_Duplicate:email:userUpdate": "A user with this email already exists",
"Unauthorized_newPost": "Unauthorized",
"NotAllowed_newPost": "NotAllowed",
"MissingField_content:newPost": "Content required",
"Unauthorized_postUpdate": "Unauthorized",
"NotAllowed_postUpdate": "NotAllowed",
"NotFound_post:postUpdate": "Post not found",
"Duplicate_user:register": "A user with this username or email already exists",
+2 -1
View File
@@ -44,7 +44,8 @@ class ApiImpl {
public logOut = async (): Promise<boolean> => {
try {
return await (await this.postAuth('logout')).json();
if (this.token) return await (await this.postAuth('logout')).json();
return true;
} catch {
return false;
} finally {
@@ -19,7 +19,7 @@ const ErrorComponent: FC<Props> = ({ error, context, color = 'error.main' }) =>
switch (error.code) {
case ERRORS.NOT_FOUND:
return <Typography color={color}>{t(error.code, { context: `${error.entity}:${context}` })}</Typography>;
case ERRORS.UNAUTHORIZED:
case ERRORS.NOT_ALLOWED:
return <Typography color={color}>{t(error.code, { context })}</Typography>;
case ERRORS.FAILED_UPDATE:
return error.fields.map((field: string, index: number) => (
@@ -1,6 +1,7 @@
export enum ERRORS {
NOT_FOUND = 'NotFound',
UNAUTHORIZED = 'Unauthorized',
NOT_ALLOWED = 'NotAllowed',
FAILED_UPDATE = 'FailedUpdate',
MISSING_FIELD = 'MissingField',
DUPLICATE = 'Duplicate',
@@ -71,11 +71,9 @@ const UserMenu: FC<Props> = ({ anchorEl, handleClose }) => {
</MenuItem>,
]
) : register ? (
<>
<RegisterDialog open={register} onClose={() => setRegister(false)} />
</>
) : (
<>
<Box>
<LoginForm handleClose={_handleClose} />
<Box sx={{ padding: 1 }}>
<Trans i18nKey="Register prompt">
@@ -92,7 +90,7 @@ const UserMenu: FC<Props> = ({ anchorEl, handleClose }) => {
<Typography component="span" />
</Trans>
</Box>
</>
</Box>
)}
</Menu>
);
+41 -4
View File
@@ -1,7 +1,9 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { RouterProvider, createRouter } from '@tanstack/react-router';
import { StrictMode } from 'react';
import { QueryClient, QueryClientProvider, useQueryClient, useQueryErrorResetBoundary } from '@tanstack/react-query';
import { ErrorRouteComponent, RouterProvider, createRouter, useRouter } from '@tanstack/react-router';
import { StrictMode, useEffect } from 'react';
import ReactDOM from 'react-dom/client';
import Api from './api/Api';
import { ERRORS } from './components/Error/Errors';
// Import the generated route tree
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
@@ -19,6 +21,40 @@ import '@fontsource/roboto/700.css';
// Query Client
const queryClient = new QueryClient();
//TODO: REAUTH HERE
//TODO: Make nice
export const Error: ErrorRouteComponent = ({ error }) => {
const router = useRouter();
const queryErrorResetBoundary = useQueryErrorResetBoundary();
const queryClient = useQueryClient();
useEffect(() => {
// Reset the query error boundary
queryErrorResetBoundary.reset();
}, [queryErrorResetBoundary]);
//TODO: Split display, show something went wrong with retry on all, show session expired and back to main on auth
if ('code' in error && error.code === ERRORS.NOT_ALLOWED) {
Api.logOut().finally(() => {
queryClient.clear();
router.invalidate();
});
}
return (
<div>
{error.message}
<button
onClick={() => {
router.invalidate();
}}
>
retry
</button>
</div>
);
};
// Create a new router instance
const router = createRouter({
routeTree,
@@ -30,6 +66,7 @@ const router = createRouter({
// This will ensure that the loader is always called when the route is preloaded or visited
defaultPreloadStaleTime: 0,
basepath: process.env.NODE_ENV === 'development' ? 'phpCourse/exam/dist' : '/phpCourse/exam',
defaultErrorComponent: Error,
});
// Register the router instance for type safety
@@ -47,7 +84,7 @@ if (!rootElement.innerHTML) {
<StrictMode>
<QueryClientProvider client={queryClient}>
<RouterProvider router={router} />
<ReactQueryDevtools initialIsOpen={false} />
{process.env.NODE_ENV === 'development' && <ReactQueryDevtools initialIsOpen={false} />}
</QueryClientProvider>
</StrictMode>
);
+2 -37
View File
@@ -1,16 +1,10 @@
import { Box } from '@mui/material';
import { QueryClient, useQueryErrorResetBoundary } from '@tanstack/react-query';
import { createRootRouteWithContext, ErrorRouteComponent, Outlet, redirect, useRouter } from '@tanstack/react-router';
import { QueryClient } from '@tanstack/react-query';
import { createRootRouteWithContext, Outlet } from '@tanstack/react-router';
import { TanStackRouterDevtools } from '@tanstack/router-devtools';
import { useEffect } from 'react';
import Api from '../api/Api';
import { ERRORS } from '../components/Error/Errors';
import Header from '../components/Header/Header';
import { ROUTES } from '../types/Routes';
const Root = () => {
//TODO: REAUTH HERE
return (
<>
<Header />
@@ -24,35 +18,6 @@ const Root = () => {
);
};
//TODO: Make nice
const Error: ErrorRouteComponent = ({ error }) => {
const router = useRouter();
const queryErrorResetBoundary = useQueryErrorResetBoundary();
useEffect(() => {
// Reset the query error boundary
queryErrorResetBoundary.reset();
}, [queryErrorResetBoundary]);
if ('code' in error && error.code === ERRORS.UNAUTHORIZED) {
Api.logOut();
redirect({ to: ROUTES.INDEX });
}
return (
<div>
{error.message}
<button
onClick={() => {
router.invalidate();
}}
>
retry
</button>
</div>
);
};
export const Route = createRootRouteWithContext<{ queryClient: QueryClient }>()({
component: Root,
errorComponent: Error,
});