mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-06 07:20:29 +03:00
Allow more servers to be added to the list in the explore tab
This commit is contained in:
parent
d8009978e5
commit
25cfdbc6ff
3 changed files with 125 additions and 53 deletions
38
src/app/hooks/useExploreServers.ts
Normal file
38
src/app/hooks/useExploreServers.ts
Normal 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];
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue