@@ -129,7 +132,7 @@ const DirectoryNav = ({ groups }: { groups: CategoryGroup[] }) => (
const code = getDirectoryCode(community);
return (
- {getBoardName(community.title) || getDirectoryDisplayTitle(community)}
+ {getBoardName(community.title) || getDirectoryDisplayTitle(community)}
);
})}
@@ -233,11 +236,12 @@ const LoadBoardRules = ({ onLoad, onClear, isLoaded }: { onLoad: (address: strin
};
const Rules = () => {
- const { boardIdentifier } = useParams();
+ const { hash } = useLocation();
const directories = useDirectories();
const directoryDefaults = useDirectoryDefaults();
const [loadedAddress, setLoadedAddress] = useState('');
const scrolledForRef = useRef
(null);
+ const hashCode = getRulesHashCode(hash);
// Order directories alphabetically by directory code (e.g. /3/, /a/, /aco/...), like 4chan, not by title.
const directoriesWithCode = directories.filter((community) => getDirectoryCode(community)).toSorted((a, b) => getDirectoryCode(a).localeCompare(getDirectoryCode(b)));
@@ -253,24 +257,23 @@ const Rules = () => {
useEffect(() => {
setLoadedAddress('');
- if (!boardIdentifier) {
- scrolledForRef.current = null;
+ scrolledForRef.current = null;
+ if (!hashCode) {
window.scrollTo(0, 0);
}
- }, [boardIdentifier]);
+ }, [hashCode]);
- // Deep-link: /rules/:code insta-scrolls to that directory's rules once the matching section is rendered.
+ // Deep-link: /rules#code insta-scrolls to a known directory's rules once the matching section is rendered.
useEffect(() => {
- if (!boardIdentifier || scrolledForRef.current === boardIdentifier) {
+ if (!hashCode || scrolledForRef.current === hashCode || !isDirectoryRoute(hashCode, directories)) {
return;
}
- const code = resolveDirectoryCode(boardIdentifier, directories);
- const element = code ? document.getElementById(code) : null;
+ const element = document.getElementById(hashCode);
if (element) {
element.scrollIntoView();
- scrolledForRef.current = boardIdentifier;
+ scrolledForRef.current = hashCode;
}
- }, [boardIdentifier, directories]);
+ }, [hashCode, directories]);
return (