import { createSlice , PayloadAction } from '@reduxjs/toolkit' ; import { RootState } from '../..' ; interface FileViewerState { isLoading : boolean ; objectUrls : Record < string , string > ; } const initialState = { isLoading : false , objectUrls : { } , } ; export const fileViewerSlice = createSlice ( { name : 'file-viewer' , initialState , reducers : { setIsLoading : ( state , action ) => { state . isLoading = action . payload ; } , setObjectUrl : ( state , action ) => { state . objectUrls [ action . payload . fileId ] = action . payload . url ; } , revokeObjectUrl : ( state , action ) => { const objectUrl = state . objectUrls [ action . payload ] ; if ( objectUrl ) { URL . revokeObjectURL ( objectUrl ) ; delete state . objectUrls [ action . payload ] ; } } , resetState : ( state ) => { Object . assign ( state , initialState ) ; } , } , } ) ; export const fileViewerSelectors = { objectUrlByFileId ( state ) { return ( fileId ) => state . fileViewer . objectUrls [ fileId ] ; } , } ; export const fileViewerActions = fileViewerSlice . actions ; export default fileViewerSlice . reducer ;