Add trusted links to state

This commit is contained in:
Snazzah
2021-08-30 13:07:35 +00:00
committed by GitHub
parent 13e0fc86b0
commit 88a73b007f
3 changed files with 44 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
export interface TrustedLinks {
domains?: string[];
}
export type TrustedLinksAction =
| { type: undefined }
| {
type: "TRUSTED_LINKS_ADD_DOMAIN";
domain: string;
}
| {
type: "TRUSTED_LINKS_REMOVE_DOMAIN";
domain: string;
};
export function trustedLinks(
state = {} as TrustedLinks,
action: TrustedLinksAction,
): TrustedLinks {
switch (action.type) {
case "TRUSTED_LINKS_ADD_DOMAIN":
return {
...state,
domains: [
...(state.domains ?? []).filter((v) => v !== action.domain),
action.domain,
],
};
case "TRUSTED_LINKS_REMOVE_DOMAIN":
return {
...state,
domains: state.domains?.filter((v) => v !== action.domain),
};
default:
return state;
}
}