Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
"use client";
import { focusManager, useQuery } from "@tanstack/react-query";
import { ArchiveRestore } from "@multica/ui/icons";
import { toast } from "sonner";
import { useWorkspaceId } from "@multica/core/hooks";
import { archivedInboxLookupOptions, useUnarchiveInbox } from "@multica/core/inbox";
import type { MenuPrimitives } from "./issue-actions-menu-items";
import { useT } from "../../i18n";
/** The reader's archived inbox notification for this issue, if any. An issue
* opened from search or a link has no other way out of Inbox → Archived. */
export function useArchivedInboxItemId(issueId: string, enabled: boolean): string | undefined {
const wsId = useWorkspaceId();
// Every inbox event refetches this lookup, so a hidden page skips it like the unread summary does.
// The host calls this rather than the lazily mounted menu, so the entry doesn't pop in after opening.
const { data } = useQuery({
...archivedInboxLookupOptions(wsId, issueId),
enabled: () => enabled && focusManager.isFocused(),
refetchOnWindowFocus: true,
});
return enabled ? data?.items.find((i) => i.archived)?.id : undefined;
}
export function InboxRestoreMenuItem({ itemId, Item }: { itemId: string; Item: MenuPrimitives["Item"] }) {
const { t } = useT("issues");
const { t: tInbox } = useT("inbox");
const { mutateAsync: unarchive } = useUnarchiveInbox();
return (
<Item
// The menu closes on click and unmounts this item, so the toasts follow
// the request's promise rather than per-call mutation callbacks.
onClick={() =>
unarchive(itemId).then(
() => toast.success(tInbox(($) => $.toasts.unarchived)),
(err) =>
toast.error(
err instanceof Error && err.message
? err.message
: tInbox(($) => $.errors.unarchive_failed),
),
)
}
>
<ArchiveRestore className="h-3.5 w-3.5" />
{t(($) => $.actions.restore_to_inbox)}
</Item>
);
}