-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
306 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { createFileUploader } from "@solid-primitives/upload"; | ||
import { useAction, useSubmission } from "@solidjs/router"; | ||
import { Icon } from "solid-heroicons"; | ||
import { arrowTopRightOnSquare, arrowUpTray, camera, trash } from "solid-heroicons/solid-mini"; | ||
import { Component, Show } from "solid-js"; | ||
import { toast } from "solid-sonner"; | ||
import { Avatar, Dropdown, Separator } from "~/components"; | ||
import { components } from "~/lib/api/schema"; | ||
import { formatResourceURL } from "~/lib/api/uploads"; | ||
import { removeCurrentUserAvatar, updateCurrentUserAvatar } from "~/lib/api/users/me"; | ||
import { useI18n } from "~/lib/i18n"; | ||
|
||
export type AvatarEditProps = { | ||
user: components["schemas"]["CurrentUserResponse"]; | ||
}; | ||
|
||
export const AvatarEdit: Component<AvatarEditProps> = (props) => { | ||
const i18n = useI18n(); | ||
|
||
const updateAvatar = useAction(updateCurrentUserAvatar); | ||
const updatingAvatar = useSubmission(updateCurrentUserAvatar); | ||
const uploader = createFileUploader({ accept: "image/*" }); | ||
|
||
const removeAvatar = useAction(removeCurrentUserAvatar); | ||
const removingAvatar = useSubmission(removeCurrentUserAvatar); | ||
|
||
const selectAvatar = () => { | ||
uploader.selectFiles(async (uploads) => { | ||
const result = await updateAvatar(uploads[0].file); | ||
if (result?.error) { | ||
toast.error(result.error.detail?.toString()); | ||
} | ||
}); | ||
}; | ||
|
||
return ( | ||
<Dropdown placement="bottom"> | ||
<Dropdown.Trigger as={Avatar} aria-busy={updatingAvatar.pending || removingAvatar.pending}> | ||
<Avatar.Img src={props.user.avatar_url} alt={props.user.email} /> | ||
<div class="absolute inset-0 flex flex-col items-center justify-center bg-black/50 font-semibold text-white opacity-0 transition-opacity hover:opacity-100"> | ||
<Icon path={camera} class="size-8" /> | ||
<span>{i18n.t.components.avatarEdit.update()}</span> | ||
</div> | ||
</Dropdown.Trigger> | ||
<Dropdown.Content> | ||
<Show when={props.user.avatar_url}> | ||
{(avatar_url) => ( | ||
<> | ||
<Dropdown.Item onSelect={() => window.open(formatResourceURL(avatar_url()), "_blank")}> | ||
<Dropdown.ItemIcon path={arrowTopRightOnSquare} class="size-4" /> | ||
<Dropdown.ItemLabel>{i18n.t.components.avatarEdit.open()}</Dropdown.ItemLabel> | ||
</Dropdown.Item> | ||
<Separator orientation="horizontal" class="my-0.5" /> | ||
</> | ||
)} | ||
</Show> | ||
<Dropdown.Item onSelect={selectAvatar} disabled={updatingAvatar.pending}> | ||
<Dropdown.ItemIcon path={arrowUpTray} class="size-4" /> | ||
<Dropdown.ItemLabel>{i18n.t.components.avatarEdit.select()}</Dropdown.ItemLabel> | ||
</Dropdown.Item> | ||
<Dropdown.Item | ||
class="text-red-600" | ||
onSelect={removeAvatar} | ||
disabled={!props.user.avatar_url || removingAvatar.pending} | ||
> | ||
<Dropdown.ItemIcon path={trash} class="size-4" /> | ||
<Dropdown.ItemLabel>{i18n.t.components.avatarEdit.remove()}</Dropdown.ItemLabel> | ||
</Dropdown.Item> | ||
</Dropdown.Content> | ||
</Dropdown> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./ui"; | ||
export * from "./session-expiration-observer"; | ||
export * from "./avatar-edit"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { JSX, ValidComponent } from "solid-js"; | ||
import type { ImageRootProps, ImageImgProps } from "@kobalte/core/image"; | ||
|
||
export type AvatarRootProps<T extends ValidComponent = "span"> = ImageRootProps<T> & JSX.StylableSVGAttributes; | ||
export type AvatarImgProps<T extends ValidComponent = "img"> = Omit<ImageImgProps<T>, "src"> & | ||
JSX.StylableSVGAttributes & { | ||
alt: string; | ||
src: string | null | undefined; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { tv } from "tailwind-variants"; | ||
|
||
export const styles = tv({ | ||
slots: { | ||
root: [ | ||
"group relative inline-flex size-24 items-center justify-center container-size", | ||
"select-none overflow-hidden rounded-full text-fg-soft ring-1 ring-bg-tertiary", | ||
], | ||
img: ["group-aria-busy:cursor-progress group-aria-busy:animate-pulse"], | ||
alt: [ | ||
"flex size-full items-center justify-center", | ||
"bg-bg-default text-cqi-50 font-medium uppercase leading-none", | ||
"group-aria-busy:cursor-progress group-aria-busy:animate-pulse", | ||
], | ||
fallback: ["size-full animate-pulse bg-bg-default"], | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { type ValidComponent, Show, splitProps } from "solid-js"; | ||
import { Transition } from "solid-transition-group"; | ||
|
||
import { Image } from "@kobalte/core/image"; | ||
import type { PolymorphicProps } from "@kobalte/core/polymorphic"; | ||
|
||
import { formatResourceURL } from "~/lib/api/uploads"; | ||
import { merge } from "~/lib/utils/css/merge"; | ||
|
||
import type { AvatarImgProps, AvatarRootProps } from "./avatar.props"; | ||
import { styles } from "./avatar.styles"; | ||
|
||
export const AvatarRoot = <T extends ValidComponent = "span">(props: PolymorphicProps<T, AvatarRootProps<T>>) => { | ||
const [local, others] = splitProps(props as AvatarRootProps<T>, ["class"]); | ||
|
||
return <Image class={merge(styles().root(), local.class)} {...others} />; | ||
}; | ||
|
||
export const AvatarImg = <T extends ValidComponent = "img">(props: PolymorphicProps<T, AvatarImgProps<T>>) => { | ||
const [local, others] = splitProps(props as AvatarImgProps<T>, ["class", "src"]); | ||
|
||
return ( | ||
<Transition | ||
mode="outin" | ||
enterClass="blur-md" | ||
enterToClass="blur-0" | ||
exitClass="blur-0" | ||
exitToClass="blur-md" | ||
enterActiveClass="transition-filter" | ||
exitActiveClass="transition-filter" | ||
> | ||
<Show when={local.src} fallback={<span class={styles().alt()}>{props.alt.slice(0, 2)}</span>}> | ||
{(src) => ( | ||
<span> | ||
<Image.Img src={formatResourceURL(src())} class={merge(styles().img(), local.class)} {...others} /> | ||
<Image.Fallback class={styles().fallback()} /> | ||
</span> | ||
)} | ||
</Show> | ||
</Transition> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { AvatarImg, AvatarRoot } from "./avatar"; | ||
|
||
export const Avatar = Object.assign(AvatarRoot, { | ||
Img: AvatarImg, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.