Allow more servers to be added to the list in the explore tab

This commit is contained in:
Ginger 2025-03-10 11:21:14 -04:00
parent d8009978e5
commit 25cfdbc6ff
3 changed files with 125 additions and 53 deletions

View file

@ -0,0 +1,38 @@
import { AccountDataEvent } from '../../types/matrix/accountData';
import { useAccountData } from './useAccountData';
import { useMatrixClient } from './useMatrixClient';
export type InCinnyExploreServersContent = {
servers?: string[];
};
export type ExploreServerListAction =
| {
type: 'APPEND';
server: string;
}
| {
type: 'DELETE';
server: string;
};
export const useExploreServers = (): [string[], (action: ExploreServerListAction) => void] => {
const mx = useMatrixClient();
const userAddedServers =
useAccountData(AccountDataEvent.CinnyExploreServers)?.getContent<InCinnyExploreServersContent>()
?.servers ?? [];
const setUserAddedServers = (action: ExploreServerListAction) => {
if (action.type === 'APPEND') {
mx.setAccountData(AccountDataEvent.CinnyExploreServers, {
servers: [...userAddedServers, action.server],
});
} else if (action.type === 'DELETE') {
mx.setAccountData(AccountDataEvent.CinnyExploreServers, {
servers: userAddedServers.filter((server) => server !== action.server),
});
}
};
return [userAddedServers, setUserAddedServers];
};