Files
5chan/src/views/home/home.tsx
T

243 lines
7.4 KiB
TypeScript
Raw Normal View History

import { useRef } from 'react';
import styles from './home.module.css';
import { Link, useNavigate } from 'react-router-dom';
import { Trans, useTranslation } from 'react-i18next';
2024-04-18 17:44:35 +02:00
import { Subplebbit, useSubplebbits } from '@plebbit/plebbit-react-hooks';
import packageJson from '../../../package.json';
2024-04-18 17:44:35 +02:00
import { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits';
const isValidAddress = (address: string): boolean => {
if (address.includes('/') || address.includes('\\') || address.includes(' ')) {
return false;
}
return true;
};
2024-03-01 20:42:21 +01:00
const SearchBar = () => {
const searchInputRef = useRef<HTMLInputElement>(null);
const { t } = useTranslation();
const navigate = useNavigate();
const handleSearchSubmit = () => {
const inputValue = searchInputRef.current?.value;
if (inputValue && isValidAddress(inputValue)) {
navigate(`/p/${inputValue}`);
} else {
alert('invalid address');
}
};
2024-03-01 20:42:21 +01:00
return (
<div className={styles.searchBar}>
<input
autoCorrect='off'
autoComplete='off'
spellCheck='false'
autoCapitalize='off'
type='text'
placeholder={`"board.eth/.sol" ${t('or')} "12D3KooW..."`}
ref={searchInputRef}
onSubmit={handleSearchSubmit}
onKeyDown={(e) => {
if (e.key === 'Enter') {
handleSearchSubmit();
}
}}
/>
<button onClick={handleSearchSubmit}>{t('go')}</button>
2024-03-01 20:42:21 +01:00
</div>
);
};
2024-03-01 20:42:21 +01:00
const InfoBox = () => {
const { t } = useTranslation();
return (
<div className={styles.box}>
2024-03-21 22:16:24 +01:00
<div className={styles.infoboxBar}>
2024-03-01 20:42:21 +01:00
<h2>{t('what_is_plebchan')}</h2>
</div>
<div className={styles.boxContent}>
<Trans i18nKey='plebchan_description' shouldUnescape={true} components={{ 1: <Link to='https://plebbit.com' target='_blank' rel='noopener noreferrer' /> }} />
<br />
<br />
{t('no_global_rules_info')}
</div>
</div>
);
};
2024-04-18 17:44:35 +02:00
const Boards = ({ subplebbits }: { subplebbits: (Subplebbit | undefined)[] }) => {
2024-03-01 20:42:21 +01:00
const { t } = useTranslation();
return (
<div className={styles.box}>
2024-03-21 22:16:24 +01:00
<div className={styles.boxBar}>
2024-03-01 20:42:21 +01:00
<h2 className={styles.capitalize}>{t('boards')}</h2>
<span>{t('options')} </span>
</div>
<div className={styles.boardsBoxContent}>
<div className={styles.column}>
<h3>Default SFW</h3>
<div className={styles.list}>
{subplebbits
2024-04-18 17:44:35 +02:00
.filter((subplebbit: Subplebbit | undefined): subplebbit is Subplebbit => subplebbit !== undefined)
.map((subplebbit: Subplebbit) => {
const address = subplebbit.address;
return (
<div className={styles.subplebbit} key={address}>
<Link to={`/p/${address}`}>{address}</Link>
</div>
);
})}
2024-03-01 20:42:21 +01:00
</div>
</div>
<div className={styles.column}>
<h3>Default NSFW</h3>
</div>
2024-03-01 20:42:21 +01:00
<div className={styles.column}>
<h3>Subscriptions</h3>
</div>
<div className={styles.column}>
<h3>Moderating</h3>
</div>
</div>
</div>
);
};
const PopularThreads = () => {
const { t } = useTranslation();
return (
<div className={styles.box}>
2024-03-15 22:42:13 +01:00
<div className={`${styles.boxBar} ${styles.color2ColorBar}`}>
2024-03-01 20:42:21 +01:00
<h2 className={styles.capitalize}>{t('popular_threads')}</h2>
<span>{t('options')} </span>
</div>
<div className={styles.boxContent}></div>
</div>
);
};
2024-03-15 22:42:13 +01:00
const Stats = () => {
const { t } = useTranslation();
return (
<div className={styles.box}>
<div className={`${styles.boxBar} ${styles.color2ColorBar}`}>
<h2 className={styles.capitalize}>{t('stats')}</h2>
</div>
<div className={styles.boxContent}></div>
</div>
);
};
const { version } = packageJson;
const downloadAppLink = (() => {
const platform = navigator.platform;
if (platform === 'Linux' || platform === 'Linux x86_64' || platform === 'Linux i686' || platform === 'Linux aarch64') {
return `https://github.com/plebbit/plebchan/releases/download/v${version}/plebchan-${version}.AppImage`;
} else if (platform === 'Win32' || platform === 'Win64' || platform === 'Windows') {
return `https://github.com/plebbit/plebchan/releases/download/v${version}/plebchan.Portable.${version}.exe`;
} else if (platform === 'MacIntel' || platform === 'Macintosh') {
return `https://github.com/plebbit/plebchan/releases/download/v${version}/plebchan-${version}.dmg`;
} else if (platform === 'Android') {
return undefined;
} else if (platform === 'iPhone' || platform === 'iPad') {
return undefined;
} else {
return undefined;
}
})();
2024-04-10 17:56:34 +02:00
const isElectron = window.isElectron === true;
const commitRef = process.env.REACT_APP_COMMIT_REF;
2024-03-15 22:42:13 +01:00
const Footer = () => {
const { t } = useTranslation();
2024-03-15 22:42:13 +01:00
return (
2024-04-10 17:56:34 +02:00
<>
<ul className={styles.footer}>
<li>
2024-04-10 17:56:34 +02:00
<a href='https://plebbit.com' target='_blank' rel='noopener noreferrer'>
{t('about')}
</a>
</li>
2024-04-10 17:56:34 +02:00
<li>
<a href='https://twitter.com/plebchan_eth' target='_blank' rel='noopener noreferrer'>
Twitter
</a>
</li>
<li>
<a href='https://t.me/plebbit' target='_blank' rel='noopener noreferrer'>
Telegram
</a>
</li>
<li>
<a href='https://discord.gg/E7ejphwzGW' target='_blank' rel='noopener noreferrer'>
Discord
</a>
</li>
<li>
<a href='https://github.com/plebbit/plebchan' target='_blank' rel='noopener noreferrer'>
GitHub
</a>
</li>
{downloadAppLink && (
<li>
<a href={downloadAppLink} target='_blank' rel='noopener noreferrer'>
{t('download_app')}
</a>
</li>
)}
<li>
<a href='https://etherscan.io/token/0xEA81DaB2e0EcBc6B5c4172DE4c22B6Ef6E55Bd8f' target='_blank' rel='noopener noreferrer'>
{t('token')}
</a>
</li>
<li>
<a href='https://github.com/plebbit/whitepaper/discussions/2' target='_blank' rel='noopener noreferrer'>
{t('whitepaper')}
</a>
</li>
</ul>
<div className={styles.version}>
<a href={`https://github.com/plebbit/plebchan/releases/tag/v${packageJson.version}`} target='_blank' rel='noopener noreferrer'>
v{packageJson.version}
2024-03-15 22:42:13 +01:00
</a>
2024-04-10 17:56:34 +02:00
{isElectron && (
<a className={styles.fullNodeStats} href='http://localhost:5001/webui/' target='_blank' rel='noreferrer'>
node stats
</a>
)}
{commitRef && (
<a href={`https://github.com/plebbit/plebchan/commit/${commitRef}`} target='_blank' rel='noopener noreferrer'>
2024-04-29 11:12:54 +02:00
#{commitRef.slice(0, 7)}
2024-04-10 17:56:34 +02:00
</a>
)}
</div>
</>
2024-03-15 22:42:13 +01:00
);
};
2024-04-18 17:44:35 +02:00
const Home = () => {
const subplebbitAddresses = useDefaultSubplebbitAddresses();
const { subplebbits } = useSubplebbits({ subplebbitAddresses });
2024-02-28 21:18:37 +01:00
return (
<div className={styles.content}>
<Link to='/'>
<div className={styles.logo}>
<img alt='' src='/assets/logo/logo-transparent.png' />
2024-02-28 21:18:37 +01:00
</div>
</Link>
2024-03-01 20:42:21 +01:00
<SearchBar />
<InfoBox />
<Boards subplebbits={subplebbits} />
2024-03-01 20:42:21 +01:00
<PopularThreads />
2024-03-15 22:42:13 +01:00
<Stats />
<Footer />
2024-02-28 21:18:37 +01:00
</div>
);
2024-02-27 17:58:08 +01:00
};
export default Home;