web/src/utils/fetch-reddit-info.ts

38 lines · 779 bytes

4 symbols in this file
 1import { fetchEnrich } from './fetch-enrich';
 2
 3export const fetchRedditInfo = (
 4  subreddit: string,
 5): Promise<RedditData | null> =>
 6  fetchEnrich<RedditData>(
 7    'Reddit',
 8    `/v1/enrich/reddit/${subreddit}`,
 9    `r/${subreddit}`,
10  );
11
12interface SubredditInfo {
13  name: string | null;
14  title: string | null;
15  description: string | null;
16  longDescription: string | null;
17  icon: string | null;
18  banner: string | null;
19  color: string | null;
20  subscribers: number | null;
21  activeSubscribers: number | null;
22  dateCreated: number | null;
23  descriptionHtml: string | null;
24}
25
26interface Post {
27  title: string;
28  body: string;
29  upVotes: number;
30  downVotes: number;
31  date: number;
32  url: string;
33}
34
35export interface RedditData {
36  info: SubredditInfo;
37  posts: Post[];
38}