mirror of
https://gitcode.com/GitHub_Trending/ji/jitsi-meet.git
synced 2025-12-30 11:22:31 +00:00
69 lines
1.4 KiB
TypeScript
69 lines
1.4 KiB
TypeScript
import ReducerRegistry from '../base/redux/ReducerRegistry';
|
|
|
|
import {
|
|
ADD_FILE,
|
|
UPDATE_FILE_UPLOAD_PROGRESS,
|
|
_FILE_LIST_RECEIVED,
|
|
_FILE_REMOVED
|
|
} from './actionTypes';
|
|
import { IFileMetadata } from './types';
|
|
|
|
export interface IFileSharingState {
|
|
files: Map<string, IFileMetadata>;
|
|
}
|
|
|
|
const DEFAULT_STATE = {
|
|
files: new Map<string, IFileMetadata>()
|
|
};
|
|
|
|
ReducerRegistry.register<IFileSharingState>('features/file-sharing',
|
|
(state = DEFAULT_STATE, action): IFileSharingState => {
|
|
switch (action.type) {
|
|
case ADD_FILE: {
|
|
const newFiles = new Map(state.files);
|
|
|
|
newFiles.set(action.file.fileId, action.file);
|
|
|
|
return {
|
|
...state,
|
|
files: newFiles
|
|
};
|
|
}
|
|
|
|
case _FILE_REMOVED: {
|
|
const newFiles = new Map(state.files);
|
|
|
|
newFiles.delete(action.fileId);
|
|
|
|
return {
|
|
...state,
|
|
files: newFiles
|
|
};
|
|
}
|
|
|
|
case UPDATE_FILE_UPLOAD_PROGRESS: {
|
|
const newFiles = new Map(state.files);
|
|
const file = newFiles.get(action.fileId);
|
|
|
|
if (file) {
|
|
newFiles.set(action.fileId, { ...file, progress: action.progress });
|
|
}
|
|
|
|
return {
|
|
...state,
|
|
files: newFiles
|
|
};
|
|
}
|
|
|
|
case _FILE_LIST_RECEIVED: {
|
|
return {
|
|
...state,
|
|
files: new Map(Object.entries(action.files))
|
|
};
|
|
}
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
});
|