From e47727c074bf5a60024b5c04f64e8bd33218fced Mon Sep 17 00:00:00 2001 From: plebeius Date: Sun, 15 Feb 2026 14:32:14 +0800 Subject: [PATCH] fix(home): derive board link state from directory availability Replaced one-off /biz/ and /pol/ checks with a single board-name-to-address resolver built from useDirectories() data. The homepage boards list now consistently colors and links any available directory board without manual hardcoding. --- src/views/home/boards-list/boards-list.tsx | 521 +++++---------------- 1 file changed, 110 insertions(+), 411 deletions(-) diff --git a/src/views/home/boards-list/boards-list.tsx b/src/views/home/boards-list/boards-list.tsx index ef9ea82c..e9fcd9ac 100644 --- a/src/views/home/boards-list/boards-list.tsx +++ b/src/views/home/boards-list/boards-list.tsx @@ -8,10 +8,9 @@ import useBoardsFilterStore from '../../../stores/use-boards-filter-store'; import BoardsFilterModal from './boards-filter-modal'; import styles from '../home.module.css'; -// Helper function to find board address by matching title pattern -const findBoardAddress = (multisub: DirectoryCommunity[], titlePattern: string): string | null => { - const entry = multisub.find((ms) => ms.title === titlePattern); - return entry?.address || null; +const getBoardNameFromDirectoryTitle = (title: string): string => { + const match = title.match(/^\/[^/]+\/\s*-\s*(.+)$/); + return match?.[1]?.trim() || title.trim(); }; const NSFWBadge = () => { @@ -55,9 +54,37 @@ const BoardsList = ({ multisub }: { multisub: DirectoryCommunity[] }) => { openDirectoryModal(); }; - // Find active boards - const bizAddress = findBoardAddress(multisub, '/biz/ - Business & Finance'); - const polAddress = findBoardAddress(multisub, '/pol/ - Politically Incorrect'); + const boardAddressesByName = multisub.reduce>((acc, community) => { + if (!community.title) return acc; + const boardName = getBoardNameFromDirectoryTitle(community.title); + if (!acc[boardName]) { + acc[boardName] = community.address; + } + return acc; + }, {}); + + const renderBoardLink = (boardName: string) => { + const address = boardAddressesByName[boardName]; + + if (address) { + return ( +
  • + handleLinkClick(e, address)}> + {boardName} + +
  • + ); + } + + return ( +
  • + + {boardName} + +
  • + ); + }; + const errorMessage = error?.message; // Filtering logic: determine which categories to show @@ -93,62 +120,20 @@ const BoardsList = ({ multisub }: { multisub: DirectoryCommunity[] }) => { @@ -160,46 +145,14 @@ const BoardsList = ({ multisub }: { multisub: DirectoryCommunity[] }) => { <>

    Video Games

    )} @@ -211,81 +164,21 @@ const BoardsList = ({ multisub }: { multisub: DirectoryCommunity[] }) => {

    Interests

      -
    • - - Comics & Cartoons - -
    • -
    • - - Technology - -
    • -
    • - - Television & Film - -
    • -
    • - - Weapons - -
    • -
    • - - Auto - -
    • -
    • - - Animals & Nature - -
    • -
    • - - Traditional Games - -
    • -
    • - - Sports - -
    • -
    • - - Extreme Sports - -
    • -
    • - - Professional Wrestling - -
    • -
    • - - Science & Math - -
    • -
    • - - History & Humanities - -
    • -
    • - - International - -
    • -
    • - - Outdoors - -
    • -
    • - - Toys - -
    • + {renderBoardLink('Comics & Cartoons')} + {renderBoardLink('Technology')} + {renderBoardLink('Television & Film')} + {renderBoardLink('Weapons')} + {renderBoardLink('Auto')} + {renderBoardLink('Animals & Nature')} + {renderBoardLink('Traditional Games')} + {renderBoardLink('Sports')} + {renderBoardLink('Extreme Sports')} + {renderBoardLink('Professional Wrestling')} + {renderBoardLink('Science & Math')} + {renderBoardLink('History & Humanities')} + {renderBoardLink('International')} + {renderBoardLink('Outdoors')} + {renderBoardLink('Toys')}
    )} @@ -295,88 +188,26 @@ const BoardsList = ({ multisub }: { multisub: DirectoryCommunity[] }) => {

    Creative

      - {(showAll || showNsfwOnly) && ( -
    • - - Oekaki - -
    • - )} + {(showAll || showNsfwOnly) && renderBoardLink('Oekaki')} {(showAll || showWorksafeOnly) && ( <> -
    • - - Papercraft & Origami - -
    • -
    • - - Photography - -
    • -
    • - - Food & Cooking - -
    • + {renderBoardLink('Papercraft & Origami')} + {renderBoardLink('Photography')} + {renderBoardLink('Food & Cooking')} )} - {(showAll || showNsfwOnly) && ( -
    • - - Artwork/Critique - -
    • - )} - {(showAll || showNsfwOnly) && ( -
    • - - Wallpapers/General - -
    • - )} + {(showAll || showNsfwOnly) && renderBoardLink('Artwork/Critique')} + {(showAll || showNsfwOnly) && renderBoardLink('Wallpapers/General')} {(showAll || showWorksafeOnly) && ( <> -
    • - - Literature - -
    • -
    • - - Music - -
    • -
    • - - Fashion - -
    • -
    • - - 3DCG - -
    • -
    • - - Graphic Design - -
    • -
    • - - Do-It-Yourself - -
    • -
    • - - Worksafe GIF - -
    • -
    • - - Quests - -
    • + {renderBoardLink('Literature')} + {renderBoardLink('Music')} + {renderBoardLink('Fashion')} + {renderBoardLink('3DCG')} + {renderBoardLink('Graphic Design')} + {renderBoardLink('Do-It-Yourself')} + {renderBoardLink('Worksafe GIF')} + {renderBoardLink('Quests')} )}
    @@ -391,64 +222,16 @@ const BoardsList = ({ multisub }: { multisub: DirectoryCommunity[] }) => { <>

    Other

      - {bizAddress ? ( -
    • - handleLinkClick(e, bizAddress)}> - Business & Finance - -
    • - ) : ( -
    • - - Business & Finance - -
    • - )} -
    • - - Travel - -
    • -
    • - - Fitness - -
    • -
    • - - Paranormal - -
    • -
    • - - Advice - -
    • -
    • - - LGBT - -
    • -
    • - - Pony - -
    • -
    • - - Current News - -
    • -
    • - - Worksafe Requests - -
    • -
    • - - Very Important Posts - -
    • + {renderBoardLink('Business & Finance')} + {renderBoardLink('Travel')} + {renderBoardLink('Fitness')} + {renderBoardLink('Paranormal')} + {renderBoardLink('Advice')} + {renderBoardLink('LGBT')} + {renderBoardLink('Pony')} + {renderBoardLink('Current News')} + {renderBoardLink('Worksafe Requests')} + {renderBoardLink('Very Important Posts')}
    )} @@ -459,44 +242,12 @@ const BoardsList = ({ multisub }: { multisub: DirectoryCommunity[] }) => {

    Misc.

      -
    • - - Random - -
    • -
    • - - ROBOT9001 - -
    • - {polAddress ? ( -
    • - handleLinkClick(e, polAddress)}> - Politically Incorrect - -
    • - ) : ( -
    • - - Politically Incorrect - -
    • - )} -
    • - - International/Random - -
    • -
    • - - Cams & Meetups - -
    • -
    • - - Shit 5chan Says - -
    • + {renderBoardLink('Random')} + {renderBoardLink('ROBOT9001')} + {renderBoardLink('Politically Incorrect')} + {renderBoardLink('International/Random')} + {renderBoardLink('Cams & Meetups')} + {renderBoardLink('Shit 5chan Says')}
    )} @@ -509,71 +260,19 @@ const BoardsList = ({ multisub }: { multisub: DirectoryCommunity[] }) => {

    Adult

      -
    • - - Sexy Beautiful Women - -
    • -
    • - - Hardcore - -
    • -
    • - - Handsome Men - -
    • -
    • - - Hentai - -
    • -
    • - - Ecchi - -
    • -
    • - - Yuri - -
    • -
    • - - Hentai/Alternative - -
    • -
    • - - Yaoi - -
    • -
    • - - Torrents - -
    • -
    • - - High Resolution - -
    • -
    • - - Adult GIF - -
    • -
    • - - Adult Cartoons - -
    • -
    • - - Adult Requests - -
    • + {renderBoardLink('Sexy Beautiful Women')} + {renderBoardLink('Hardcore')} + {renderBoardLink('Handsome Men')} + {renderBoardLink('Hentai')} + {renderBoardLink('Ecchi')} + {renderBoardLink('Yuri')} + {renderBoardLink('Hentai/Alternative')} + {renderBoardLink('Yaoi')} + {renderBoardLink('Torrents')} + {renderBoardLink('High Resolution')} + {renderBoardLink('Adult GIF')} + {renderBoardLink('Adult Cartoons')} + {renderBoardLink('Adult Requests')}
    )}