Skip to content

Commit

Permalink
feat/refactor: reddit comments (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathen-Smith committed Mar 25, 2024
1 parent 233878c commit b9a715a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 11 deletions.
40 changes: 40 additions & 0 deletions components/Reddit/RedditComment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import useDarkMode from '../../hooks/useDarkMode';
import useScript from '../../hooks/useScript';

interface RedditCommentEmbedProps {
commentUrl: string;
postAuthor: string;
discussionUrl: string;
subreddit: string;
height: number;
}

export default function RedditComment({
commentUrl,
postAuthor,
discussionUrl,
subreddit,
height,
}: RedditCommentEmbedProps) {
const { isDark } = useDarkMode();
useScript('https://embed.reddit.com/widgets.js');

return (
<blockquote
className="reddit-embed-bq"
style={{ height: `${height.toString()}px` }}
data-embed-height={height.toString()}
data-embed-theme={isDark ? 'dark' : 'light'}
>
<a href={commentUrl}>Comment</a>
<br />
by
<a href={`https://www.reddit.com/user/${postAuthor}/`}>u/{postAuthor}</a>
from discussion
<a href={discussionUrl}>s</a>
<br />
in
<a href={`https://www.reddit.com/r/${subreddit}/`}>{subreddit}</a>
</blockquote>
);
}
14 changes: 8 additions & 6 deletions components/RedditPost.tsx → components/Reddit/RedditPost.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import useDarkMode from '../hooks/useDarkMode';
import useScript from '../hooks/useScript';
import useDarkMode from '../../hooks/useDarkMode';
import useScript from '../../hooks/useScript';

interface RedditEmbedProps {
interface RedditPostEmbedProps {
url: string;
title: string;
author: string;
subreddit: string;
height: number;
}

export default function RedditPost({
url,
title,
author,
subreddit,
}: RedditEmbedProps) {
height,
}: RedditPostEmbedProps) {
const { isDark } = useDarkMode();
useScript('https://embed.reddit.com/widgets.js');

return (
<blockquote
className="reddit-embed-bq"
style={{ height: '316px' }}
data-embed-height="316"
style={{ height: `${height.toString()}px` }}
data-embed-height={height.toString()}
data-embed-theme={isDark ? 'dark' : 'light'}
>
<a href={url}>{title}</a>
Expand Down
9 changes: 9 additions & 0 deletions components/Reddit/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import dynamic from 'next/dynamic';

export const RedditPost = dynamic(() => import('./RedditPost'), {
ssr: false,
});

export const RedditComment = dynamic(() => import('./RedditComment'), {
ssr: false,
});
7 changes: 2 additions & 5 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
import '../styles/globals.css';
import type { AppProps } from 'next/app';
import { MDXProvider } from '@mdx-js/react';
import dynamic from 'next/dynamic';

import Tweet from '../components/Tweet';
import { RedditPost, RedditComment } from '../components/Reddit';

const RedditPost = dynamic(() => import('../components/RedditPost'), {
ssr: false,
});
const components = { Tweet, RedditPost };
const components = { Tweet, RedditPost, RedditComment };

function MyApp({ Component, pageProps }: AppProps) {
return (
Expand Down

0 comments on commit b9a715a

Please sign in to comment.