50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
|
|
import type { ArticleDetail } from "@geo/shared-types";
|
||
|
|
|
||
|
|
export interface ArticleActionState {
|
||
|
|
showPublish: boolean;
|
||
|
|
showEdit: boolean;
|
||
|
|
showPreview: boolean;
|
||
|
|
showCopy: boolean;
|
||
|
|
showDelete: boolean;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function resolveArticleActionState(generateStatus?: string | null): ArticleActionState {
|
||
|
|
if (generateStatus === "completed") {
|
||
|
|
return {
|
||
|
|
showPublish: true,
|
||
|
|
showEdit: true,
|
||
|
|
showPreview: true,
|
||
|
|
showCopy: true,
|
||
|
|
showDelete: true,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
if (generateStatus === "draft" || generateStatus === "failed") {
|
||
|
|
return {
|
||
|
|
showPublish: false,
|
||
|
|
showEdit: true,
|
||
|
|
showPreview: false,
|
||
|
|
showCopy: false,
|
||
|
|
showDelete: true,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
return {
|
||
|
|
showPublish: false,
|
||
|
|
showEdit: false,
|
||
|
|
showPreview: true,
|
||
|
|
showCopy: false,
|
||
|
|
showDelete: true,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
export function buildArticleClipboardContent(detail: Pick<ArticleDetail, "title" | "markdown_content">): string {
|
||
|
|
return [
|
||
|
|
detail.title ? `# ${detail.title}` : "",
|
||
|
|
detail.markdown_content ?? "",
|
||
|
|
]
|
||
|
|
.filter(Boolean)
|
||
|
|
.join("\n\n")
|
||
|
|
.trim();
|
||
|
|
}
|