mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-05 15:00:30 +03:00
Use consistent "bookmark" wording in code and UI
This commit is contained in:
parent
53612f4641
commit
c45cb62e2d
6 changed files with 129 additions and 173 deletions
43
src/app/hooks/useBookmarkedServers.ts
Normal file
43
src/app/hooks/useBookmarkedServers.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { useCallback, useMemo } from 'react';
|
||||
import { AccountDataEvent } from '../../types/matrix/accountData';
|
||||
import { useAccountData } from './useAccountData';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
|
||||
export type InCinnyBookmarkedServersContent = {
|
||||
servers?: string[];
|
||||
};
|
||||
|
||||
export const useBookmarkedServers = (): [
|
||||
string[],
|
||||
(server: string) => Promise<void>,
|
||||
(server: string) => Promise<void>
|
||||
] => {
|
||||
const mx = useMatrixClient();
|
||||
const accountData = useAccountData(AccountDataEvent.CinnyBookmarkedServers);
|
||||
const bookmarkedServers = useMemo(
|
||||
() => accountData?.getContent<InCinnyBookmarkedServersContent>()?.servers ?? [],
|
||||
[accountData]
|
||||
);
|
||||
|
||||
const addServerBookmark = useCallback(
|
||||
async (server: string) => {
|
||||
if (bookmarkedServers.indexOf(server) === -1) {
|
||||
await mx.setAccountData(AccountDataEvent.CinnyBookmarkedServers, {
|
||||
servers: [...bookmarkedServers, server],
|
||||
});
|
||||
}
|
||||
},
|
||||
[mx, bookmarkedServers]
|
||||
);
|
||||
|
||||
const removeServerBookmark = useCallback(
|
||||
async (server: string) => {
|
||||
await mx.setAccountData(AccountDataEvent.CinnyBookmarkedServers, {
|
||||
servers: bookmarkedServers.filter((addedServer) => server !== addedServer),
|
||||
});
|
||||
},
|
||||
[mx, bookmarkedServers]
|
||||
);
|
||||
|
||||
return [bookmarkedServers, addServerBookmark, removeServerBookmark];
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue