Live video on the AT Protocol
1import { createAppSlice } from "../../hooks/createSlice";
2import { initialState } from "./shared";
3
4export const platformSlice = createAppSlice({
5 name: "platform",
6 initialState,
7 reducers: (create) => ({
8 handleNotification: create.reducer(
9 (
10 state,
11 action: { payload: { [key: string]: string | object } | undefined },
12 ) => {
13 return state;
14 },
15 ),
16 clearNotification: create.reducer((state) => {
17 return {
18 ...state,
19 notificationDestination: null,
20 };
21 }),
22 openLoginLink: create.asyncThunk(
23 async (url: string) => {
24 window.location.href = url;
25 },
26 {
27 pending: (state) => {
28 state.status = "loading";
29 },
30 fulfilled: (state) => {
31 state.status = "idle";
32 },
33 rejected: (state) => {
34 state.status = "failed";
35 },
36 },
37 ),
38
39 initPushNotifications: create.asyncThunk(
40 async () => {
41 // someday we'll do web notifications but for now it's mobile-only
42 },
43 {
44 pending: (state) => {},
45 fulfilled: (state) => {},
46 rejected: (state) => {},
47 },
48 ),
49
50 registerNotificationToken: create.asyncThunk(async () => {}, {
51 pending: (state) => {},
52 fulfilled: (state) => {},
53 rejected: (state) => {},
54 }),
55 }),
56
57 selectors: {
58 selectNotificationToken: (platform) => platform.notificationToken,
59 selectNotificationDestination: (platform) =>
60 platform.notificationDestination,
61 },
62});
63
64export const { openLoginLink, clearNotification } = platformSlice.actions;
65export const { selectNotificationToken, selectNotificationDestination } =
66 platformSlice.selectors;