spa hardening, offline logging, rate limit fixes
server: - backup exporter, auth extractors, error shapes, CONTEXT (prior work) - spa assets served outside the rate limit via route_layer - requests_per_second went to per_second(), which takes an interval not a rate: 50 meant one request per 50s once burst was spent. now converted properly. 15/s, burst 60 spa fixes: - account delete cleared snake_case token keys that were never written - refresh interceptor could retry forever - date ranges used local day boundaries stamped +00:00 - "all" period trend plotted one page; calendar days fabricated mood 3 - chart grid invisible: hsl(var(--border)) against rgba tokens - blob url leak, orphaned media on failed save, devtools in prod bundle - pt-safe/safe-area-pb classes never existed spa features: - offline outbox: entries queue to IndexedDB, replay with backoff, only server refusals count against an entry - drafts persist, quick-log sheet, diary infinite scroll + filters - route error boundary, stale-chunk recovery, no service worker in dev a11y + perf: - mood picker is a radiogroup, activity picker keyboard-operable, text alternatives for colour/emoji, locale week start - dark glass over the bright photo: worst case 1.4:1 -> 4.9-9.6:1 - initial payload 1095->769kB raw, 306->230kB gzip; 38 unused components and 5 deps dropped; fonts 218->133kB 53 tests added (43 spa, 10 server)
This commit is contained in:
103
spa/src/components/entry/pending-entries.tsx
Normal file
103
spa/src/components/entry/pending-entries.tsx
Normal file
@@ -0,0 +1,103 @@
|
||||
import { format } from "date-fns"
|
||||
import { AlertTriangle, Clock } from "lucide-react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card, CardContent } from "@/components/ui/card"
|
||||
import { MoodBadge } from "@/components/mood/mood-badge"
|
||||
import {
|
||||
useDiscardQueued,
|
||||
useQueuedEntries,
|
||||
useRetryQueued,
|
||||
} from "@/hooks/use-outbox"
|
||||
import { isStuck } from "@/lib/outbox-sync"
|
||||
import { contentPreview } from "@/lib/entry-preview"
|
||||
import type { QueuedEntry } from "@/lib/store/outbox"
|
||||
|
||||
/**
|
||||
* Entries written on this device that the server has not taken yet. They are
|
||||
* shown with the journal so that logging offline still looks like it worked.
|
||||
*/
|
||||
export function PendingEntries() {
|
||||
const { data: queued = [] } = useQueuedEntries()
|
||||
|
||||
if (!queued.length) return null
|
||||
|
||||
return (
|
||||
<section className="flex flex-col gap-2">
|
||||
<h2 className="text-xs font-medium tracking-wide text-muted-foreground uppercase">
|
||||
Not sent yet
|
||||
</h2>
|
||||
{queued.map((entry) => (
|
||||
<PendingEntryCard key={entry.id} queued={entry} />
|
||||
))}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function PendingEntryCard({ queued }: { queued: QueuedEntry }) {
|
||||
const retry = useRetryQueued()
|
||||
const discard = useDiscardQueued()
|
||||
const stuck = isStuck(queued)
|
||||
const note = contentPreview(queued.draft.content)
|
||||
|
||||
return (
|
||||
<Card className="border-dashed">
|
||||
<CardContent className="flex items-start gap-3 p-4">
|
||||
{queued.draft.mood !== null && <MoodBadge value={queued.draft.mood} />}
|
||||
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<span className="flex items-center gap-1 text-xs text-muted-foreground">
|
||||
{stuck ? (
|
||||
<AlertTriangle
|
||||
className="h-3 w-3 text-destructive"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
) : (
|
||||
<Clock className="h-3 w-3" aria-hidden="true" />
|
||||
)}
|
||||
{stuck ? "The server would not take this" : "Waiting to send"}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{format(new Date(queued.draft.loggedAt), "MMM d, h:mm a")}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{note && (
|
||||
<p className="mt-1 line-clamp-2 text-sm text-muted-foreground">
|
||||
{note}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{stuck && (
|
||||
<>
|
||||
{queued.lastError && (
|
||||
<p className="mt-1 text-xs text-destructive">
|
||||
{queued.lastError}
|
||||
</p>
|
||||
)}
|
||||
<div className="mt-2 flex gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={retry.isPending}
|
||||
onClick={() => retry.mutate(queued)}
|
||||
>
|
||||
{retry.isPending ? "Retrying…" : "Try again"}
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="text-destructive"
|
||||
disabled={discard.isPending}
|
||||
onClick={() => discard.mutate(queued.id)}
|
||||
>
|
||||
Discard
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user