Skip to content

Commit

Permalink
Finalizing gifting page
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljolley committed Dec 1, 2024
1 parent e561cb2 commit 7013464
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 49 deletions.
10 changes: 6 additions & 4 deletions src/components/giving/Giving.astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
export const prerender = false;
import GivingForm from './GivingForm.astro';
import NotSubbed from './NotSubbed.astro';
import Registered from './Registered.astro';
import SignIn from './SignIn.astro';
import { getSub } from '@lib/supabase';
import { isSub } from '@scripts/twitch';
import { subCheck } from '@scripts/twitch';
export interface Props {
user: {
Expand All @@ -15,7 +16,7 @@ export interface Props {
};
}
const { user } = Astro.props;
const isSubscriber = user ? await isSub(user.user_id) : null;
const check = user ? await subCheck(user.user_id) : null;
const registered = user ? await getSub(user.id) : null;
---
Expand All @@ -26,10 +27,11 @@ const registered = user ? await getSub(user.id) : null;
{!user &&
<SignIn />
}
{user && !isSubscriber &&
{user && !check?.isSub &&
<NotSubbed user={user} />
<!-- ({check.status} {check.message}) -->
}
{user && isSubscriber && !registered &&
{user && check?.isSub && !registered &&
<GivingForm user={user} />
}
{user && registered &&
Expand Down
1 change: 0 additions & 1 deletion src/components/giving/GivingForm.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
export interface Props {
user: {
id: string;
Expand Down
1 change: 0 additions & 1 deletion src/components/giving/NotSubbed.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
export interface Props {
user: {
id: string;
Expand Down
9 changes: 0 additions & 9 deletions src/components/giving/SignIn.astro
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
---
import Icon from "@components/Icon.astro"
export interface Props {
user: {
id: string;
nickname: string;
profileImg: string;
};
}
const { user } = Astro.props;
---

<h3>Get in on the fun!</h3>
Expand Down
3 changes: 0 additions & 3 deletions src/pages/notyou.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ const permalink = `https://${import.meta.env.HOST}/`;
const user = await authData(Astro.cookies);
if (user && user.nickname.toLowerCase() === "cmjchrisjones") {
Astro.redi
}
---

<html>
Expand Down
13 changes: 0 additions & 13 deletions src/pages/register.astro

This file was deleted.

15 changes: 0 additions & 15 deletions src/pages/signin.astro

This file was deleted.

14 changes: 11 additions & 3 deletions src/scripts/twitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,28 @@ export async function isOnline(): Promise<string> {
return thumbnail;
}

export async function isSub(userId: string): Promise<boolean> {
export async function subCheck(userId: string): Promise<{isSub: boolean, err: any}> {
const headers = await getATHeaders();
const response = await fetch(
`https://api.twitch.tv/helix/subscriptions?broadcaster_id=${import.meta.env.TWITCH_CHANNEL_ID}&user_id=${userId}`,
{
headers,
},
);


const body = await response.text();
const { data: subscribers } = JSON.parse(body);

if (subscribers && subscribers.length > 0) {
return true;
return {
isSub: true,
err: null
};
}

return false;
return {
isSub: false,
err: {status: response.status, message: response.statusText}
};
}

0 comments on commit 7013464

Please sign in to comment.