Skip to content

Commit 3d44525

Browse files
committed
fix loading preferences
1 parent 58881e4 commit 3d44525

2 files changed

Lines changed: 19 additions & 25 deletions

File tree

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function App() {
1616
const [showSideBar, setShowSideBar] = useState(false)
1717
const [showSettings, setShowSettings] = useState(false)
1818
const [currentPage, setCurrentPage] = useState('home')
19-
const { state, dispatcher } = useContext(PreferencesContext)
19+
const { dispatcher, ...state } = useContext(PreferencesContext)
2020

2121
useEffect(() => {
2222
trackPageView(currentPage)

src/configuration/AppWrapper.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { ErrorBoundary } from 'react-error-boundary'
77
import { trackException } from '../utils/Analytics'
88
import { AiFillBug } from 'react-icons/ai'
99
import { WiRefresh } from 'react-icons/wi'
10-
import { APP } from '../Constants'
10+
import { APP, LS_PREFERENCES_KEY } from '../Constants'
11+
import AppStorage from '../services/localStorage'
1112

1213
function ErrorFallback({ error, resetErrorBoundary }) {
1314
return (
@@ -24,7 +25,6 @@ function ErrorFallback({ error, resetErrorBoundary }) {
2425

2526
export default function AppWrapper({ children }) {
2627
const configuration = useContext(ConfigurationContext)
27-
2828
const [state, dispatcher] = useReducer(
2929
AppReducer,
3030
{
@@ -42,22 +42,21 @@ export default function AppWrapper({ children }) {
4242
],
4343
},
4444
(initialState) => {
45-
try {
46-
let preferences = AppStorage.getItem(LS_PREFERENCES_KEY)
47-
if (preferences) {
48-
preferences = JSON.parse(preferences)
49-
preferences = {
50-
...preferences,
51-
userSelectedTags: supportedTags.filter((tag) =>
52-
preferences.userSelectedTags.includes(tag.value)
53-
),
54-
}
55-
return {
56-
...initialState,
57-
...preferences,
58-
}
45+
let preferences = AppStorage.getItem(LS_PREFERENCES_KEY)
46+
if (preferences) {
47+
preferences = JSON.parse(preferences)
48+
preferences = {
49+
...preferences,
50+
userSelectedTags: configuration.supportedTags.filter((tag) =>
51+
preferences.userSelectedTags.includes(tag.value)
52+
),
53+
}
54+
return {
55+
...initialState,
56+
...preferences,
5957
}
60-
} catch (e) {}
58+
}
59+
6160
return initialState
6261
}
6362
)
@@ -67,13 +66,8 @@ export default function AppWrapper({ children }) {
6766
}
6867

6968
return (
70-
<ErrorBoundary
71-
FallbackComponent={ErrorFallback}
72-
onError={errorHandler}
73-
onReset={() => {
74-
// reset the state of your app so the error doesn't happen again
75-
}}>
76-
<PreferencesProvider value={{ ...state, state, dispatcher: dispatcher }}>
69+
<ErrorBoundary FallbackComponent={ErrorFallback} onError={errorHandler}>
70+
<PreferencesProvider value={{ ...state, dispatcher: dispatcher }}>
7771
{children}
7872
</PreferencesProvider>
7973
</ErrorBoundary>

0 commit comments

Comments
 (0)