import { Api, CalendarItem, Classmate, EtjanstChild, MenuItem, NewsItem, Notification, ScheduleItem, Skola24Child, TimetableEntry, User, } from '@skolplattformen/api-skolplattformen' import { Action, Reducer } from 'redux' export interface Reporter { log: (message: string) => void error: (error: Error, label?: string) => void } export interface IApiContext { api: Api storage: AsyncStorage isLoggedIn: boolean isFake: boolean reporter: Reporter } export type EntityStatus = 'pending' | 'loading' | 'loaded' | 'error' export interface EntityState { data: T status: EntityStatus error?: Error } export interface ApiCall { (): Promise } export interface ExtraActionProps { apiCall: ApiCall retries: number key: string defaultValue: T getFromCache?: () => Promise saveToCache?: (value: string) => Promise } export type EntityActionType = | 'GET_FROM_API' | 'RESULT_FROM_API' | 'API_ERROR' | 'GET_FROM_CACHE' | 'RESULT_FROM_CACHE' | 'STORE_IN_CACHE' | 'CLEAR' export type EntityName = | 'USER' | 'ETJANST_CHILDREN' | 'SKOLA24_CHILDREN' | 'CHILDREN' | 'CALENDAR' | 'CLASSMATES' | 'MENU' | 'NEWS' | 'NEWS_DETAILS' | 'NOTIFICATIONS' | 'SCHEDULE' | 'TIMETABLE' | 'ALL' export interface EntityAction extends Action { entity: EntityName data?: T error?: Error extra?: ExtraActionProps } export interface EntityMap { [key: string]: EntityState } export type EntityReducer = Reducer, EntityAction> export interface EntityStoreRootState { etjanstChildren: EntityMap skola24Children: EntityMap user: EntityMap calendar: EntityMap classmates: EntityMap menu: EntityMap news: EntityMap newsDetails: EntityMap notifications: EntityMap schedule: EntityMap timetable: EntityMap } export interface EntityHookResult extends EntityState { reload: () => void } export interface AsyncStorage { getItem(key: string): Promise setItem(key: string, value: string): Promise }