location.js 4.83 KB
export const initialState = {
    startLocation: null,
    endLocation: null,
    endTime: '',

    optRoute: null,

    settingLocation: false,
    settingTime: false,
    settingOptRoute: false,
    settingVelocity: false,


    personalVelocity: 60,
    info: '',
};

export const SET_SLOC_REQUEST = 'SET_SLOC_REQUEST';
export const SET_SLOC_SUCCESS = 'SET_SLOC_SUCCESS';
export const SET_SLOC_FAILURE = 'SET_SLOC_FAILURE';
export const SET_ELOC_REQUEST = 'SET_ELOC_REQUEST';
export const SET_ELOC_SUCCESS = 'SET_ELOC_SUCCESS';
export const SET_ELOC_FAILURE = 'SET_ELOC_FAILURE';
export const SET_USER_LOC = 'SET_USER_LOC';

export const SET_TIME_REQUEST = 'SET_TIME_REQUEST';
export const SET_TIME_SUCCESS = 'SET_TIME_SUCCESS';
export const SET_TIME_FAILURE = 'SET_TIME_FAILURE';

export const SET_OPTROUTE_REQUEST = 'SET_OPTROUTE_REQUEST';
export const SET_OPTROUTE_SUCCESS = 'SET_OPTROUTE_SUCCESS';
export const SET_OPTROUTE_FAILURE = 'SET_OPTROUTE_FAILURE';

export const SET_PERVELOCITY_REQUEST = 'SET_PERVELOCITY_REQUEST';
export const SET_PERVELOCITY_SUCCESS = 'SET_PERVELOCITY_SUCCESS';
export const SET_PERVELOCITY_FAILURE = 'SET_PERVELOCITY_FAILURE';


export default (state = initialState, action) => {
    switch (action.type) {

        case SET_SLOC_REQUEST: {
            return {
                ...state,
                settingLocation: true,
            }
        }

        case SET_SLOC_SUCCESS: {
            const {startLocation} = action.data;
            return {
                ...state,
                startLocation,
                isLoggingIn: false,
            };
        }

        case SET_SLOC_FAILURE: {
            const {info} = action.data;
            return {
                ...state,
                settingLocation: false,
                info,
            }
        }


        case SET_ELOC_REQUEST: {
            return {
                ...state,
                settingLocation: true,
            }
        }

        case SET_ELOC_SUCCESS: {
            const {endLocation} = action.data;
            return {
                ...state,
                endLocation,
                isLoggingIn: false,
            };
        }

        case SET_ELOC_FAILURE: {
            const {info} = action.data;
            return {
                ...state,
                settingLocation: false,
                info,
            }
        }

        case SET_USER_LOC: {
            var {userLocation} = action.data;
            userLocation = {
                title: '현위치',
                latitude: userLocation.coords.latitude,
                longitude: userLocation.coords.longitude,
                latitudeDelta: 0.0039,
                longitudeDelta: 0.0039,
                description: 'start point',

            };
            console.log(userLocation.coords);
            return {
                ...state,
                startLocation: userLocation,
                settingLocation: false
            }
        }

        case SET_TIME_REQUEST: {
            return {
                ...state,
                settingTime: true,
            }
        }
        case SET_TIME_SUCCESS: {
            const {date} = action.data;
            console.log('reducer SET_TIME_SUCCESS', date);
            return {
                ...state,
                endTime: date,
                settingTime: false,
            }
        }
        case SET_TIME_FAILURE: {
            const {info} = action.data;
            return {
                ...state,
                settingTime: false,
            }
        }

        case SET_OPTROUTE_REQUEST: {
            return {
                ...state,
                settingOptRoute: true,
            }
        }

        case SET_OPTROUTE_SUCCESS: {
            var {optRoute} = action.data;
            console.log('SET_OPTROUTE_SUCCESST', optRoute);
            return {
                ...state,
                optRoute: optRoute,
                settingOptRoute: false,
            }
        }

        case SET_OPTROUTE_FAILURE: {
            const {info} = action.data;
            return {
                ...state,
                settingOptRoute: false,
            }
        }


        case SET_PERVELOCITY_REQUEST: {
            return {
                ...state,
                settingVelocity: true,
            }
        }

        case SET_PERVELOCITY_SUCCESS: {
            var {personalVelocity} = action.data;
            console.log('SET_PERVELOCITY_SUCCESS', personalVelocity);
            return {
                ...state,
                personalVelocity,
                settingVelocity: true,
            }
        }

        case SET_PERVELOCITY_FAILURE: {
            const {info} = action.data;
            return {
                ...state,
                settingVelocity: false,
            }
        }

        default: {
            return {
                ...state,
            };
        }
    }
};