diff --git a/src/app.tsx b/src/app.tsx index 7183a6ba..8b5841d1 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -1,33 +1,39 @@ import { useEffect } from 'react'; import { Outlet, Route, Routes, useLocation, useParams } from 'react-router-dom'; import { isHomeView } from './lib/utils/view-utils'; -import { useSubplebbit } from '@plebbit/plebbit-react-hooks'; -import styles from './app.module.css'; +import { Subplebbit as SubplebbitType, useSubplebbits } from '@plebbit/plebbit-react-hooks'; +import { useDefaultSubplebbitAddresses } from './hooks/use-default-subplebbits'; import useTheme from './hooks/use-theme'; +import styles from './app.module.css'; import Home from './views/home'; import Settings from './views/settings'; import Subplebbit from './views/subplebbit'; import BoardNav from './components/board-nav'; import BoardBanner from './components/board-banner'; +import { DesktopBoardButtons } from './components/board-buttons'; +import { MobileBoardButtons } from './components/board-buttons'; import BoardStats from './components/board-stats'; import PostForm from './components/post-form'; -import { MobileBoardButtons } from './components/board-buttons'; -import { DesktopBoardButtons } from './components/board-buttons'; -const BoardLayout = () => { +interface BoardLayoutProps { + subplebbits: (SubplebbitType | undefined)[]; +} + +const BoardLayout = ({ subplebbits }: BoardLayoutProps) => { const { subplebbitAddress } = useParams<{ subplebbitAddress: string }>(); - const subplebbit = useSubplebbit({ subplebbitAddress }); + const subplebbit = subplebbits.find((s) => s?.address === subplebbitAddress); + const { address, createdAt, title } = subplebbit || {}; return ( <> - {subplebbitAddress && ( + {address && ( <> - - - - - - + + + + + + )} @@ -40,6 +46,11 @@ const App = () => { const location = useLocation(); const isInHomeView = isHomeView(location.pathname); + const subplebbitAddresses = useDefaultSubplebbitAddresses(); + const { subplebbits } = useSubplebbits({ subplebbitAddresses }); + + console.log(subplebbits); + useEffect(() => { document.body.classList.forEach((className) => document.body.classList.remove(className)); document.body.classList.add(theme); @@ -55,9 +66,9 @@ const App = () => { return (
- } /> - }> - } /> + } /> + }> + } /> } /> diff --git a/src/components/board-nav/board-nav.tsx b/src/components/board-nav/board-nav.tsx index 309ceb7e..459e1bc1 100644 --- a/src/components/board-nav/board-nav.tsx +++ b/src/components/board-nav/board-nav.tsx @@ -1,11 +1,11 @@ import { Link, useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import useDefaultSubplebbits from '../../hooks/use-default-subplebbits'; +import { Subplebbit } from '@plebbit/plebbit-react-hooks'; import styles from './board-nav.module.css'; interface BoardNavProps { address?: string | undefined; - subplebbits?: any; + subplebbits: (Subplebbit | undefined)[]; currentSubplebbit?: string | undefined; } @@ -16,15 +16,18 @@ const BoardNavDesktop = ({ subplebbits }: BoardNavProps) => {
[ - {subplebbits.map((subplebbit: any, index: number) => ( - - {index === 0 ? null : ' '} - - {subplebbit.address.includes('.') ? subplebbit.address : subplebbit.title || subplebbit.address.slice(0, 10).concat('...')} - - {index !== subplebbits.length - 1 ? ' /' : null} - - ))} + {subplebbits.map((subplebbit: any, index: number) => { + const { address, title } = subplebbit; + return ( + + {index === 0 ? null : ' '} + + {address.includes('.') ? address : title || address.slice(0, 10).concat('...')} + + {index !== subplebbits.length - 1 ? ' /' : null} + + ); + })} ] @@ -72,13 +75,11 @@ const BoardNavMobile = ({ subplebbits, currentSubplebbit }: BoardNavProps) => { ); }; -const BoardNav = ({ address }: BoardNavProps) => { - const defaultSubplebbits = useDefaultSubplebbits(); - +const BoardNav = ({ address, subplebbits }: BoardNavProps) => { return ( <> - - + + ); }; diff --git a/src/components/markdown/markdown.tsx b/src/components/markdown/markdown.tsx index 05885d65..091798ea 100644 --- a/src/components/markdown/markdown.tsx +++ b/src/components/markdown/markdown.tsx @@ -4,7 +4,6 @@ import ReactMarkdown from 'react-markdown'; import rehypeSanitize, { defaultSchema } from 'rehype-sanitize'; import remarkGfm from 'remark-gfm'; import supersub from 'remark-supersub'; -import { visit } from 'unist-util-visit'; interface MarkdownProps { content: string; diff --git a/src/components/post/post.module.css b/src/components/post/post.module.css index a518f3d0..c0362a5e 100644 --- a/src/components/post/post.module.css +++ b/src/components/post/post.module.css @@ -2,11 +2,11 @@ clear: both; } -.hrWrapper hr { +.postDesktop .hrWrapper hr { margin: 0; /* margin bugs Virtuoso scrolling */ } -.hrWrapper { +.postDesktop .hrWrapper { padding-top: 0.5em; /* instead of using margin, wrap with padding */ padding-bottom: 0.5em; } @@ -89,8 +89,24 @@ padding: 1em 40px; } +.postMobile hr { + padding-bottom: 30px; +} + +.postMobile .thread { + border-top: none; + margin: 0; + clear: both; +} + @media (max-width: 640px) { .postDesktop { display: none; } +} + +@media (min-width: 641px) { + .postMobile { + display: none; + } } \ No newline at end of file diff --git a/src/components/post/post.tsx b/src/components/post/post.tsx index c33cd6c3..fc301ceb 100644 --- a/src/components/post/post.tsx +++ b/src/components/post/post.tsx @@ -7,7 +7,7 @@ import { getLinkMediaInfoMemoized } from '../../lib/utils/media-utils'; import { getFormattedDate } from '../../lib/utils/time-utils'; import Markdown from '../markdown'; -const Post = ({ post }: Comment) => { +const PostDesktop = ({ post }: Comment) => { const { t } = useTranslation(); const { author, cid, content, link, locked, pinned, postCid, shortCid, subplebbitAddress, timestamp, title } = post || {}; const { displayName, shortAddress } = author || {}; @@ -15,64 +15,85 @@ const Post = ({ post }: Comment) => { const linkMediaInfo = getLinkMediaInfoMemoized(link); return ( -
-
-
-
-
-
- {linkMediaInfo?.url && ( - - )} -
- {title && {title.length > 75 ? title.slice(0, 75) + '...' : title}}{' '} - - {displayName || 'Anonymous'} - (u/{shortAddress}) +
+
+
+
+ {linkMediaInfo?.url && ( + + )} +
+ {title && {title.length > 75 ? title.slice(0, 75) + '...' : title}}{' '} + + {displayName || 'Anonymous'} + (u/{shortAddress}) + + {getFormattedDate(timestamp)} + + + + c/ + + + {shortCid} - {getFormattedDate(timestamp)} - - - - c/ - - - {shortCid} - - - {pinned && ( - - - - )} - {locked && ( - - - - )} - - [{t('reply')}] - + + {pinned && ( + + - -
- {content && ( -
-
- -
-
)} + {locked && ( + + + + )} + + [{t('reply')}] + + + +
+ {content && ( +
+
+ +
+
+ )} +
+ ); +}; + +const PostMobile = ({ post }: Comment) => { + return ( +
+
+
+
+
+
); }; +const Post = ({ post }: Comment) => { + return ( +
+
+ + +
+
+ ); +}; + export default Post; diff --git a/src/views/home/home.tsx b/src/views/home/home.tsx index d344385b..69b902b1 100644 --- a/src/views/home/home.tsx +++ b/src/views/home/home.tsx @@ -2,9 +2,13 @@ import { useRef } from 'react'; import styles from './home.module.css'; import { Link, useNavigate } from 'react-router-dom'; import { Trans, useTranslation } from 'react-i18next'; -import { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits'; +import { Subplebbit } from '@plebbit/plebbit-react-hooks'; import packageJson from '../../../package.json'; +interface HomeProps { + subplebbits: (Subplebbit | undefined)[]; +} + const isValidAddress = (address: string): boolean => { if (address.includes('/') || address.includes('\\') || address.includes(' ')) { return false; @@ -65,9 +69,8 @@ const InfoBox = () => { ); }; -const Boards = () => { +const Boards = ({ subplebbits }: HomeProps) => { const { t } = useTranslation(); - const defaultSubplebbitAddresses = useDefaultSubplebbitAddresses(); return (
@@ -79,11 +82,16 @@ const Boards = () => {

Default SFW

- {defaultSubplebbitAddresses.map((address) => ( -
- {address} -
- ))} + {subplebbits + .filter((subplebbit): subplebbit is Subplebbit => subplebbit !== undefined) + .map((subplebbit) => { + const address = subplebbit.address; + return ( +
+ {address} +
+ ); + })}
@@ -193,7 +201,7 @@ const Footer = () => { ); }; -const Home = () => { +const Home = ({ subplebbits }: HomeProps) => { return (
@@ -203,7 +211,7 @@ const Home = () => { - +