Skip to content

Commit

Permalink
feat: improve event info dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwynr committed Sep 11, 2024
1 parent 65f5960 commit a42bdb6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/components/settings/events/dialog/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type Event = {
}
}

export const Content = memo(({ uuid }: { uuid: string }) => {
export const Content = memo(({ uuid, icon, text }: { uuid: string; icon: JSX.Element; text: string }) => {
const query = useQuery({
queryKey: ["fetchEvent", uuid],
queryFn: () => worker.fetchEvent({ uuid }) as Promise<Event>
Expand Down Expand Up @@ -62,6 +62,10 @@ export const Content = memo(({ uuid }: { uuid: string }) => {

return (
<div className="flex flex-col mt-2 gap-2">
<div className="flex flex-row bg-secondary rounded-md p-2 px-2.5 gap-2">
<div className="flex flex-row shrink-0">{icon}</div>
<p>{text}</p>
</div>
<div className="flex flex-row bg-secondary rounded-md p-2 px-2.5 justify-between items-center">
<p className="text-muted-foreground text-sm">{uuid}</p>
<Copy
Expand Down
14 changes: 12 additions & 2 deletions src/components/settings/events/dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { useTranslation } from "react-i18next"
export const EventDialog = memo(() => {
const [open, setOpen] = useState<boolean>(false)
const [uuid, setUUID] = useState<string | null>(null)
const [icon, setIcon] = useState<JSX.Element | null>(null)
const [text, setText] = useState<string>("")
const { t } = useTranslation()

const preventDefault = useCallback((e: Event) => {
Expand All @@ -15,8 +17,10 @@ export const EventDialog = memo(() => {
}, [])

useEffect(() => {
const listener = eventEmitter.on("openEventDialog", (id: string) => {
const listener = eventEmitter.on("openEventDialog", ({ id, text, icon }: { id: string; text: string; icon: JSX.Element }) => {
setUUID(id)
setIcon(icon)
setText(text)
setOpen(true)
})

Expand All @@ -36,7 +40,13 @@ export const EventDialog = memo(() => {
onOpenAutoFocus={preventDefault}
>
<DialogHeader>{t("dialogs.event.title")}</DialogHeader>
{uuid && <Content uuid={uuid} />}
{uuid && icon && text && (
<Content
uuid={uuid}
icon={icon}
text={text}
/>
)}
<DialogFooter />
</DialogContent>
</Dialog>
Expand Down
32 changes: 22 additions & 10 deletions src/components/settings/events/event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,9 @@ export const Event = memo(({ event, account }: { event: UserEvent; account: User
}
}, [event, t])

const open = useCallback(() => {
eventEmitter.emit("openEventDialog", event.uuid)
}, [event.uuid])

return (
<div
className="flex flex-row border-b items-center p-4 py-3 justify-between gap-10 hover:bg-secondary hover:rounded-md w-full cursor-pointer"
onClick={open}
>
<div className="flex flex-row gap-3 items-center">
const eventIcon = useMemo(() => {
return (
<>
{event.type === "folderColorChanged" ||
event.type === "folderLinkEdited" ||
event.type === "baseFolderCreated" ||
Expand Down Expand Up @@ -245,6 +238,25 @@ export const Event = memo(({ event, account }: { event: UserEvent; account: User
size={24}
/>
)}
</>
)
}, [account.avatarURL, event.info, event.type])

const open = useCallback(() => {
eventEmitter.emit("openEventDialog", {
id: event.uuid,
icon: eventIcon,
text: eventText
})
}, [event.uuid, eventIcon, eventText])

return (
<div
className="flex flex-row border-b items-center p-4 py-3 justify-between gap-10 hover:bg-secondary hover:rounded-md w-full cursor-pointer"
onClick={open}
>
<div className="flex flex-row gap-3 items-center">
{eventIcon}
<p className="line-clamp-1 text-ellipsis break-all">{eventText}</p>
</div>
<p className="text-muted-foreground text-sm shrink-0">{simpleDate(event.timestamp)}</p>
Expand Down

0 comments on commit a42bdb6

Please sign in to comment.