Skip to content

Commit a585f45

Browse files
committed
migrate appboundary to ts
1 parent a9c8906 commit a585f45

3 files changed

Lines changed: 8 additions & 57 deletions

File tree

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'normalize.css';
44
import './index.css';
55
import App from './App';
66
import AppWrapper from 'src/providers/AppWrapper'
7-
import AppErrorBoundary from 'src/providers/AppErrorBoundary'
7+
import {AppErrorBoundary} from 'src/providers/AppErrorBoundary'
88
import { ConfigurationWrapper } from 'src/features/remoteConfig/'
99
import { QueryClientProvider } from '@tanstack/react-query'
1010
import { queryClient } from 'src/lib/react-query'
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import React from 'react'
2-
import { ErrorBoundary } from 'react-error-boundary'
2+
import { ErrorBoundary} from 'react-error-boundary'
33
import { AiFillBug } from 'react-icons/ai'
44
import { WiRefresh } from 'react-icons/wi'
55

6-
export default function AppErrorBoundary({ children }) {
7-
function ErrorFallback({ error, resetErrorBoundary }) {
6+
export const AppErrorBoundary = ({ children }: {children: React.ReactNode}) => {
7+
8+
const ErrorFallback = ({ error, resetErrorBoundary }: {error: Error, resetErrorBoundary: () => void}) => {
89
return (
910
<div className="Page appError">
1011
<AiFillBug size={64} />
1112
<p>Sorry there was a problem loading this page.</p>
12-
<p>{error}</p>
13+
<p>{error.message}</p>
1314
<button onClick={resetErrorBoundary}>
1415
<WiRefresh size={32} className={'buttonIcon'} /> Try again
1516
</button>

src/providers/AppWrapper.js

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,9 @@
1-
import React, { useReducer, useState, useEffect } from 'react'
2-
import { LS_PREFERENCES_KEY } from 'src/Constants'
3-
import AppStorage from '../services/localStorage'
4-
import { PreferencesProvider } from '../preferences/PreferencesContext'
5-
import { getOSMode } from '../services/os'
6-
import AppReducer from '../preferences/AppReducer'
7-
import { useRemoteConfigStore } from 'src/features/remoteConfig'
1+
import React, { useState, useEffect } from 'react'
82
import { migrateToNewStorage } from 'src/utils/StorageMigration'
93

104
export default function AppWrapper({ children }) {
11-
const {
12-
remoteConfig: { supportedTags },
13-
} = useRemoteConfigStore()
145
const [appReady, setAppReady] = useState(false)
156

16-
const [state, dispatcher] = useReducer(
17-
AppReducer,
18-
{
19-
userSelectedTags: supportedTags.filter((t) => t.value === 'javascript'),
20-
userBookmarks: [],
21-
theme: getOSMode(),
22-
openLinksNewTab: true,
23-
listingMode: 'normal',
24-
searchEngine: 'Google',
25-
cards: [
26-
{ id: 0, name: 'github' },
27-
{ id: 1, name: 'hackernews' },
28-
{ id: 2, name: 'devto' },
29-
{ id: 3, name: 'producthunt' },
30-
],
31-
},
32-
(initialState) => {
33-
let preferences = AppStorage.getItem(LS_PREFERENCES_KEY)
34-
if (preferences) {
35-
preferences = JSON.parse(preferences)
36-
preferences = {
37-
...preferences,
38-
userSelectedTags: supportedTags.filter((tag) =>
39-
preferences.userSelectedTags.includes(tag.value)
40-
),
41-
cards: preferences.cards.filter((card) => card.name !== 'stackoverflow'),
42-
}
43-
return {
44-
...initialState,
45-
...preferences,
46-
}
47-
}
48-
49-
return initialState
50-
}
51-
)
52-
537
useEffect(() => {
548
try {
559
migrateToNewStorage()
@@ -59,9 +13,5 @@ export default function AppWrapper({ children }) {
5913
}
6014
}, [])
6115

62-
return (
63-
<PreferencesProvider value={{ ...state, dispatcher: dispatcher }}>
64-
{appReady && children}
65-
</PreferencesProvider>
66-
)
16+
return appReady && children
6717
}

0 commit comments

Comments
 (0)