[Glitch] Adds featured tab to web

Port 64d94f9e57 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Echo
2025-04-10 17:40:30 +02:00
committed by Claire
parent 42ae13058d
commit eb07c0c439
16 changed files with 380 additions and 245 deletions

View File

@@ -0,0 +1,37 @@
import { useEffect } from 'react';
import { useParams } from 'react-router';
import { fetchAccount, lookupAccount } from 'flavours/glitch/actions/accounts';
import { normalizeForLookup } from 'flavours/glitch/reducers/accounts_map';
import { useAppDispatch, useAppSelector } from 'flavours/glitch/store';
interface Params {
acct?: string;
id?: string;
}
export function useAccountId() {
const { acct, id } = useParams<Params>();
const accountId = useAppSelector(
(state) =>
id ??
(state.accounts_map.get(normalizeForLookup(acct)) as string | undefined),
);
const account = useAppSelector((state) =>
accountId ? state.accounts.get(accountId) : undefined,
);
const isAccount = !!account;
const dispatch = useAppDispatch();
useEffect(() => {
if (!accountId) {
dispatch(lookupAccount(acct));
} else if (!isAccount) {
dispatch(fetchAccount(accountId));
}
}, [dispatch, accountId, acct, isAccount]);
return accountId;
}