mirror of
https://github.com/outline/outline.git
synced 2026-11-22 05:51:43 +03:00
* feat: Show outline document icon for empty documents * fix: Rebuild recent document actions when document state changes * feat: Thinner outline icon for empty documents
68 lines
2.2 KiB
TypeScript
68 lines
2.2 KiB
TypeScript
import { useTranslation } from "react-i18next";
|
|
import Icon from "@shared/components/Icon";
|
|
import { createInternalLinkAction } from "~/actions";
|
|
import { RecentSection } from "~/actions/sections";
|
|
import { documentBreadcrumbText } from "~/components/DocumentBreadcrumb";
|
|
import { useComputed } from "~/hooks/useComputed";
|
|
import useStores from "~/hooks/useStores";
|
|
import type Document from "~/models/Document";
|
|
import { documentPath } from "~/utils/routeHelpers";
|
|
import { DocumentIcon } from "~/components/Icons/DocumentIcon";
|
|
|
|
/** The number of documents listed under "Recently viewed" in the command bar. */
|
|
export const recentDocumentCount = 6;
|
|
|
|
/**
|
|
* Narrows recently viewed documents to those listed under "Recently viewed" in
|
|
* the command bar, so that other actions can avoid offering them a second time.
|
|
*
|
|
* @param recentlyViewed the recently viewed documents, most recent first.
|
|
* @param activeDocumentId the currently open document, which is excluded.
|
|
* @param count the maximum number of documents to return.
|
|
* @returns the documents shown in the command bar.
|
|
*/
|
|
export function recentDocuments(
|
|
recentlyViewed: Document[],
|
|
activeDocumentId: string | undefined,
|
|
count = recentDocumentCount
|
|
): Document[] {
|
|
return recentlyViewed
|
|
.filter((document) => document.id !== activeDocumentId)
|
|
.slice(0, count);
|
|
}
|
|
|
|
const useRecentDocumentActions = (count = recentDocumentCount) => {
|
|
const { documents, ui } = useStores();
|
|
const { t } = useTranslation();
|
|
|
|
return useComputed(
|
|
() =>
|
|
recentDocuments(
|
|
documents.recentlyViewed,
|
|
ui.activeDocumentId ?? undefined,
|
|
count
|
|
).map((item) =>
|
|
createInternalLinkAction({
|
|
name: item.displayTitle,
|
|
analyticsName: "Recently viewed document",
|
|
section: RecentSection,
|
|
visible: ({ isMCP }) => !isMCP,
|
|
description: documentBreadcrumbText(item, t),
|
|
icon: item.icon ? (
|
|
<Icon
|
|
value={item.icon}
|
|
initial={item.initial}
|
|
color={item.color ?? undefined}
|
|
/>
|
|
) : (
|
|
<DocumentIcon empty={item.isEmpty} />
|
|
),
|
|
to: documentPath(item),
|
|
})
|
|
),
|
|
[count, documents, ui, t]
|
|
);
|
|
};
|
|
|
|
export default useRecentDocumentActions;
|