This repository has been archived by the owner on May 10, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: split up actions/reducers into domain specific files
- Loading branch information
1 parent
feec878
commit b808785
Showing
24 changed files
with
504 additions
and
467 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import WebDB from '../web-db'; | ||
|
||
export const ACTION_ADD_LANGUAGE_REQUEST = 'ADD_LANGUAGE_REQUEST'; | ||
export const ACTION_ADD_LANGUAGE_SUCCESS = 'ADD_LANGUAGE_SUCCESS'; | ||
export const ACTION_ADD_LANGUAGE_FAILURE = 'ADD_LANGUAGE_FAILURE'; | ||
|
||
export const ACTION_REMOVE_LANGUAGE_REQUEST = 'REMOVE_LANGUAGE_REQUEST'; | ||
export const ACTION_REMOVE_LANGUAGE_SUCCESS = 'REMOVE_LANGUAGE_SUCCESS'; | ||
export const ACTION_REMOVE_LANGUAGE_FAILURE = 'REMOVE_LANGUAGE_FAILURE'; | ||
|
||
export function addLanguage(language) { | ||
return async function(dispatch, getState) { | ||
try { | ||
dispatch(sendAddLanguage()); | ||
|
||
const state = getState(); | ||
const db = new WebDB(state.login.username, state.login.password); | ||
const updatedLanguages = await db.addLanguage(language); | ||
dispatch(addLanguageSuccess(updatedLanguages)); | ||
} catch (err) { | ||
dispatch(addLanguageFailure()); | ||
throw err; | ||
} | ||
}; | ||
} | ||
|
||
export function removeLanguage(language) { | ||
return async function(dispatch, getState) { | ||
try { | ||
dispatch(sendRemoveLanguage()); | ||
|
||
const state = getState(); | ||
const db = new WebDB(state.login.username, state.login.password); | ||
const updatedLanguages = await db.removeLanguage(language); | ||
dispatch(removeLanguageSuccess(updatedLanguages)); | ||
} catch (err) { | ||
dispatch(removeLanguageFailure()); | ||
throw err; | ||
} | ||
}; | ||
} | ||
|
||
export function sendAddLanguage() { | ||
return { | ||
type: ACTION_ADD_LANGUAGE_REQUEST, | ||
}; | ||
} | ||
|
||
export function addLanguageSuccess(languages) { | ||
return { | ||
type: ACTION_ADD_LANGUAGE_SUCCESS, | ||
languages, | ||
}; | ||
} | ||
|
||
export function addLanguageFailure() { | ||
return { | ||
type: ACTION_ADD_LANGUAGE_FAILURE, | ||
}; | ||
} | ||
|
||
export function sendRemoveLanguage() { | ||
return { | ||
type: ACTION_REMOVE_LANGUAGE_REQUEST, | ||
}; | ||
} | ||
|
||
export function removeLanguageSuccess(languages) { | ||
return { | ||
type: ACTION_REMOVE_LANGUAGE_SUCCESS, | ||
languages, | ||
}; | ||
} | ||
|
||
export function removeLanguageFailure() { | ||
return { | ||
type: ACTION_REMOVE_LANGUAGE_FAILURE, | ||
}; | ||
} |
Oops, something went wrong.