* feat: redesign * feat: update other columns to new design * chore: small fixes * fix: better manage external webview * feat: redesign note * feat: update ui * chore: update * chore: update * chore: polish ui * chore: update auth ui * feat: finalize note design * chore: small fixes * feat: add window management in rust * chore: format * feat: update ui for event screen * feat: update event screen * feat: final
48 lines
946 B
TypeScript
48 lines
946 B
TypeScript
import { Spinner } from "@lume/ui";
|
|
import { cn } from "@lume/utils";
|
|
import { useRouteContext } from "@tanstack/react-router";
|
|
import {
|
|
type Dispatch,
|
|
type ReactNode,
|
|
type SetStateAction,
|
|
useState,
|
|
} from "react";
|
|
import { toast } from "sonner";
|
|
|
|
export function AvatarUploader({
|
|
setPicture,
|
|
children,
|
|
className,
|
|
}: {
|
|
setPicture: Dispatch<SetStateAction<string>>;
|
|
children: ReactNode;
|
|
className?: string;
|
|
}) {
|
|
const { ark } = useRouteContext({ strict: false });
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const uploadAvatar = async () => {
|
|
// start loading
|
|
setLoading(true);
|
|
try {
|
|
const image = await ark.upload();
|
|
setPicture(image);
|
|
} catch (e) {
|
|
toast.error(String(e));
|
|
}
|
|
|
|
// stop loading
|
|
setLoading(false);
|
|
};
|
|
|
|
return (
|
|
<button
|
|
type="button"
|
|
onClick={() => uploadAvatar()}
|
|
className={cn("size-4", className)}
|
|
>
|
|
{loading ? <Spinner className="size-4" /> : children}
|
|
</button>
|
|
);
|
|
}
|