Migrate actions,reducers and action types to TS #15
This commit is contained in:
13
app/reducers/imageGallery/IImageGalleryAction.ts
Normal file
13
app/reducers/imageGallery/IImageGalleryAction.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import {ImageGalleryActionType} from 'constants/imageGalleryActionType'
|
||||
|
||||
/**
|
||||
* ImageGallery action interface
|
||||
*
|
||||
* @export
|
||||
* @interface IImageGalleryAction
|
||||
*/
|
||||
export interface IImageGalleryAction {
|
||||
payload: any,
|
||||
type: ImageGalleryActionType
|
||||
|
||||
}
|
||||
67
app/reducers/imageGallery/ImageGalleryState.ts
Normal file
67
app/reducers/imageGallery/ImageGalleryState.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { Image } from "domain/imageGallery";
|
||||
|
||||
/**
|
||||
* ImageGallery state
|
||||
*
|
||||
* @export
|
||||
* @class ImageGalleryState
|
||||
*/
|
||||
export class ImageGalleryState {
|
||||
|
||||
/**
|
||||
* Image gallery is open {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof ImageGalleryState
|
||||
*/
|
||||
status: Boolean = false;
|
||||
|
||||
/**
|
||||
* The list of image
|
||||
*
|
||||
* @type {(Image[] | null)}
|
||||
* @memberof ImageGalleryState
|
||||
*/
|
||||
images: Image[] = [];
|
||||
|
||||
/**
|
||||
* Selected image name
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof ImageGalleryState
|
||||
*/
|
||||
selectImage: string = '';
|
||||
|
||||
/**
|
||||
* Selected image address
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof ImageGalleryState
|
||||
*/
|
||||
selectURL: string = '';
|
||||
|
||||
/**
|
||||
* If image gallery is loaded {true} or not false
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof ImageGalleryState
|
||||
*/
|
||||
loaded: Boolean = false;
|
||||
|
||||
/**
|
||||
* Images address list
|
||||
*
|
||||
* @type {*}
|
||||
* @memberof ImageGalleryState
|
||||
*/
|
||||
imageURLList: any = {};
|
||||
|
||||
/**
|
||||
* Store image requested
|
||||
*
|
||||
* @type {*}
|
||||
* @memberof ImageGalleryState
|
||||
*/
|
||||
imageRequests: any = {};
|
||||
|
||||
}
|
||||
71
app/reducers/imageGallery/imageGalleryReducer.ts
Normal file
71
app/reducers/imageGallery/imageGalleryReducer.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
// - Import react components
|
||||
import _ from 'lodash'
|
||||
|
||||
// - Import domain
|
||||
import { User } from "domain/users";
|
||||
import { Image } from "domain/imageGallery";
|
||||
|
||||
// - Import image gallery action types
|
||||
import {ImageGalleryActionType} from 'constants/imageGalleryActionType'
|
||||
|
||||
|
||||
import { IImageGalleryAction } from "./IImageGalleryAction";
|
||||
import { ImageGalleryState } from "./ImageGalleryState";
|
||||
|
||||
|
||||
/**
|
||||
* Image gallery reducer
|
||||
*/
|
||||
export var imageGalleryReducer = (state: ImageGalleryState = new ImageGalleryState(), action: IImageGalleryAction) => {
|
||||
const { payload } = action
|
||||
|
||||
switch (action.type) {
|
||||
/* ----------------- CRUD ----------------- */
|
||||
case ImageGalleryActionType.ADD_IMAGE_GALLERY:
|
||||
return {
|
||||
...state,
|
||||
images: [...state.images!, payload.image]
|
||||
}
|
||||
case ImageGalleryActionType.ADD_IMAGE_LIST_GALLERY:
|
||||
return {
|
||||
...state,
|
||||
images: [...payload],
|
||||
loaded: true
|
||||
}
|
||||
|
||||
case ImageGalleryActionType.DELETE_IMAGE:
|
||||
return {
|
||||
...state,
|
||||
images: [
|
||||
...state.images!.filter((item: Image) => {
|
||||
return item.id !== payload.id
|
||||
})
|
||||
]
|
||||
}
|
||||
case ImageGalleryActionType.SET_IMAGE_URL:
|
||||
return {
|
||||
...state,
|
||||
imageURLList: {
|
||||
...state.imageURLList,
|
||||
[payload.name]: payload.url
|
||||
}
|
||||
}
|
||||
|
||||
case ImageGalleryActionType.SEND_IMAGE_REQUEST:
|
||||
return {
|
||||
...state,
|
||||
imageRequests: [
|
||||
...state.imageRequests,
|
||||
payload
|
||||
]
|
||||
}
|
||||
|
||||
case ImageGalleryActionType.CLEAT_ALL_DATA_IMAGE_GALLERY:
|
||||
return new ImageGalleryState()
|
||||
|
||||
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
3
app/reducers/imageGallery/index.ts
Normal file
3
app/reducers/imageGallery/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { imageGalleryReducer } from "./imageGalleryReducer";
|
||||
|
||||
export {imageGalleryReducer};
|
||||
Reference in New Issue
Block a user