diff --git a/apps/sovoli.com/src/app/[username]/[slug]/actions/updateTitleAction.ts b/apps/sovoli.com/src/app/[username]/[slug]/actions/updateTitleAction.ts index 925db7e4..a6df7b19 100644 --- a/apps/sovoli.com/src/app/[username]/[slug]/actions/updateTitleAction.ts +++ b/apps/sovoli.com/src/app/[username]/[slug]/actions/updateTitleAction.ts @@ -1,5 +1,6 @@ "use server"; +import { revalidatePath } from "next/cache"; import { unauthorized } from "next/navigation"; import { withZod } from "@rvf/zod"; import { db, eq, schema } from "@sovoli/db"; @@ -41,7 +42,7 @@ export async function updateTitleAction( }) .where(eq(schema.Knowledge.id, result.data.id)); - return { - status: "success", - }; + revalidatePath("[username]/[slug]", "page"); + + return { status: "success" }; } diff --git a/apps/sovoli.com/src/app/[username]/[slug]/components/title/KnowledgeTitle.tsx b/apps/sovoli.com/src/app/[username]/[slug]/components/title/KnowledgeTitle.tsx index f81657ff..7ce15d28 100644 --- a/apps/sovoli.com/src/app/[username]/[slug]/components/title/KnowledgeTitle.tsx +++ b/apps/sovoli.com/src/app/[username]/[slug]/components/title/KnowledgeTitle.tsx @@ -9,6 +9,7 @@ import { TitleUpdateForm } from "./TitleUpdateForm"; export function KnowledgeTitle() { const knowledge = useKnowledge(); + const [title, setTitle] = useState(knowledge.title ?? ""); const { data: session } = useSession(); const [isEditing, setIsEditing] = useState(false); @@ -20,10 +21,14 @@ export function KnowledgeTitle() { id={knowledge.id} title={knowledge.title ?? ""} onCancel={() => setIsEditing(false)} + onSubmitted={(newTitle) => { + setTitle(newTitle); + setIsEditing(false); + }} /> ) : (