Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion web/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"cn": "^0.5.2",
"es-module-shims": "^2.8.4",
"es-toolkit": "^1.53.2",
"isbot": "^5",
"ky": "^2.2.0",
"lucide-react": "^1.73.0",
"maplibre-gl": "^6",
Expand Down
5 changes: 2 additions & 3 deletions web/src/components/longlink/display/image.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { cn } from 'cn';
import { useState, type ComponentProps } from 'react';
import { useImageResource } from './use-image-resource';
import { Skeleton } from '@/components/shadcn/skeleton';
import { useMergedRefs } from '@base-ui/utils/useMergedRefs';
import { AspectRatio } from '@/components/shadcn/aspect-ratio';
import { useImageBody, useImageResource } from './use-image-resource';

type ImageProps = Omit<ComponentProps<'img'>, 'src' | 'alt'> & {
/** Scoped Solution image path, or an image data/blob URL. */
Expand Down Expand Up @@ -36,8 +36,7 @@ function ImageContent({
dangerouslySetInnerHTML: _html,
...props
}: ImageProps) {
const { src: localSrc, body, unavailable } = useImageResource(src);
const image = useImageBody(body);
const { src: localSrc, body, image, unavailable } = useImageResource(src);
const mergedRef = useMergedRefs(image, ref);
const [broken, setBroken] = useState<Blob | string>();

Expand Down
5 changes: 2 additions & 3 deletions web/src/components/longlink/display/logo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ImageOff } from 'lucide-react';
import { useEffect, useState } from 'react';
import { Spinner } from '@/components/shadcn/spinner';
import { useImageBody, useImageResource } from './use-image-resource';
import { useImageResource } from './use-image-resource';

/** Displays contained artwork in a fixed frame with a missing-image fallback. */
export function Logo({
Expand Down Expand Up @@ -38,8 +38,7 @@ function LogoContent({
detail: boolean;
padded: boolean;
}) {
const { src, body, unavailable } = useImageResource(path);
const image = useImageBody(body);
const { src, body, image, unavailable } = useImageResource(path);
const [decoded, setDecoded] = useState<{ source: Blob | string; status: 'loaded' | 'error' }>();
const source = body ?? src;
const status = decoded?.source === source ? decoded?.status : undefined;
Expand Down
12 changes: 4 additions & 8 deletions web/src/components/longlink/display/use-image-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ import { useBinaryQuery } from '@/lib/hooks/use-binary-query';
export function useImageResource(src?: string) {
const local = src?.startsWith('data:image/') || src?.startsWith('blob:');
const { data, isError } = useBinaryQuery(local ? undefined : src);
if (local || src === undefined) return { src, unavailable: src === undefined };

const body = data?.type.startsWith('image/') ? data : undefined;
return { body, unavailable: isError || !!(data && !body) };
}

export function useImageBody(body?: Blob) {
const body = !local && src !== undefined && data?.type.startsWith('image/') ? data : undefined;
const image = useRef<HTMLImageElement>(null);

useEffect(() => {
Expand All @@ -25,5 +19,7 @@ export function useImageBody(body?: Blob) {
};
}, [body]);

return image;
if (local || src === undefined) return { src, image, unavailable: src === undefined };

return { body, image, unavailable: isError || !!(data && !body) };
}
45 changes: 17 additions & 28 deletions web/src/components/longlink/maps/canvas.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ViewMap } from './map';
import { coordinateError } from './data';
import type { MapOptions } from './types';
import * as mapcn from '@/components/mapcn/map';
import { useEffect, type ReactNode } from 'react';
import { Button } from '@/components/shadcn/button';
import { ErrorBoundary, useErrorBoundary } from 'react-error-boundary';
import { useErrorBoundary } from 'react-error-boundary';

/** Reports asynchronous map resource failures inside the map region. */
function MapStatus() {
Expand Down Expand Up @@ -69,33 +69,22 @@ export function MapCanvas({
{message ?? 'No map data'}
</div>
) : (
<ErrorBoundary
fallbackRender={({ resetErrorBoundary }) => (
<div role="alert" className="flex h-full flex-col items-center justify-center gap-3 text-sm">
<span>Unable to load map</span>
<Button type="button" size="sm" variant="outline" onClick={resetErrorBoundary}>
Retry
</Button>
</div>
)}
<ViewMap
center={center}
zoom={zoom}
interactive={interactive}
blank={blank}
projection={{ type: projection }}
viewport={viewport}
onViewportChange={onViewportChange}
transformRequest={(url) => ({ url, credentials: 'same-origin' })}
>
<mapcn.Map
center={center}
zoom={zoom}
interactive={interactive}
blank={blank}
projection={{ type: projection }}
viewport={viewport}
onViewportChange={onViewportChange}
transformRequest={(url) => ({ url, credentials: 'same-origin' })}
>
<MapStatus />
{controls && interactive && (
<mapcn.MapControls {...(typeof controls === 'object' ? controls : {})} />
)}
{children}
</mapcn.Map>
</ErrorBoundary>
<MapStatus />
{controls && interactive && (
<mapcn.MapControls {...(typeof controls === 'object' ? controls : {})} />
)}
{children}
</ViewMap>
)}
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/longlink/maps/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function ViewMap(props: PublicProps<Omit<mapcn.MapProps, 'theme'> & RefAt
return (
<ErrorBoundary
fallbackRender={({ resetErrorBoundary }) => (
<div role="alert" className="flex min-w-0 flex-1">
<div role="alert" className="flex h-full min-w-0 flex-1 items-center justify-center">
<Empty title="Unable to load map">
<Button type="button" size="sm" variant="outline" onClick={resetErrorBoundary}>
Retry
Expand Down
2 changes: 1 addition & 1 deletion web/src/lib/hooks/use-submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ApiErrorContext } from '@/lib/errors';
import { ReportedError } from '@/lib/reported';
import { useSingleFlight } from '@/lib/hooks/use-single-flight';

export type SubmitOptions = { onError: (error: Error) => void | Promise<void> };
type SubmitOptions = { onError: (error: Error) => void | Promise<void> };

/** Protects a callback from duplicate activation until its work and error handling finish. */
export function useSubmit<T>(
Expand Down
2 changes: 1 addition & 1 deletion web/src/lib/view-capabilities.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';
import type { ViewData, RequestOptions } from '@/views/protocol';

export type { ViewData, RequestOptions } from '@/views/protocol';
export type { ViewData } from '@/views/protocol';

export const RequestContext = createContext<((path: string, options?: RequestOptions) => Promise<ViewData>) | null>(
null
Expand Down
16 changes: 3 additions & 13 deletions web/src/platform/components/membership-confirmation.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useApiError } from '@/lib/errors';
import { useAction } from '@/platform/hooks/use-action';
import { Button } from '@/components/longlink/action/button';
import { Dialog } from '@/components/longlink/layout/dialog';
import { useConfirmAction } from '@/lib/hooks/use-confirm-action';
import {
AlertDialog,
AlertDialogContent,
Expand All @@ -26,8 +25,7 @@ export function MembershipConfirmation({
onClose: () => void;
onConfirm: () => Promise<void>;
}) {
const reportError = useApiError();
const { isPending: pending, inFlight, run } = useConfirmAction();
const { isPending: pending, inFlight, run } = useAction();

const footer = (
<>
Expand All @@ -39,15 +37,7 @@ export function MembershipConfirmation({
variant={destructive ? 'destructive' : 'primary'}
disabled={pending}
aria-busy={pending || undefined}
onClick={() => {
run(async () => {
try {
await onConfirm();
} catch (cause) {
reportError(cause);
}
});
}}
onClick={() => run(onConfirm)}
>
{actionLabel}
</Button>
Expand Down
19 changes: 19 additions & 0 deletions web/src/platform/hooks/use-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useApiError } from '@/lib/errors';
import { useConfirmAction } from '@/lib/hooks/use-confirm-action';

export function useAction() {
const reportError = useApiError();
const { isPending, inFlight, run } = useConfirmAction();

function runAction(action: () => void | Promise<void>) {
run(async () => {
try {
await action();
} catch (cause) {
reportError(cause);
}
});
}

return { isPending, inFlight, run: runAction };
}
50 changes: 36 additions & 14 deletions web/src/platform/routes/auth/reset-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,48 @@ function isBadTokenError(cause: unknown): boolean {

/** Accepts a password reset token and saves a new password. */
export default function ResetPassword() {
const form = useForm<ResetPasswordValues>({
defaultValues: { password: '' },
resolver: zodResolver(resetPasswordSchema)
});

const confirmation = 'Your password has been reset. You can now sign in.';

const { verification } = useVerification(PASSWORD_RESET_TOKEN_KEY, async ({ signal, token: resetToken }) => {
if (resetToken) {
await api('/api/v1/auth/reset-password/verify', { json: { token: resetToken }, method: 'POST', signal });
} else {
await api('/api/v1/auth/reset-password/setup', { signal });
}
});

if (verification?.status === 'verified') return <ResetPasswordForm />;

return (
<AuthLayout
title="Set a new password"
description={
verification?.status === 'error'
? 'This password reset link is invalid or expired. Request a new link to continue.'
: 'Choose a new password for your LongLink account.'
}
>
<title>Set a New Password | LongLink</title>
<Separator />
{verification?.status === 'error' ? (
<Link href="/auth/forgot-password" variant="primary">
Request another reset link
</Link>
) : (
<Button disabled aria-busy="true">
Reset password
</Button>
)}
</AuthLayout>
);
}

function ResetPasswordForm() {
const form = useForm<ResetPasswordValues>({
defaultValues: { password: '' },
resolver: zodResolver(resetPasswordSchema)
});

const confirmation = 'Your password has been reset. You can now sign in.';

const save = useSubmit(
async (payload: ResetPasswordValues) => {
try {
Expand All @@ -57,19 +85,13 @@ export default function ResetPassword() {
let body: ReactNode;

// Invalid and expired credentials require a replacement email.
if (verification?.status === 'error' || form.formState.errors.root?.credential) {
if (form.formState.errors.root?.credential) {
description = 'This password reset link is invalid or expired. Request a new link to continue.';
body = (
<Link href="/auth/forgot-password" variant="primary">
Request another reset link
</Link>
);
} else if (verification?.status !== 'verified') {
body = (
<Button disabled aria-busy="true">
Reset password
</Button>
);
} else if (form.formState.isSubmitSuccessful) {
body = (
<Stack gap={4}>
Expand Down
Loading