-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Allow signing back in after client-side exception
This at least allow users to recover from some bugs until they're fixed
- Loading branch information
1 parent
1f7021d
commit 7ddf7e5
Showing
17 changed files
with
226 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Component, ErrorInfo, ReactNode } from 'react' | ||
import { Header } from './common/Header' | ||
|
||
interface Props { | ||
children?: ReactNode | ||
} | ||
|
||
interface State { | ||
hasError: boolean | ||
} | ||
|
||
class ErrorBoundary extends Component<Props, State> { | ||
public state: State = { | ||
hasError: false, | ||
} | ||
|
||
public static getDerivedStateFromError(_: Error): State { | ||
return { hasError: true } | ||
} | ||
|
||
public componentDidCatch(error: Error, errorInfo: ErrorInfo) { | ||
console.error('Uncaught error:', error, errorInfo) | ||
} | ||
|
||
public render() { | ||
if (this.state.hasError) { | ||
return ( | ||
<div> | ||
<Header title="Error" /> | ||
<p className="mx-auto my-4 text-xl text-center max-w-prose"> | ||
Sorry there was an error. If you've unsynced, re-syncing might | ||
fix the issue. | ||
</p> | ||
</div> | ||
) | ||
} | ||
|
||
return this.props.children | ||
} | ||
} | ||
|
||
export default ErrorBoundary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import { useObservable } from 'dexie-react-hooks' | ||
import { db } from '../db' | ||
import { | ||
IonButton, | ||
IonButtons, | ||
IonContent, | ||
IonHeader, | ||
IonIcon, | ||
IonImg, | ||
IonInput, | ||
IonItem, | ||
IonList, | ||
IonPopover, | ||
IonTitle, | ||
IonToolbar, | ||
} from '@ionic/react' | ||
import { | ||
cloudDoneSharp, | ||
cloudDownloadSharp, | ||
cloudOfflineSharp, | ||
cloudUploadSharp, | ||
thunderstormSharp, | ||
} from 'ionicons/icons' | ||
|
||
export const Header = ({ title }: { title: string }) => { | ||
const user = useObservable(db.cloud.currentUser) | ||
const syncState = useObservable(db.cloud.syncState) | ||
const isLoggedIn = user?.isLoggedIn | ||
|
||
return ( | ||
<IonHeader> | ||
<IonToolbar> | ||
<IonImg | ||
src="/logo.png" | ||
slot="start" | ||
className="w-10 h-10 ml-4" | ||
/> | ||
<IonTitle>{title}</IonTitle> | ||
<IonButtons | ||
className="mx-2" | ||
slot="secondary" | ||
> | ||
{isLoggedIn ? ( | ||
<> | ||
<IonButton id="sync-status"> | ||
<IonIcon | ||
icon={ | ||
syncState?.error | ||
? thunderstormSharp | ||
: syncState?.phase === 'pushing' | ||
? cloudUploadSharp | ||
: syncState?.phase === 'pulling' | ||
? cloudDownloadSharp | ||
: cloudDoneSharp | ||
} | ||
color={syncState?.error ? 'danger' : 'default'} | ||
slot="icon-only" | ||
></IonIcon> | ||
<IonPopover | ||
trigger="sync-status" | ||
triggerAction="click" | ||
> | ||
<IonContent className="text-xs"> | ||
{syncState?.error ? ( | ||
<p>Sync error: ${syncState.error.message}</p> | ||
) : ( | ||
<IonList> | ||
<IonItem> | ||
<IonInput | ||
label="Email" | ||
labelPlacement="floating" | ||
readonly | ||
value={user.email} | ||
></IonInput> | ||
</IonItem> | ||
|
||
<IonItem> | ||
<IonInput | ||
label="License" | ||
labelPlacement="floating" | ||
readonly | ||
value={syncState?.license} | ||
></IonInput> | ||
</IonItem> | ||
|
||
<IonItem> | ||
<IonInput | ||
label="Status" | ||
labelPlacement="floating" | ||
readonly | ||
value={syncState?.status} | ||
></IonInput> | ||
</IonItem> | ||
|
||
<IonItem> | ||
<IonInput | ||
label="Phase" | ||
labelPlacement="floating" | ||
readonly | ||
value={syncState?.phase} | ||
></IonInput> | ||
</IonItem> | ||
|
||
<IonItem> | ||
<IonInput | ||
label="Progress" | ||
labelPlacement="floating" | ||
readonly | ||
value={syncState?.progress || '-'} | ||
></IonInput> | ||
</IonItem> | ||
</IonList> | ||
)} | ||
</IonContent> | ||
</IonPopover> | ||
</IonButton> | ||
<IonButton | ||
fill="solid" | ||
onClick={() => { | ||
db.cloud.logout() | ||
}} | ||
> | ||
Unsync | ||
</IonButton> | ||
</> | ||
) : ( | ||
<> | ||
<IonButton id="sync-status"> | ||
<IonIcon | ||
icon={cloudOfflineSharp} | ||
slot="icon-only" | ||
></IonIcon> | ||
<IonPopover | ||
trigger="sync-status" | ||
triggerAction="click" | ||
> | ||
<IonContent class="ion-padding"> | ||
Not synced. Your data is stored locally only. | ||
</IonContent> | ||
</IonPopover> | ||
</IonButton> | ||
<IonButton | ||
fill="solid" | ||
onClick={() => { | ||
db.cloud.login() | ||
}} | ||
> | ||
Sync | ||
</IonButton> | ||
</> | ||
)} | ||
</IonButtons> | ||
</IonToolbar> | ||
</IonHeader> | ||
) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.