From 8984f4bea2dda8fb5e8154ab6f6cb2cbcadab05a Mon Sep 17 00:00:00 2001 From: Korbs Date: Fri, 9 Aug 2024 00:58:40 -0400 Subject: [PATCH] Add follow button for channels --- source/src/pages/api/subscription/add.astro | 24 +++++++++++++++++ .../src/pages/api/subscription/remove.astro | 21 +++++++++++++++ source/src/pages/channel/[...slug].astro | 27 ++++++++++++++++--- 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 source/src/pages/api/subscription/add.astro create mode 100644 source/src/pages/api/subscription/remove.astro diff --git a/source/src/pages/api/subscription/add.astro b/source/src/pages/api/subscription/add.astro new file mode 100644 index 0000000..93c14f8 --- /dev/null +++ b/source/src/pages/api/subscription/add.astro @@ -0,0 +1,24 @@ +--- +import Base from "@layouts/Default.astro" +const CreatorId = Astro.url.href.split("add?=").pop() +import { supabase } from "@library/supabase" +const { data: { user } } = await supabase.auth.getUser() +const { data, error } = await supabase + .from('subs') + .insert([ + { + UserSubscribed: user?.id, + Id: CreatorId, + Platform: "YouTube" + }, + ]) + .select() + +return Astro.redirect("/channel/" + CreatorId) +--- + + +
+

One moment...

+
+ \ No newline at end of file diff --git a/source/src/pages/api/subscription/remove.astro b/source/src/pages/api/subscription/remove.astro new file mode 100644 index 0000000..25f467a --- /dev/null +++ b/source/src/pages/api/subscription/remove.astro @@ -0,0 +1,21 @@ +--- +import Base from "@layouts/Default.astro" +const CreatorId = Astro.url.href.split("remove?=").pop() +import { supabase } from "@library/supabase" +const { data: { user } } = await supabase.auth.getUser() +const id = user?.id +const { data, error } = await supabase + .from('subs') + .delete() + .eq('UserSubscribed', id) + .eq('Id', CreatorId) + .eq('Platform', 'YouTube') + +return Astro.redirect("/channel/" + CreatorId) +--- + + +
+

One moment...

+
+ \ No newline at end of file diff --git a/source/src/pages/channel/[...slug].astro b/source/src/pages/channel/[...slug].astro index 5cd8e72..dde71c4 100755 --- a/source/src/pages/channel/[...slug].astro +++ b/source/src/pages/channel/[...slug].astro @@ -13,15 +13,36 @@ import { BrightStar, Donate, Download, ShareIos, ThumbsUp } from "@iconoir/vue"; import Video from '@components/VideoItem.astro' // Fetch -const SWV = Astro.url.href.split("channel/").pop(); -const channel = await fetch(DEFAULT_MEDIA_DATA_PROXY + "/api/v1/channels/" + SWV).then((response) => response.json()); +const CreatorId = Astro.url.href.split("channel/").pop(); +const channel = await fetch(DEFAULT_MEDIA_DATA_PROXY + "/api/v1/channels/" + CreatorId).then((response) => response.json()); const DescriptionFormat = channel.descriptionHtml.replaceAll("\n", "
"); + +// User Subscription +import { supabase } from "@library/supabase" +const { data: { user } } = await supabase.auth.getUser() +const id = user?.id +let { data: subs } = await supabase + .from('subs') + .select("*") + .eq('UserSubscribed', id) + .eq('Id', CreatorId) + +if (subs[0] === undefined) { + var Subbed = false +} else { + var Subbed = true +} ---
+ {Subbed ? + Unfollow + : + Follow + }
@@ -29,7 +50,7 @@ const DescriptionFormat = channel.descriptionHtml.replaceAll("\n", "
");
- +

{channel.author}

{channel.subCountText}