import { useTranslation } from "react-i18next"; import { FeatherAtSign, FeatherChevronLeft, FeatherMessageSquare, FeatherSearch } from "@subframe/core"; import type { ChatMessageDiscoveryRowVM, ChatMessageDiscoveryVM } from "@hivegrid/view-models"; import { useLocaleFormatters } from "~/locale/format"; import { Avatar } from "~/ui/components/Avatar"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Button } from "~/ui/components/Button"; import { ButtonGroup } from "~/ui/components/ButtonGroup"; import { Card } from "~/ui/components/Card"; import { EmptyState } from "~/ui/components/EmptyState"; import { LoadingIndicatorSkeleton } from "~/ui/components/LoadingIndicatorSkeleton"; import { SearchInput } from "~/ui/components/SearchInput"; import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell"; export type ChatMessageDiscoveryActions = Readonly<{ onBack: (href: string) => void; onOpenResult: (row: ChatMessageDiscoveryRowVM) => void; onQueryChange: (query: string) => void; onSwitchMode: (href: string) => void; onLoadMore?: (cursor: string) => void | Promise; onRetry: () => void | Promise; }>; export function ChatMessageDiscoveryPage({ vm, actions }: { readonly vm: ChatMessageDiscoveryVM; readonly actions: ChatMessageDiscoveryActions }) { const { t } = useTranslation(); if (vm.status === "idle" || vm.status === "loading") { return ( ); } if (vm.status === "error") { return ( void actions.onRetry()}> {t("shared.retry")} } /> ); } if (vm.status === "empty" || !vm.data) { return ( ); } const data = vm.data; const isEmptySearch = data.mode === "search" && data.query.length === 0; const emptyTitleKey = isEmptySearch ? data.keys.emptyTitleKey : data.keys.noResultsTitleKey; const emptyBodyKey = isEmptySearch ? data.keys.emptyBodyKey : data.keys.noResultsBodyKey; const switchHref = data.mode === "search" ? data.hrefs.mentions : data.hrefs.search; const switchLabelKey = data.mode === "search" ? "chat.messageDiscovery.actions.mentions" : "chat.messageDiscovery.actions.search"; return ( : } actions={ } > {data.mode === "search" ? ( actions.onQueryChange(event.target.value)} data-ui-id="ui.chat.messageDiscovery.search" /> ) : null} {data.rows.length === 0 ? ( ) : ( {data.rows.map((row) => ( ))} )} {data.nextCursor && actions.onLoadMore ? ( ) : null} ); } function DiscoveryRow({ row, onOpen }: { readonly row: ChatMessageDiscoveryRowVM; readonly onOpen: (row: ChatMessageDiscoveryRowVM) => void }) { const { t } = useTranslation(); const formatters = useLocaleFormatters(); return ( onOpen(row)} onKeyDown={(event) => { if (event.key !== "Enter" && event.key !== " ") return; event.preventDefault(); onOpen(row); }} data-message-id={row.id} > {row.authorAvatar.fallbackLabel} {row.authorLabel} {row.channelTitle} {t(row.channelKindLabelKey)} {row.isThreadReply ? ( {t("chat.messageDiscovery.result.threadReply")} ) : null} {formatters.date(row.createdAtIso, { dateStyle: "medium", timeStyle: "short" })} {row.snippet} ); } function DiscoveryShell({ title, subtitle, icon = , actions, children, }: { readonly title: string; readonly subtitle?: string; readonly icon?: React.ReactNode; readonly actions?: React.ReactNode; readonly children: React.ReactNode; }) { return ( {children} ); }