diff --git a/package-lock.json b/package-lock.json index 60f0e5f..1276737 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,8 +17,7 @@ "react-dom": "^18.3.1", "react-redux": "^9.1.2", "react-transition-group": "^4.4.5", - "redux": "^5.0.1", - "reselect": "^5.1.1" + "redux": "^5.0.1" }, "devDependencies": { "@chromatic-com/storybook": "^1.6.1", diff --git a/package.json b/package.json index c89c8cd..375b843 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,6 @@ "react-dom": "^18.3.1", "react-redux": "^9.1.2", "react-transition-group": "^4.4.5", - "redux": "^5.0.1", - "reselect": "^5.1.1" + "redux": "^5.0.1" } } diff --git a/src/__actions/__tests__/dock.test.js b/src/__actions/__tests__/dock.test.js deleted file mode 100644 index d2cdc16..0000000 --- a/src/__actions/__tests__/dock.test.js +++ /dev/null @@ -1,28 +0,0 @@ -import { - SET_DOCK_OPTIONS, - setDockOptions -} from '../dock'; - -describe('actions/dock', () => { - describe('setDockOptions', () => { - it(`should return action with "${SET_DOCK_OPTIONS}" type`, () => { - expect(setDockOptions()).toHaveProperty('type', SET_DOCK_OPTIONS); - }); - - it('should return action with prop "options" and value given object', () => { - const action = setDockOptions({stuff: true}); - expect(action).toHaveProperty('options'); - expect(action.options).toEqual({stuff: true}); - }); - - it('should not add nothing extra', () => { - const expected = { - type: SET_DOCK_OPTIONS, - options: { - smth: 10 - } - }; - expect(setDockOptions({smth: 10})).toEqual(expected); - }); - }); -}); diff --git a/src/__actions/__tests__/intro.test.js b/src/__actions/__tests__/intro.test.js deleted file mode 100644 index 2b8143a..0000000 --- a/src/__actions/__tests__/intro.test.js +++ /dev/null @@ -1,25 +0,0 @@ -import { - SET_INTRO, - setIntro -} from '../intro'; - -describe('actions/intro', () => { - describe('setIntro', () => { - it(`should return action with "${SET_INTRO}" type`, () => { - expect(setIntro()).toHaveProperty('type', SET_INTRO); - }); - - it('should return action with given value', () => { - expect(setIntro(true)).toHaveProperty('value', true); - expect(setIntro(false)).toHaveProperty('value', false); - }); - - it('should not add nothing extra', () => { - const expected = { - type: SET_INTRO, - value: true - }; - expect(setIntro(true)).toEqual(expected); - }); - }); -}); diff --git a/src/__actions/__tests__/settings.test.js b/src/__actions/__tests__/settings.test.js deleted file mode 100644 index 86258ed..0000000 --- a/src/__actions/__tests__/settings.test.js +++ /dev/null @@ -1,28 +0,0 @@ -import { - SET_OPTIONS, - setOptions -} from '../settings'; - -describe('actions/settings', () => { - describe('setOptions', () => { - it(`should return action with "${SET_OPTIONS}" type`, () => { - expect(setOptions()).toHaveProperty('type', SET_OPTIONS); - }); - - it('should return action with prop "options" and value given object', () => { - const action = (setOptions({stuff: true})); - expect(action).toHaveProperty('options'); - expect(action.options).toEqual({stuff: true}); - }); - - it('should not add nothing extra', () => { - const expected = { - type: SET_OPTIONS, - options: { - smth: 10 - } - }; - expect(setOptions({smth: 10})).toEqual(expected); - }); - }); -}); diff --git a/src/__actions/__tests__/weather.test.js b/src/__actions/__tests__/weather.test.js deleted file mode 100644 index 94c0676..0000000 --- a/src/__actions/__tests__/weather.test.js +++ /dev/null @@ -1,129 +0,0 @@ -import { - WEATHER_LOAD_REQUEST, - WEATHER_LOAD_SUCCESS, - WEATHER_LOAD_FAILURE, - - loadWeatherRequest, - loadWeatherSuccess, - loadWeatherFailure, - loadWeather -} from '../weather'; - -jest.mock('../../services/weather'); -import weather from '../../services/weather'; - -describe('actions/weather', () => { - describe('loadWeatherRequest', () => { - it(`it should return action with "${WEATHER_LOAD_REQUEST}" type`, () => { - expect(loadWeatherRequest()).toHaveProperty('type', WEATHER_LOAD_REQUEST); - }); - - it('should return action with location specified', () => { - expect(loadWeatherRequest('some_location')).toHaveProperty('location', 'some_location'); - }); - - it('should not add nothing extra', () => { - const expected = { - type: WEATHER_LOAD_REQUEST, - location: 'some_location' - }; - expect(loadWeatherRequest('some_location')).toEqual(expected); - }); - }); - - describe('loadWeatherSuccess', () => { - it(`it should return action with "${WEATHER_LOAD_SUCCESS}" type`, () => { - expect(loadWeatherSuccess()).toHaveProperty('type', WEATHER_LOAD_SUCCESS); - }); - - it('should return action with location specified', () => { - expect(loadWeatherSuccess({}, 'some_location')).toHaveProperty('location', 'some_location'); - }); - - it('should return action with data specified', () => { - const action = loadWeatherSuccess({some: 'data'}); - expect(action).toHaveProperty('data'); - expect(action.data).toEqual({some: 'data'}); - }); - - it('should not add nothing extra', () => { - const expected = { - type: WEATHER_LOAD_SUCCESS, - location: 'some_location', - data: { - some: 'data' - } - }; - expect(loadWeatherSuccess({some: 'data'}, 'some_location')).toEqual(expected); - }); - }); - - describe('loadWeatherFailure', () => { - it(`it should return action with "${WEATHER_LOAD_FAILURE}" type`, () => { - expect(loadWeatherFailure()).toHaveProperty('type', WEATHER_LOAD_FAILURE); - }); - - it('should return action with location specified', () => { - expect(loadWeatherFailure({}, 'some_location')).toHaveProperty('location', 'some_location'); - }); - - it('should return action with error specified', () => { - const error = new Error('stuff'); - const action = loadWeatherFailure(error); - expect(action).toHaveProperty('error', error); - }); - - it('should not add nothing extra', () => { - const error = new Error('stuff'); - const expected = { - type: WEATHER_LOAD_FAILURE, - location: 'some_location', - error - }; - expect(loadWeatherFailure(error, 'some_location')).toEqual(expected); - }); - }); - - describe('loadWeather', () => { - const stubWeather = func => { - weather.fetch = jest.fn().mockImplementation(func); - // sinon.stub(weather, 'fetch').callsFake(func); - }; - const location = 'some_location'; - const data = { - some: 'data' - }; - const error = new Error('some network or position error + metadata'); - - let dispatchSpy; - beforeEach(() => { - dispatchSpy = jest.fn(); - }); - - afterEach(() => { - dispatchSpy = null; - }); - - it(`should dispatch "${WEATHER_LOAD_REQUEST}" action sync`, () => { - stubWeather(() => Promise.resolve()); - - loadWeather(location)(dispatchSpy); - // sync - expect(dispatchSpy).toHaveBeenCalledWith(loadWeatherRequest(location)); - }); - - it(`should dispatch "${WEATHER_LOAD_SUCCESS}" action with loaded data async`, () => { - stubWeather(() => Promise.resolve(data)); - return loadWeather(location)(dispatchSpy).then(() => { - expect(dispatchSpy).toHaveBeenCalledWith(loadWeatherSuccess(data, location)); - }); - }); - - it(`should dispatch "${WEATHER_LOAD_FAILURE}" action with error async`, () => { - stubWeather(() => Promise.reject(error)); - return loadWeather(location)(dispatchSpy).then(() => { - expect(dispatchSpy).toHaveBeenCalledWith(loadWeatherFailure(error, location)); - }); - }); - }); -}); diff --git a/src/__actions/dock.ts b/src/__actions/dock.ts deleted file mode 100644 index 1dcf548..0000000 --- a/src/__actions/dock.ts +++ /dev/null @@ -1,6 +0,0 @@ -export const SET_DOCK_OPTIONS = 'SET_DOCK_OPTIONS'; - -export const setDockOptions = options => ({ - type: SET_DOCK_OPTIONS, - options, -}); diff --git a/src/__actions/intro.ts b/src/__actions/intro.ts deleted file mode 100644 index 02028ec..0000000 --- a/src/__actions/intro.ts +++ /dev/null @@ -1,6 +0,0 @@ -export const SET_INTRO = 'SET_INTRO'; - -export const setIntro = value => ({ - type: SET_INTRO, - value -}); diff --git a/src/__actions/settings.ts b/src/__actions/settings.ts deleted file mode 100644 index b97f86b..0000000 --- a/src/__actions/settings.ts +++ /dev/null @@ -1,6 +0,0 @@ -export const SET_OPTIONS = 'SET_OPTIONS'; - -export const setOptions = options => ({ - type: SET_OPTIONS, - options -}); diff --git a/src/__actions/weather.ts b/src/__actions/weather.ts deleted file mode 100644 index 41cb113..0000000 --- a/src/__actions/weather.ts +++ /dev/null @@ -1,32 +0,0 @@ -import weather from '../services/weather'; - -export const WEATHER_LOAD_REQUEST = 'WEATHER_LOAD_REQUEST'; -export const WEATHER_LOAD_SUCCESS = 'WEATHER_LOAD_SUCCESS'; -export const WEATHER_LOAD_FAILURE = 'WEATHER_LOAD_FAILURE'; - - -export const loadWeatherRequest = location => ({ - type: WEATHER_LOAD_REQUEST, - location -}); - -export const loadWeatherSuccess = (data, location) => ({ - type: WEATHER_LOAD_SUCCESS, - data, - location -}); - -export const loadWeatherFailure = (error, location) => ({ - type: WEATHER_LOAD_FAILURE, - error, - location -}); - -export const loadWeather = location => dispatch => { - dispatch(loadWeatherRequest(location)); - - return weather.fetch(location).then( - data => dispatch(loadWeatherSuccess(data, location)), - err => dispatch(loadWeatherFailure(err, location)) - ); -}; diff --git a/src/__containers/__docTitleUpdater/DocTitleUpdater.ts b/src/__containers/__docTitleUpdater/DocTitleUpdater.ts deleted file mode 100644 index 3f5c9ed..0000000 --- a/src/__containers/__docTitleUpdater/DocTitleUpdater.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { connect } from 'react-redux'; - -import { selectSettings } from '../../__selectors'; - -import { DocTitleUpdater } from '../../components/DocTitleUpdater/DocTitleUpdater'; - -const mapStateToProps = (state) => { - const settings = selectSettings(state); - - return { - use24: settings.use24format, - displaySeconds: settings.displaySeconds, - }; -}; - -const DocTitleUpdaterContainer = connect(mapStateToProps)(DocTitleUpdater); - -export default DocTitleUpdaterContainer; diff --git a/src/__containers/intro/Intro.ts b/src/__containers/intro/Intro.ts deleted file mode 100644 index 4a10503..0000000 --- a/src/__containers/intro/Intro.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { connect } from 'react-redux'; - -import { selectSettings } from '../../__selectors'; - -import { setIntro } from '../../__actions/intro'; - -import Intro from '../../components/intro/Intro'; - -const mapStateToProps = (state) => ({ - settings: selectSettings(state), -}); - -const mapDispatchToProps = (dispatch) => ({ - setIntro(val) { - return dispatch(setIntro(val)); - }, -}); - -const IntroContainer = connect(mapStateToProps, mapDispatchToProps)(Intro); - -export default IntroContainer; diff --git a/src/__containers/settings/Settings.ts b/src/__containers/settings/Settings.ts deleted file mode 100644 index 18c531d..0000000 --- a/src/__containers/settings/Settings.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { connect } from 'react-redux'; - -import { selectSettings, selectDock } from '../../__selectors'; - -import { setOptions } from '../../__actions/settings'; -import { setDockOptions } from '../../__actions/dock'; - -import Settings from '../../components/settings_old/Settings'; - -const mapStateToProps = (state) => { - const settings = selectSettings(state); - const dock = selectDock(state); - - return { - settings, - dock, - }; -}; - -const mapDispatchToProps = (dispatch) => ({ - setOptions(options) { - return dispatch(setOptions(options)); - }, - - setDockOptions(options) { - return dispatch(setDockOptions(options)); - }, -}); - -const SettingsContainer = connect(mapStateToProps, mapDispatchToProps)(Settings); - -export default SettingsContainer; diff --git a/src/__containers/weather/Current.ts b/src/__containers/weather/Current.ts deleted file mode 100644 index b6e0eff..0000000 --- a/src/__containers/weather/Current.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { connect } from 'react-redux'; - -import { selectLocation, selectCurrentWeather, selectSettings } from '../../__selectors'; - -import CurrentWeather from '../../components/weather/Current'; - -const mapStateToProps = (state) => ({ - data: selectCurrentWeather(state), - location: selectLocation(state), - temperatureUnits: selectSettings(state).temperatureUnits, -}); - -export default connect(mapStateToProps)(CurrentWeather); diff --git a/src/__containers/weather/Forecast.ts b/src/__containers/weather/Forecast.ts deleted file mode 100644 index b51f640..0000000 --- a/src/__containers/weather/Forecast.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { connect } from 'react-redux'; - -import { selectWeatherForecast } from '../../__selectors'; - -import WeatherForecast from '../../components/weather/Forecast'; - -const mapStateToProps = (state) => ({ - data: selectWeatherForecast(state), -}); - -export default connect(mapStateToProps)(WeatherForecast); diff --git a/src/__reducers/__tests__/dock.test.js b/src/__reducers/__tests__/dock.test.js deleted file mode 100644 index 1358e1f..0000000 --- a/src/__reducers/__tests__/dock.test.js +++ /dev/null @@ -1,42 +0,0 @@ -import dockReducer from '../dock'; -import { - SET_DOCK_OPTIONS, - setDockOptions -} from '../../actions/dock'; - -describe('reducers/dock', () => { - const initialState = {}; - - it('should return initial state by default', () => { - /* eslint no-undefined: 0 */ - expect(dockReducer(undefined, {})).toEqual(initialState); - }); - - it(`should handle "${SET_DOCK_OPTIONS}" action type`, () => { - let state = {}; - const action1 = setDockOptions({some: 'data'}); - const action2 = setDockOptions({some: 'data2', another: 'data'}); - state = dockReducer(state, action1); - expect(state).toEqual({ - some: 'data' - }); - state = dockReducer(state, action2); - expect(state).toEqual({ - some: 'data2', - another: 'data' - }); - }); - - it('should not handle other action types', () => { - const state = { - some: 'data' - }; - const nextState = dockReducer(state, { - type: 'SOME_OTHER_ACTION_TYPE', - options: { - whatever: true - } - }); - expect(nextState).toEqual(state); - }); -}); diff --git a/src/__reducers/__tests__/intro.test.js b/src/__reducers/__tests__/intro.test.js deleted file mode 100644 index 6e961d1..0000000 --- a/src/__reducers/__tests__/intro.test.js +++ /dev/null @@ -1,31 +0,0 @@ -import introReducer from '../intro'; -import { - SET_INTRO, - setIntro -} from '../../actions/intro'; - -describe('reducers/intro', () => { - const initialState = false; - - it('should return initial state by default', () => { - /* eslint no-undefined: 0 */ - expect(introReducer(undefined, {})).toEqual(initialState); - }); - - it(`should handle "${SET_INTRO}" action type`, () => { - let state = false; - const action1 = setIntro(true); - const action2 = setIntro(false); - expect(introReducer(state, action1)).toBe(true); - expect(introReducer(state, action2)).toBe(false); - }); - - it('should not handle other action types', () => { - const state = false; - const nextState = introReducer(state, { - type: 'SOME_OTHER_ACTION_TYPE', - value: true - }); - expect(nextState).toEqual(state); - }); -}); diff --git a/src/__reducers/__tests__/settings.test.js b/src/__reducers/__tests__/settings.test.js deleted file mode 100644 index f280663..0000000 --- a/src/__reducers/__tests__/settings.test.js +++ /dev/null @@ -1,41 +0,0 @@ -import {settings as initialState} from '../../config'; -import settingsReducer from '../settings'; -import { - SET_OPTIONS, - setOptions -} from '../../actions/settings'; - -describe('reducers/settings', () => { - it('should return initial state by default', () => { - /* eslint no-undefined: 0 */ - expect(settingsReducer(undefined, {})).toEqual(initialState); - }); - - it(`should handle "${SET_OPTIONS}" action type`, () => { - let state = {}; - const action1 = setOptions({some: 'data'}); - const action2 = setOptions({some: 'data2', another: 'data'}); - state = settingsReducer(state, action1); - expect(state).toEqual({ - some: 'data' - }); - state = settingsReducer(state, action2); - expect(state).toEqual({ - some: 'data2', - another: 'data' - }); - }); - - it('should not handle other action types', () => { - const state = { - some: 'data' - }; - const nextState = settingsReducer(state, { - type: 'SOME_OTHER_ACTION_TYPE', - options: { - whatever: true - } - }); - expect(nextState).toEqual(state); - }); -}); diff --git a/src/__reducers/__tests__/view.test.js b/src/__reducers/__tests__/view.test.js deleted file mode 100644 index 68def9f..0000000 --- a/src/__reducers/__tests__/view.test.js +++ /dev/null @@ -1,72 +0,0 @@ -import viewReducer from '../view'; -import { - OPEN_SETTINGS, - CLOSE_SETTINGS, - TOGGLE_SETTINGS, - openSettings, - closeSettings, - toggleSettings -} from '../../actions/view'; - -describe('reducers/view', () => { - const initialState = { - settingsOpen: false - }; - - it('should return initial state by default', () => { - /* eslint no-undefined: 0 */ - expect(viewReducer(undefined, {})).toEqual(initialState); - }); - - it(`should set "settingsOpen" to true if "${OPEN_SETTINGS}" action dispatched`, () => { - const action = openSettings(); - expect(viewReducer({ - settingsOpen: false - }, action)).toEqual({ - settingsOpen: true - }); - expect(viewReducer({ - settingsOpen: true - }, action)).toEqual({ - settingsOpen: true - }); - }); - - it(`should set "settingsOpen" to false if "${CLOSE_SETTINGS}" action dispatched`, () => { - const action = closeSettings(); - expect(viewReducer({ - settingsOpen: true - }, action)).toEqual({ - settingsOpen: false - }); - expect(viewReducer({ - settingsOpen: false - }, action)).toEqual({ - settingsOpen: false - }); - }); - - it(`should toggle "settingsOpen" true/false if "${TOGGLE_SETTINGS}" action dispatched`, () => { - const action = toggleSettings(); - expect(viewReducer({ - settingsOpen: true - }, action)).toEqual({ - settingsOpen: false - }); - expect(viewReducer({ - settingsOpen: false - }, action)).toEqual({ - settingsOpen: true - }); - }); - - it('should not handle other action types', () => { - const state = { - settingsOpen: false - }; - const nextState = viewReducer(state, { - type: 'SOME_OTHER_ACTION_TYPE' - }); - expect(nextState).toEqual(state); - }); -}); diff --git a/src/__reducers/__tests__/weather.test.js b/src/__reducers/__tests__/weather.test.js deleted file mode 100644 index 7081c2f..0000000 --- a/src/__reducers/__tests__/weather.test.js +++ /dev/null @@ -1,73 +0,0 @@ -import weatherReducer from '../weather'; -import { - WEATHER_LOAD_REQUEST, - WEATHER_LOAD_SUCCESS, - WEATHER_LOAD_FAILURE, - - loadWeatherRequest, - loadWeatherSuccess, - loadWeatherFailure -} from '../../actions/weather'; - -describe('reducers/weather', () => { - const initialState = {}; - - const location = 'some_location'; - it('should return initial state by default', () => { - /* eslint no-undefined: 0 */ - expect(weatherReducer(undefined, {})).toEqual(initialState); - }); - - describe(`${WEATHER_LOAD_REQUEST}`, () => { - it('should set "loading: true" for given location', () => { - let state = {}; - const action = loadWeatherRequest(location); - state = weatherReducer(state, action); - expect(state[location]).toHaveProperty('loading', true); - }); - }); - - describe(`${WEATHER_LOAD_SUCCESS}`, () => { - it('should set "loading: false" for given location', () => { - let state = {}; - const action = loadWeatherSuccess({}, location); - state = weatherReducer(state, action); - expect(state[location]).toHaveProperty('loading', false); - }); - - it('should set "data" to action.data for given location', () => { - let state = {}; - const action = loadWeatherSuccess({some: 'data'}, location); - state = weatherReducer(state, action); - expect(state[location]).toHaveProperty('data'); - expect(state[location].data).toEqual({some: 'data'}); - }); - }); - - describe(`${WEATHER_LOAD_FAILURE}`, () => { - it('should set "loading: false" for given location', () => { - let state = {}; - const action = loadWeatherFailure({}, location); - state = weatherReducer(state, action); - expect(state[location]).toHaveProperty('loading', false); - }); - - it('should set "error" to action.error for given location', () => { - let state = {}; - const error = new Error('some error'); - const action = loadWeatherFailure(error, location); - state = weatherReducer(state, action); - expect(state[location]).toHaveProperty('error', error); - }); - }); - - it('should not handle other action types', () => { - const state = {}; - const nextState = weatherReducer(state, { - type: 'SOME_OTHER_ACTION_TYPE', - data: {some: 'data'}, - error: new Error('some error') - }); - expect(nextState).toEqual(state); - }); -}); diff --git a/src/__reducers/dock.ts b/src/__reducers/dock.ts deleted file mode 100644 index 5e2a248..0000000 --- a/src/__reducers/dock.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { SET_DOCK_OPTIONS } from '../__actions/dock'; - -function settings(state = {}, action) { - switch (action.type) { - case SET_DOCK_OPTIONS: - return Object.assign({}, state, action.options); - - default: - return Object.assign({}, state); - } -} - -export default settings; diff --git a/src/__reducers/index.ts b/src/__reducers/index.ts deleted file mode 100644 index 95564ad..0000000 --- a/src/__reducers/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import intro from './intro'; -import settings from './settings'; -import dock from './dock'; -import weather from './weather'; - -const reducers = { - intro, - settings, - dock, - weather, -}; - -export default reducers; diff --git a/src/__reducers/intro.ts b/src/__reducers/intro.ts deleted file mode 100644 index adced3d..0000000 --- a/src/__reducers/intro.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { SET_INTRO } from '../__actions/intro'; - -const intialState = false; - -function intro(state = intialState, action) { - if (action.type === SET_INTRO) return !!action.value; - return state; -} - -export default intro; diff --git a/src/__reducers/settings.ts b/src/__reducers/settings.ts deleted file mode 100644 index 7a6fbf2..0000000 --- a/src/__reducers/settings.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { settings as defaults } from '../config'; -import { SET_OPTIONS } from '../__actions/settings'; - -function settings(state = defaults, action) { - switch (action.type) { - case SET_OPTIONS: - return Object.assign({}, state, action.options); - - default: - return Object.assign({}, state); - } -} - -export default settings; diff --git a/src/__reducers/weather.ts b/src/__reducers/weather.ts deleted file mode 100644 index 99a1c47..0000000 --- a/src/__reducers/weather.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { - WEATHER_LOAD_REQUEST, - WEATHER_LOAD_SUCCESS, - WEATHER_LOAD_FAILURE, -} from '../__actions/weather'; - -const initialState = {}; - -const initialWeatherState = { - loading: false, - data: null, - error: null, -}; - -function weather(state = initialState, action) { - if ([WEATHER_LOAD_REQUEST, WEATHER_LOAD_SUCCESS, WEATHER_LOAD_FAILURE].includes(action.type)) { - const { location } = action; - return Object.assign({}, state, { - [location]: weatherItem(state[location], action), - }); - } - - return Object.assign({}, state); -} - -function weatherItem(state = initialWeatherState, action) { - switch (action.type) { - case WEATHER_LOAD_REQUEST: - return Object.assign({}, state, { - loading: true, - }); - - case WEATHER_LOAD_SUCCESS: - return Object.assign({}, state, { - loading: false, - data: action.data, - }); - - case WEATHER_LOAD_FAILURE: - return Object.assign({}, state, { - loading: false, - error: action.error, - }); - - default: - return Object.assign({}, state); - } -} - -export default weather; diff --git a/src/__selectors/__tests__/index.test.js b/src/__selectors/__tests__/index.test.js deleted file mode 100644 index 78581c6..0000000 --- a/src/__selectors/__tests__/index.test.js +++ /dev/null @@ -1,199 +0,0 @@ -import { - selectDock, - selectSettings, - selectView, - selectIntro, - - selectWeatherError, - selectWeatherLoading, - selectWeatherData, - - selectWeatherForecast, - selectLocation, - - selectLocationName -} from '../index'; - -describe('selectors', () => { - describe('selectDock', () => { - it('should return .dock portion of the state', () => { - expect(selectDock({dock: 'test'})).toBe('test'); - }); - }); - - describe('selectSettings', () => { - it('should return .settings portion of the state', () => { - expect(selectSettings({settings: 'test'})).toBe('test'); - }); - }); - - describe('selectView', () => { - it('should return .view portion of the state', () => { - expect(selectView({view: 'test'})).toBe('test'); - }); - }); - - describe('selectIntro', () => { - it('should return .intro portion of the state', () => { - expect(selectIntro({intro: 'test'})).toBe('test'); - }); - }); - - describe('selectLocationName', () => { - it('should return customLocation is useLocation is "custom"', () => { - expect(selectLocationName({ - settings: { - useLocation: 'custom', - customLocation: 'test' - } - })).toBe('test'); - }); - - test( - 'should return "auto" is useLocation is "custom" but customLocation is not set', - () => { - expect(selectLocationName({ - settings: { - useLocation: 'custom', - customLocation: '' - } - })).toBe('auto'); - } - ); - - it('should return "auto" is useLocation is not "custom"', () => { - expect(selectLocationName({ - settings: { - useLocation: 'test', - customLocation: '' - } - })).toBe('auto'); - }); - }); - - describe('selectWeatherData', () => { - it('should return data for specific location', () => { - expect(selectWeatherData({ - settings: {useLocation: 'auto'}, - weather: { - auto: 'test' - } - })).toBe('test'); - }); - - it('should return null when there is no data', () => { - expect(selectWeatherData({ - settings: {useLocation: 'auto'}, - weather: { - auto: '' - } - })).toEqual(null); - }); - }); - - describe('selectWeatherError', () => { - it('should return .error prop of the weather portion', () => { - expect(selectWeatherError({ - settings: {useLocation: 'auto'}, - weather: { - auto: { - error: 'test' - } - } - })).toBe('test'); - }); - }); - - describe('selectWeatherLoading', () => { - it('should return .loading prop of the weather portion', () => { - expect(selectWeatherLoading({ - settings: {useLocation: 'auto'}, - weather: { - auto: { - loading: 'test' - } - } - })).toBe('test'); - }); - }); - - describe('selectLocation', () => { - it('should return city info from weather data for specific location', () => { - expect(selectLocation({ - settings: {useLocation: 'auto'}, - weather: { - auto: { - data: { - location: { - city: 'test_name' - } - } - } - } - })).toEqual({ - city: 'test_name' - }); - }); - - it('should null if no weather data', () => { - expect(selectLocation({ - settings: {useLocation: 'auto'}, - weather: { - auto: null - } - })).toBe(null); - }); - }); - - describe('selectWeatherForecast', () => { - it('should return null if no weather data available', () => { - expect(selectWeatherForecast({ - settings: {useLocation: 'auto'}, - weather: { - auto: null - } - })).toBe(null); - }); - - it('should accumulate weather data for specific location', () => { - expect(selectWeatherForecast({ - settings: {useLocation: 'auto', temperatureUnits: 'c'}, - weather: { - auto: { - data: { - forecast: [{ - code: '1', - date: '1 Jan 2000', - day: 'Wed', - max: 1, - min: 10, - text: 'test1' - }, { - code: '2', - date: '12 Jan 2000', - day: 'Thu', - max: 2, - min: 20, - text: 'test2' - }] - } - } - } - })).toEqual([{ - code: '1', - date: '1 Jan 2000', - day: 'Wed', - max: 1, - min: 10, - text: 'test1' - }, { - code: '2', - date: '12 Jan 2000', - day: 'Thu', - max: 2, - min: 20, - text: 'test2' - }]); - }); - }); -}); diff --git a/src/__selectors/index.ts b/src/__selectors/index.ts deleted file mode 100644 index a96efca..0000000 --- a/src/__selectors/index.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { createSelector } from 'reselect'; -import { convertTemperature } from '../utils'; - -export const selectDock = state => state.dock; -export const selectSettings = state => state.settings; -export const selectIntro = state => state.intro; -export const selectWeather = state => state.weather; - -export const selectLocationName = createSelector( - selectSettings, - ({ useLocation, customLocation }) => - useLocation === 'custom' ? customLocation || 'auto' : 'auto', -); - -export const selectWeatherData = createSelector( - [selectWeather, selectLocationName], - (weather, location) => weather[location] || null, -); - -export const selectCurrentWeather = createSelector( - [selectWeatherData, selectSettings], - (weather, { temperatureUnits }) => { - if (!weather || !weather.data || !weather.data.current) return null; - const { current } = weather.data; - return { - ...current, - temp: convertTemperature(current.temp, temperatureUnits), - }; - }, -); - -export const selectWeatherForecast = createSelector( - [selectWeatherData, selectSettings], - (weather, { temperatureUnits }) => { - if (!weather || !weather.data || !weather.data.forecast) return null; - const { forecast } = weather.data; - return forecast.slice(0, 5).map(day => ({ - ...day, - min: convertTemperature(day.min, temperatureUnits), - max: convertTemperature(day.max, temperatureUnits), - })); - }, -); - -export const selectLocation = createSelector(selectWeatherData, weather => { - if (!weather || !weather.data || !weather.data.location) return null; - return weather.data.location; -}); - -export const selectWeatherLoading = createSelector( - selectWeatherData, - weather => weather && weather.loading, -); - -export const selectWeatherError = createSelector( - selectWeatherData, - weather => weather && weather.error, -); diff --git a/src/components/App/App.tsx b/src/components/App/App.tsx index 6452d47..c7c9555 100644 --- a/src/components/App/App.tsx +++ b/src/components/App/App.tsx @@ -4,22 +4,12 @@ import { useRef, useState } from 'react'; import classNames from 'classnames'; import { CSSTransition } from 'react-transition-group'; -// import FadeIn from '../../common/animations/FadeIn'; - -// import Intro from '../../containers/intro/Intro'; import Date from '../Date/Date'; import Dock from '../Dock/Dock'; import Settings from '../Settings/Settings'; import { SettingsState, useSettingsSlice } from '../../store/slices/settingsSlice'; import Clock from '../Clock/Clock'; import { DocTitleUpdater } from '../DocTitleUpdater/DocTitleUpdater'; -// import Settings from '../../containers/settings/Settings'; -// import SettingsGroups from '../SettingsGroups/SettingsGroups'; -// import SettingsTitle from '../Settings/SettingsTitle/SettingsTitle'; - -// import CurrentWeather from '../../containers/weather/Current'; -// import WeatherForecast from '../../containers/weather/Forecast'; -// import WeatherError from '../weather/Error'; const getStylesFromSettings = (settings: SettingsState) => { const getBackground = ( @@ -105,10 +95,7 @@ const App = () => { timeout={300} classNames="app--settings-transition">