Live video on the AT Protocol
79
fork

Configure Feed

Select the types of activity you want to include in your feed.

at natb/loading-overlay 57 lines 1.3 kB view raw
1import { createAppSlice } from "../../hooks/createSlice"; 2import Storage from "../../storage"; 3export const STORED_KEY_KEY = "storedKey"; 4export const DID_KEY = "did"; 5 6export interface StreamKey { 7 privateKey: string; 8 did: string; 9 address: string; 10} 11 12export interface BaseState { 13 hydrated: boolean; 14} 15 16const initialState: BaseState = { 17 hydrated: false, 18}; 19 20export const baseSlice = createAppSlice({ 21 name: "base", 22 initialState, 23 reducers: (create) => ({ 24 hydrate: create.asyncThunk( 25 async () => { 26 let storedKey: StreamKey | null = null; 27 // Async operation would go here 28 try { 29 const storedKeyStr = await Storage.getItem(STORED_KEY_KEY); 30 if (storedKeyStr) { 31 storedKey = JSON.parse(storedKeyStr); 32 } 33 } catch (e) { 34 // we don't have one i guess 35 } 36 return { storedKey }; 37 }, 38 { 39 pending: (state) => { 40 state.hydrated = false; 41 }, 42 fulfilled: (state) => { 43 state.hydrated = true; 44 }, 45 rejected: (state) => { 46 state.hydrated = false; 47 }, 48 }, 49 ), 50 }), 51 selectors: { 52 selectHydrated: (state) => state.hydrated, 53 }, 54}); 55 56export const { hydrate } = baseSlice.actions; 57export const { selectHydrated } = baseSlice.selectors;