Skip to content

Commit

Permalink
Merge pull request #390 from berty/feat/rememberTheme
Browse files Browse the repository at this point in the history
feat: Save last filters as next default filters.
  • Loading branch information
Jorropo authored Oct 5, 2020
2 parents 06f3aff + 1a3fcd9 commit cd6f82a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion web/src/hooks/queryHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const useSetFiltersOnQueryChange = () => {
const { search: locationSearch } = useLocation()
useEffect(() => {
const updateFilters = () => {
const { artifact_kinds, build_driver, build_state } = getFiltersFromUrlQuery({ locationSearch }) || {}
const { artifact_kinds, build_driver, build_state } = JSON.parse(window.localStorage.getItem("uiFilters")) || getFiltersFromUrlQuery({ locationSearch }) || {}
dispatch({
type: actions.UPDATE_UI_FILTERS,
payload: { artifact_kinds, build_driver, build_state },
Expand Down
4 changes: 3 additions & 1 deletion web/src/store/GlobalStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const INITIAL_STATE = {
build_state: [],
},
calculatedFilters: {
projects: [PROJECT.messenger],
projects: JSON.parse(window.localStorage.getItem("projects")) || [PROJECT.messenger],
order: 'created_at',
},
showingFilterModal: false,
Expand All @@ -58,6 +58,8 @@ function reducer(state, action) {
}
}
case actions.LOGOUT:
window.localStorage.removeItem("projects")
window.localStorage.removeItem("uiFilters")
return {
...state,
autoRefreshOn: false,
Expand Down
19 changes: 12 additions & 7 deletions web/src/ui/components/FilterModal/FilterModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const FilterModal = ({ closeAction }) => {
className="btn btn-primary"
data-dismiss="modal"
onClick={() => {
window.localStorage.setItem("projects", JSON.stringify([...selectedProjects]))
updateState({
isLoaded: false,
needsRefresh: true,
Expand All @@ -139,16 +140,20 @@ const FilterModal = ({ closeAction }) => {
},
})
closeAction()
const uiFilters = {
build_driver: selectedDrivers,
build_state: selectedBuildStates,
artifact_kinds: selectedArtifactKinds,
}
window.localStorage.setItem("uiFilters", JSON.stringify(uiFilters))
history.push({
path: '/',
search: queryString
.stringify(
_.pickBy({
build_driver: selectedDrivers,
build_state: selectedBuildStates,
artifact_kinds: selectedArtifactKinds,
},
(val) => getIsArrayWithN(val, 1)),
_.pickBy(
uiFilters,
(val) => getIsArrayWithN(val, 1),
),
),
})
}}
Expand All @@ -163,8 +168,8 @@ const FilterModal = ({ closeAction }) => {
<Tag
onClick={() => {
removeAuthCookie()
dispatch({ type: actions.LOGOUT })
dispatch({ type: actions.UPDATE_UI_FILTERS, payload: {} })
dispatch({ type: actions.LOGOUT })
closeAction()
redirectHome()
}}
Expand Down

0 comments on commit cd6f82a

Please sign in to comment.