mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
use user state if possible to avoid stale data
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { UserRound } from "lucide-react";
|
import { UserRound } from "lucide-react";
|
||||||
|
import { useSession } from "@/components/session-provider";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const FALLBACK_COLOURS = [
|
const FALLBACK_COLOURS = [
|
||||||
@@ -41,18 +42,25 @@ function getInitials(username: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function Avatar({
|
export default function Avatar({
|
||||||
avatarURL,
|
avatarURL: _avatarURL,
|
||||||
name,
|
name: _name,
|
||||||
username,
|
username,
|
||||||
size,
|
size,
|
||||||
textClass = "text-xs",
|
textClass = "text-xs",
|
||||||
|
strong = false,
|
||||||
}: {
|
}: {
|
||||||
avatarURL?: string | null;
|
avatarURL?: string | null;
|
||||||
name?: string;
|
name?: string;
|
||||||
username?: string;
|
username?: string;
|
||||||
size?: number;
|
size?: number;
|
||||||
textClass?: string;
|
textClass?: string;
|
||||||
|
strong?: boolean;
|
||||||
}) {
|
}) {
|
||||||
|
// if the username matches the authed user, use their avatarURL and name (avoid stale data)
|
||||||
|
const { user } = useSession();
|
||||||
|
const avatarURL = !strong && username && user && username === user.username ? user.avatarURL : _avatarURL;
|
||||||
|
const name = !strong && username && user && username === user.username ? user.name : _name;
|
||||||
|
|
||||||
const backgroundClass = username
|
const backgroundClass = username
|
||||||
? FALLBACK_COLOURS[hashStringToIndex(username, FALLBACK_COLOURS.length)]
|
? FALLBACK_COLOURS[hashStringToIndex(username, FALLBACK_COLOURS.length)]
|
||||||
: "bg-muted";
|
: "bg-muted";
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ export function UploadAvatar({
|
|||||||
avatarURL={avatarURL}
|
avatarURL={avatarURL}
|
||||||
size={24}
|
size={24}
|
||||||
textClass={"text-4xl"}
|
textClass={"text-4xl"}
|
||||||
|
strong
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{!uploading && showEdit && (
|
{!uploading && showEdit && (
|
||||||
|
|||||||
Reference in New Issue
Block a user