-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from hookdeck/feat/support-edits
feat: edit the title and description
- Loading branch information
Showing
24 changed files
with
3,411 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use server"; | ||
|
||
import { VlogItem } from "@/types/VlogItem"; | ||
import { createClient } from "@/utils/supabase/server"; | ||
import { revalidatePath } from "next/cache"; | ||
|
||
export async function updateVlog(prevState: any, formData: FormData) { | ||
const supabase = createClient(); | ||
const { | ||
data: { user }, | ||
} = await supabase.auth.getUser(); | ||
if (!user) { | ||
throw new Error("You must be logged in to update a vlog title"); | ||
} | ||
|
||
const vlogId = formData.get("vlogId") as string; | ||
const title = formData.get("title") as string; | ||
const description = formData.get("description") as string; | ||
|
||
// TODO: validate form data | ||
const updates: { title?: string; description?: string } = {}; | ||
if (title) { | ||
updates["title"] = title; | ||
} | ||
if (description) { | ||
updates["description"] = description; | ||
} | ||
|
||
const { data, error } = await supabase | ||
.from("videos") | ||
.select("*") | ||
.eq("id", vlogId) | ||
.single(); | ||
|
||
if (error) { | ||
// TODO: handle error | ||
console.error("Could not find vlog with ID", vlogId); | ||
return; | ||
} | ||
|
||
if (data) { | ||
const vlog = data as VlogItem; | ||
const { error } = await supabase | ||
.from("videos") | ||
.update(updates) | ||
.eq("id", vlogId); | ||
if (!error) { | ||
revalidatePath(`/vlogs/${vlog.by_username}/${vlogId}`); | ||
return { updated: true }; | ||
} else { | ||
// TODO: handle error | ||
console.error("Error updating vlog title for vlog with ID", vlogId); | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.