Repository navigation
fix(web): correct account analytics and sync behavior #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ import { currencies } from '@convex/shared/validators'; | |
| import { FinanceSignedOut } from '@/components/finance/FinanceSignedOut'; | ||
| import { useBrowserSync } from '@/lib/offline/BrowserSyncProvider'; | ||
| import { useLocalRecords } from '@/lib/offline/hooks'; | ||
| import { commitLocalWrite, type LocalRecord } from '@/lib/offline/repository'; | ||
| import { clearLocalData, commitLocalWrite, type LocalRecord } from '@/lib/offline/repository'; | ||
|
|
||
| type Profile = LocalRecord & { | ||
| displayName?: string; | ||
|
|
@@ -106,8 +106,19 @@ export default function ProfilePage() { | |
| } | ||
| } | ||
| async function leave() { | ||
| await signOut(); | ||
| router.replace('/sign-in'); | ||
| setMessage(''); | ||
| try { | ||
| if (!userId) throw new Error('AUTH_REQUIRED'); | ||
| await clearLocalData(userId); | ||
| await signOut(); | ||
|
Comment on lines
+112
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If IndexedDB is unavailable, blocked, or fails while Useful? React with 👍 / 👎. |
||
| router.replace('/sign-in'); | ||
| } catch (cause) { | ||
| setMessage( | ||
| cause instanceof Error | ||
| ? cause.message | ||
| : 'Could not clear this browser’s saved data and sign out.', | ||
| ); | ||
| } | ||
| } | ||
| const name = profile?.displayName ?? 'Your profile'; | ||
| return ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,24 @@ export default function SyncSettingsPage() { | |
| failedEntries, | ||
| conflicts, | ||
| retryNow, | ||
| retryEntry, | ||
| resolveConflict, | ||
| } = useBrowserSync(); | ||
| const [saving, setSaving] = React.useState(false); | ||
| const [error, setError] = React.useState(''); | ||
| const [resolvingConflict, setResolvingConflict] = React.useState<string | null>(null); | ||
|
|
||
| async function chooseConflict(conflictId: string, winner: 'local' | 'cloud') { | ||
| setResolvingConflict(conflictId); | ||
| setError(''); | ||
| try { | ||
| await resolveConflict(conflictId, winner); | ||
| } catch (cause) { | ||
| setError(cause instanceof Error ? cause.message : 'Could not resolve this conflict.'); | ||
| } finally { | ||
| setResolvingConflict(null); | ||
| } | ||
| } | ||
|
|
||
| async function selectWindow(value: LocalSyncWindow) { | ||
| if (saving || value === syncWindow) return; | ||
|
|
@@ -57,6 +72,7 @@ export default function SyncSettingsPage() { | |
| ); | ||
|
|
||
| const problems = failedEntries.length + conflicts.length; | ||
| const needsAttention = problems > 0 || Boolean(syncError); | ||
| return ( | ||
| <SettingsShell | ||
| title="Sync" | ||
|
|
@@ -67,7 +83,7 @@ export default function SyncSettingsPage() { | |
| icon={ | ||
| !isConnected ? ( | ||
| <CloudOff size={22} /> | ||
| ) : problems ? ( | ||
| ) : needsAttention ? ( | ||
| <TriangleAlert size={22} /> | ||
| ) : ( | ||
| <Cloud size={22} /> | ||
|
|
@@ -78,15 +94,17 @@ export default function SyncSettingsPage() { | |
| ? 'Offline' | ||
| : isSyncing | ||
| ? 'Syncing…' | ||
| : problems | ||
| ? `${problems} change${problems === 1 ? '' : 's'} need attention` | ||
| : needsAttention | ||
| ? problems | ||
| ? `${problems} change${problems === 1 ? '' : 's'} need attention` | ||
| : 'Sync needs attention' | ||
| : 'Everything is synced' | ||
| } | ||
| description={ | ||
| !isConnected | ||
| syncError ?? | ||
| (!isConnected | ||
| ? 'Changes save in this browser and sync when you reconnect.' | ||
| : (syncError ?? | ||
| 'Finapp keeps a copy in this browser so it opens fast and works offline.') | ||
| : 'Finapp keeps a copy in this browser so it opens fast and works offline.') | ||
| } | ||
| action={ | ||
| <Button | ||
|
|
@@ -99,15 +117,67 @@ export default function SyncSettingsPage() { | |
| </Button> | ||
| } | ||
| /> | ||
| {problems ? ( | ||
| {needsAttention ? ( | ||
| <SettingsGroup title="Needs attention"> | ||
| <SettingsLink | ||
| icon={<TriangleAlert size={19} />} | ||
| tone="warning" | ||
| title={`${failedEntries.length} failed, ${conflicts.length} conflicting`} | ||
| description="Review and retry or choose which version to keep" | ||
| onPress={() => router.push('/notifications')} | ||
| /> | ||
| {syncError ? ( | ||
| <p role="alert" style={{ margin: 0, color: 'var(--finapp-destructive)' }}> | ||
| {syncError} | ||
| </p> | ||
| ) : null} | ||
| {failedEntries.map((entry) => ( | ||
| <div | ||
| key={entry.localId} | ||
| style={{ | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'space-between', | ||
| gap: 12, | ||
| }} | ||
| > | ||
| <span>{entry.lastError ?? `${entry.operation} could not sync`}</span> | ||
| <Button | ||
| size="sm" | ||
| variant="outline" | ||
| disabled={!isConnected || isSyncing} | ||
| onPress={() => | ||
| void retryEntry(entry.localId).catch((cause: unknown) => | ||
| setError( | ||
| cause instanceof Error ? cause.message : 'Could not retry this change.', | ||
| ), | ||
| ) | ||
| } | ||
| > | ||
| Retry | ||
| </Button> | ||
| </div> | ||
| ))} | ||
| {conflicts.map((conflict) => ( | ||
| <div key={conflict.id} style={{ display: 'grid', gap: 8, paddingBlock: 8 }}> | ||
| <p style={{ margin: 0 }}> | ||
| {conflict.entityType} {conflict.recordId} has a local and cloud version. Choose | ||
| which to keep. | ||
| </p> | ||
|
Comment on lines
+155
to
+159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For every sync conflict, this page displays only the entity type and record ID before offering destructive “Keep this device” and “Keep cloud” actions. Since Useful? React with 👍 / 👎. |
||
| <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}> | ||
| <Button | ||
| size="sm" | ||
| variant="outline" | ||
| disabled={resolvingConflict !== null} | ||
| onPress={() => void chooseConflict(conflict.id, 'local')} | ||
|
Comment on lines
+161
to
+165
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If “Keep this device” is pressed while a background sync is already running, conflict resolution creates a pending outbox entry and then calls Useful? React with 👍 / 👎. |
||
| > | ||
| Keep this device | ||
| </Button> | ||
| <Button | ||
| size="sm" | ||
| variant="outline" | ||
| disabled={resolvingConflict !== null} | ||
| onPress={() => void chooseConflict(conflict.id, 'cloud')} | ||
| > | ||
| Keep cloud | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| ))} | ||
| {error ? <p role="alert">{error}</p> : null} | ||
| </SettingsGroup> | ||
| ) : null} | ||
| <SettingsGroup | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the user signs out while
BrowserSyncProvideris syncing,clearLocalDatacan finish before an in-flight bootstrap or pull writes its response to IndexedDB. Signing out does not cancel those operations, which retain the user ID they started with, so they can repopulate finance records after this deletion and leave private data in the browser despite the sign-out guarantee. Coordinate shutdown of active sync before clearing, or perform a final clear after synchronization can no longer write.Useful? React with 👍 / 👎.