mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-26 00:50:56 -05:00
Add trusted links to state
This commit is contained in:
parent
0ca99ddceb
commit
4c34787ef3
3 changed files with 44 additions and 0 deletions
|
@ -14,6 +14,7 @@ import { QueuedMessage } from "./reducers/queue";
|
|||
import { SectionToggle } from "./reducers/section_toggle";
|
||||
import { Settings } from "./reducers/settings";
|
||||
import { SyncOptions } from "./reducers/sync";
|
||||
import { TrustedLinks } from "./reducers/trusted_links";
|
||||
import { Unreads } from "./reducers/unreads";
|
||||
|
||||
export type State = {
|
||||
|
@ -29,6 +30,7 @@ export type State = {
|
|||
lastOpened: LastOpened;
|
||||
notifications: Notifications;
|
||||
sectionToggle: SectionToggle;
|
||||
trustedLinks: TrustedLinks;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
@ -59,6 +61,7 @@ store.subscribe(() => {
|
|||
lastOpened,
|
||||
notifications,
|
||||
sectionToggle,
|
||||
trustedLinks,
|
||||
} = store.getState() as State;
|
||||
|
||||
localForage.setItem("state", {
|
||||
|
@ -74,6 +77,7 @@ store.subscribe(() => {
|
|||
lastOpened,
|
||||
notifications,
|
||||
sectionToggle,
|
||||
trustedLinks,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import { sectionToggle, SectionToggleAction } from "./section_toggle";
|
|||
import { config, ConfigAction } from "./server_config";
|
||||
import { settings, SettingsAction } from "./settings";
|
||||
import { sync, SyncAction } from "./sync";
|
||||
import { trustedLinks, TrustedLinksAction } from "./trusted_links";
|
||||
import { unreads, UnreadsAction } from "./unreads";
|
||||
|
||||
export default combineReducers({
|
||||
|
@ -27,6 +28,7 @@ export default combineReducers({
|
|||
lastOpened,
|
||||
notifications,
|
||||
sectionToggle,
|
||||
trustedLinks,
|
||||
});
|
||||
|
||||
export type Action =
|
||||
|
@ -42,4 +44,5 @@ export type Action =
|
|||
| LastOpenedAction
|
||||
| NotificationsAction
|
||||
| SectionToggleAction
|
||||
| TrustedLinksAction
|
||||
| { type: "__INIT"; state: State };
|
||||
|
|
37
src/redux/reducers/trusted_links.ts
Normal file
37
src/redux/reducers/trusted_links.ts
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue