Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/components/screens/chat/ChatPinnedMessagesPage.tsx
T

110 lines
4.7 KiB
TypeScript

import { Link } from "react-router";
import { useTranslation } from "react-i18next";
import { FeatherArrowLeft, FeatherPin } from "@subframe/core";
import type { ChatPinnedMessagesVM } from "@hivegrid/view-models";
import { useLocaleFormatters } from "~/locale/format";
import { Alert } from "~/ui/components/Alert";
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 { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell";
import { ChatMessageFeatureCard } from "./ChatMessageFeatureCard";
export function ChatPinnedMessagesPage({
vm,
busyMessageId,
errorKey,
featureErrorKeys,
actions,
}: {
readonly vm: ChatPinnedMessagesVM;
readonly busyMessageId: string | null;
readonly errorKey: string | null;
readonly featureErrorKeys?: Readonly<Record<string, string>>;
readonly actions: {
readonly onBack: (href: string) => void;
readonly onUnpin: (messageId: string) => void;
readonly onRetryFeature?: (messageId: string) => void;
readonly onRetry: () => void;
};
}): React.JSX.Element {
const { t } = useTranslation();
const formatters = useLocaleFormatters();
const data = vm.status === "ready" ? vm.data : null;
return (
<PageShell uiId="ui.chat.pinned" className="mobile:[&_button]:min-h-11 mobile:[&_button]:min-w-11">
<PageHeader
icon={<FeatherPin className={PAGE_HEADER_ICON_CLASS} />}
title={data ? t("chat.pinned.title", { channel: data.channelTitle }) : t("chat.pinned.titleFallback")}
actions={
<Button variant="tertiary" icon={<FeatherArrowLeft />} onClick={() => data && actions.onBack(data.backHref)} disabled={!data}>
{t("shared.back")}
</Button>
}
/>
<PageBody>
{vm.status === "loading" || vm.status === "idle" ? (
<LoadingIndicatorSkeleton variant="list" aria-label={t("shared.loading")} />
) : vm.status === "error" ? (
<EmptyState
outlined
variant="error"
title={t("shared.error")}
body={t(vm.error.messageKey)}
action={<Button onClick={actions.onRetry}>{t("shared.retry")}</Button>}
/>
) : !data || data.rows.length === 0 ? (
<EmptyState outlined title={t(data?.emptyHeadlineKey ?? "chat.pinned.empty.headline")} body={t(data?.emptyBodyKey ?? "chat.pinned.empty.body")} />
) : (
<ButtonGroup align="stack">
{errorKey ? <Alert variant="error" title={t(errorKey)} notDismissible /> : null}
{data.rows.map((row) => (
<Card key={row.message.id} data-ui-id="ui.chat.pinned.row">
<ButtonGroup align="stack">
<ButtonGroup>
<BadgeFeedback farbe="subtle-information" size="small">
{t("chat.pinned.by", { user: row.pinnedByLabel })}
</BadgeFeedback>
<BadgeFeedback farbe="ghost-neutral" size="small">
{formatters.date(row.pinnedAtIso, { dateStyle: "medium", timeStyle: "short" })}
</BadgeFeedback>
</ButtonGroup>
{row.note ? <span>{row.note}</span> : null}
<ChatMessageFeatureCard
message={row.message}
featureErrorKey={featureErrorKeys?.[row.message.id]}
actions={{
onToggleReaction: () => undefined,
onTogglePin: (messageId, pinned) => pinned || actions.onUnpin(messageId),
onRetryFeature: actions.onRetryFeature,
}}
/>
<ButtonGroup>
<Link to={row.messageHref}>{t("chat.pinned.openMessage")}</Link>
{row.canUnpin ? (
<Button
variant="tertiary"
size="small"
icon={<FeatherPin />}
onClick={() => actions.onUnpin(row.message.id)}
disabled={busyMessageId === row.message.id}
loading={busyMessageId === row.message.id}
>
{t("chat.pinned.unpin")}
</Button>
) : null}
</ButtonGroup>
</ButtonGroup>
</Card>
))}
</ButtonGroup>
)}
</PageBody>
</PageShell>
);
}