diff --git a/functions/src/models/TanamDocument.ts b/functions/src/models/TanamDocument.ts index 51cd9d12..642194fa 100644 --- a/functions/src/models/TanamDocument.ts +++ b/functions/src/models/TanamDocument.ts @@ -32,7 +32,14 @@ export abstract class TanamDocument { public readonly createdAt?: TimestampType; public readonly updatedAt?: TimestampType; - abstract get status(): TanamPublishStatus; + get status(): TanamPublishStatus { + if (!this.publishedAt) { + return "unpublished"; + } else { + return "published"; + } + } + protected abstract getServerTimestamp(): FieldValueType; toJson(): object { diff --git a/functions/src/models/TanamDocumentAdmin.ts b/functions/src/models/TanamDocumentAdmin.ts index 38cb866a..7b4ec7b3 100644 --- a/functions/src/models/TanamDocumentAdmin.ts +++ b/functions/src/models/TanamDocumentAdmin.ts @@ -1,22 +1,12 @@ import {FieldValue, Timestamp} from "firebase-admin/firestore"; -import {ITanamDocument, TanamDocument, TanamPublishStatus} from "./TanamDocument"; import {DocumentSnapshot} from "firebase-functions/v2/firestore"; +import {ITanamDocument, TanamDocument} from "./TanamDocument"; export class TanamDocumentAdmin extends TanamDocument { constructor(id: string, json: ITanamDocument) { super(id, json); } - get status(): TanamPublishStatus { - if (!this.publishedAt) { - return "unpublished"; - } else if (this.publishedAt.toMillis() > Timestamp.now().toMillis()) { - return "scheduled"; - } else { - return "published"; - } - } - getServerTimestamp(): FieldValue { return FieldValue.serverTimestamp(); } diff --git a/hosting/src/app/(protected)/content/article/[documentId]/page.tsx b/hosting/src/app/(protected)/content/article/[documentId]/page.tsx index 1bfc5aca..20554a37 100644 --- a/hosting/src/app/(protected)/content/article/[documentId]/page.tsx +++ b/hosting/src/app/(protected)/content/article/[documentId]/page.tsx @@ -12,7 +12,7 @@ export default function DocumentDetailsPage() { const router = useRouter(); const {documentId} = useParams<{documentId: string}>() ?? {}; const {data: document, error: documentError} = useTanamDocument(documentId); - const {update, error: writeError} = useCrudTanamDocument(documentId); + const {update, error: writeError} = useCrudTanamDocument(); const [readonlyMode] = useState(false); const [notification, setNotification] = useState(null); if (!!document?.documentType && document?.documentType !== "article") { @@ -26,7 +26,12 @@ export default function DocumentDetailsPage() { async function onDocumentContentChange(content: string) { console.log("[onDocumentContentChange]", content); - await update({data: {...document?.data, content}}); + if (!document) { + return; + } + + document.data.content = content; + await update(document); } return ( diff --git a/hosting/src/app/(protected)/content/article/page.tsx b/hosting/src/app/(protected)/content/article/page.tsx index aa954489..dea7e72f 100644 --- a/hosting/src/app/(protected)/content/article/page.tsx +++ b/hosting/src/app/(protected)/content/article/page.tsx @@ -5,24 +5,26 @@ import Loader from "@/components/common/Loader"; import Notification from "@/components/common/Notification"; import PageHeader from "@/components/common/PageHeader"; import {useTanamDocumentType} from "@/hooks/useTanamDocumentTypes"; -import {useCreateTanamDocument, useTanamDocuments} from "@/hooks/useTanamDocuments"; +import {useCrudTanamDocument, useTanamDocuments} from "@/hooks/useTanamDocuments"; import {UserNotification} from "@/models/UserNotification"; import {useRouter} from "next/navigation"; import {Suspense, useEffect, useState} from "react"; export default function DocumentTypeDocumentsPage() { const {data: documentType} = useTanamDocumentType("article"); - const {create, error: writeError} = useCreateTanamDocument(documentType?.id); + const {create, error: crudError} = useCrudTanamDocument(); const {data: documents, error: docsError} = useTanamDocuments("article"); const [notification, setNotification] = useState(null); const router = useRouter(); useEffect(() => { - setNotification(docsError || writeError); - }, [docsError, writeError]); + setNotification(docsError || crudError); + }, [docsError, crudError]); const addNewArticle = async () => { - const id = await create(); + const id = await create(documentType?.id); + + if (!id) return; router.push(`article/${id}`); }; diff --git a/hosting/src/components/Button.tsx b/hosting/src/components/Button.tsx index 40e73142..7466811e 100644 --- a/hosting/src/components/Button.tsx +++ b/hosting/src/components/Button.tsx @@ -36,16 +36,16 @@ export function Button({title, onClick, style = "normal", color = "primary", chi switch (color) { case "primary": - styles.push("bg-primary", "text-white"); + styles.push("bg-primary", !style ? "text-white" : ""); break; case "meta-3": - styles.push("bg-meta-3", "text-white"); + styles.push("bg-meta-3", !style ? "text-white" : ""); break; case "black": - styles.push("bg-black", "text-white"); + styles.push("bg-black", !style ? "text-white" : ""); break; default: - styles.push("bg-primary", "text-white"); + styles.push("bg-primary", !style ? "text-white" : ""); } switch (style) { diff --git a/hosting/src/components/Header/index.tsx b/hosting/src/components/Header/index.tsx index 37b5e5d6..22506662 100644 --- a/hosting/src/components/Header/index.tsx +++ b/hosting/src/components/Header/index.tsx @@ -1,14 +1,18 @@ import DarkModeSwitcher from "@/components/Header/DarkModeSwitcher"; import DropdownUser from "@/components/Header/DropdownUser"; +import {TogglePublishDocument} from "@/components/TogglePublishDocument"; import {useAuthentication} from "@/hooks/useAuthentication"; import Image from "next/image"; import Link from "next/link"; const Header = (props: {sidebarOpen: string | boolean | undefined; setSidebarOpen: (arg0: boolean) => void}) => { const {authUser} = useAuthentication(); + return (
+ +
{/* */}