2018-09-10 14:49:04 -05:00
|
|
|
import { FolderState } from 'app/types';
|
|
|
|
import { Action, ActionTypes } from './actions';
|
|
|
|
|
2018-09-11 03:36:55 -05:00
|
|
|
export const inititalState: FolderState = {
|
2018-09-11 12:00:37 -05:00
|
|
|
id: 0,
|
2018-09-11 03:36:55 -05:00
|
|
|
uid: 'loading',
|
|
|
|
title: 'loading',
|
2018-09-11 08:07:03 -05:00
|
|
|
url: '',
|
2018-09-11 03:36:55 -05:00
|
|
|
canSave: false,
|
|
|
|
hasChanged: false,
|
2018-09-11 08:07:03 -05:00
|
|
|
version: 0,
|
2018-09-11 03:36:55 -05:00
|
|
|
};
|
2018-09-10 14:49:04 -05:00
|
|
|
|
|
|
|
export const folderReducer = (state = inititalState, action: Action): FolderState => {
|
|
|
|
switch (action.type) {
|
|
|
|
case ActionTypes.LoadFolder:
|
|
|
|
return {
|
|
|
|
...action.payload,
|
|
|
|
hasChanged: false,
|
|
|
|
};
|
2018-09-11 10:36:23 -05:00
|
|
|
case ActionTypes.SetFolderTitle:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
title: action.payload,
|
2018-09-11 12:00:37 -05:00
|
|
|
hasChanged: action.payload.trim().length > 0,
|
2018-09-11 10:36:23 -05:00
|
|
|
};
|
2018-09-10 14:49:04 -05:00
|
|
|
}
|
|
|
|
return state;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
folder: folderReducer,
|
|
|
|
};
|