import { useEffect, useState, FormEvent } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import { useCommunity } from '@bitsocial/bitsocial-react-hooks'; import { Footer, HomeLogo } from '../home'; import { useDirectories, DirectoryCommunity, findDirectoryByAddress } from '../../hooks/use-directories'; import { useCommunityIdentifier } from '../../hooks/use-community-identifiers'; import { getCommunityAddress, getBoardPath } from '../../lib/utils/route-utils'; import Markdown from '../../components/markdown'; import styles from './rules.module.css'; import { useTranslation } from 'react-i18next'; import lowerCase from 'lodash/lowerCase'; const getBoardShortCode = (title?: string): string => { if (!title) return ''; const match = title.match(/^\/([^/]+)\//); return match ? match[1] : ''; }; const getBoardName = (title?: string): string => { if (!title) return ''; const match = title.match(/^\/[^/]+\/\s*-\s*(.+)$/); return match ? match[1] : title; }; const BoardRulesDisplay = ({ communityAddress, directories }: { communityAddress: string; directories: DirectoryCommunity[] }) => { const communityIdentifier = useCommunityIdentifier(communityAddress); const community = useCommunity(communityIdentifier ? { community: communityIdentifier } : undefined); const { rules, state, title, shortAddress } = community || {}; let loadingText: string | null = null; if (!community) { loadingText = 'connecting...'; } else { switch (state) { case 'fetching-ipns': case 'fetching-ipfs': loadingText = 'loading...'; break; case 'failed': loadingText = 'failed to load'; break; case 'succeeded': loadingText = null; break; default: loadingText = state ? `${state}...` : 'loading...'; } } const isLoaded = state === 'succeeded'; const defaultSub = directories.find((sub) => sub.address === communityAddress); let displayTitle: string; if (defaultSub?.title) { const shortCode = getBoardShortCode(defaultSub.title); const boardName = getBoardName(defaultSub.title); displayTitle = `Rules for: /${shortCode}/ - ${boardName}`; } else if (title) { const shortCode = getBoardShortCode(title); const boardName = getBoardName(title); if (shortCode && boardName && boardName !== title) { displayTitle = `Rules for: /${shortCode}/ - ${boardName}`; } else { displayTitle = `Rules for: ${shortAddress || communityAddress}`; } } else { displayTitle = `Rules for: ${shortAddress || communityAddress}`; } return (

{displayTitle}

{!isLoaded ? (

{loadingText}

) : rules && rules.length > 0 ? (
    {rules.map((rule: string, index: number) => (
  1. ))}
) : (

This board has no rules set by its owner.

)}
); }; const BoardSelector = ({ directories, selectedAddress, onSelect, }: { directories: DirectoryCommunity[]; selectedAddress: string; onSelect: (address: string) => void; }) => { const [customAddress, setCustomAddress] = useState(''); const selectedDefaultBoard = findDirectoryByAddress(directories, selectedAddress); const selectedBoardValue = selectedDefaultBoard?.address ?? ''; const handleSelectChange = (e: React.ChangeEvent) => { const value = e.target.value; if (value) { onSelect(value); setCustomAddress(''); } }; const handleCustomSubmit = (e: FormEvent) => { e.preventDefault(); const trimmed = customAddress.trim(); if (trimmed) { onSelect(trimmed); } }; const { t } = useTranslation(); return (

Load rules from a board

or
setCustomAddress(e.target.value)} className={styles.addressInput} />
); }; const Rules = () => { const { boardIdentifier } = useParams(); const navigate = useNavigate(); const directories = useDirectories(); const selectedAddress = boardIdentifier ? getCommunityAddress(boardIdentifier, directories) : ''; const handleBoardSelect = (address: string) => { const path = getBoardPath(address, directories); navigate(`/rules/${path}`, { replace: true }); }; useEffect(() => { window.scrollTo(0, 0); document.title = 'Rules - 5chan'; }, []); return (

Rules

5chan does not have global rules or moderators. It is a serverless, adminless, static tool for browsing and posting to decentralized imageboards.{' '} Each board sets its own rules independently, determined by the board owner and board admins, and enforced by the board moderators.

Please read and respect the rules of whatever board you decide to post to.
{selectedAddress && }
); }; export default Rules;