From 3806d4755be5bd3387fbac5a407cf88368e1d2ac Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 24 Mar 2024 13:00:27 +0000 Subject: [PATCH] Fetch info about reddit sub --- web/src/utils/fetch-reddit-info.ts | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 web/src/utils/fetch-reddit-info.ts diff --git a/web/src/utils/fetch-reddit-info.ts b/web/src/utils/fetch-reddit-info.ts new file mode 100644 index 0000000..810ec5a --- /dev/null +++ b/web/src/utils/fetch-reddit-info.ts @@ -0,0 +1,38 @@ + +export const fetchRedditInfo = async (subreddit: string): Promise => { + const endpoint = `https://subreddit-info.as93.net/${subreddit}`; + try { + return await fetch(endpoint).then((res) => res.json()); + } catch (error) { + console.error('Error fetching reddit data:', error); + return null; + } +}; + +interface SubredditInfo { + name: string | null; + title: string | null; + description: string | null; + longDescription: string | null; + icon: string | null; + banner: string | null; + color: string | null; + subscribers: number | null; + activeSubscribers: number | null; + dateCreated: number | null; + descriptionHtml: string | null; +} + +interface Post { + title: string; + body: string; + upVotes: number; + downVotes: number; + date: number; + url: string; +} + +export interface RedditData { + info: SubredditInfo; + posts: Post[]; +}