-
Notifications
You must be signed in to change notification settings - Fork 343
/
Copy pathindex.tsx
77 lines (67 loc) · 2.14 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { ThemeProvider } from 'styled-components'
import browser from 'webextension-polyfill'
import {
loadThemeVariant,
theme,
} from 'src/common-ui/components/design-library/theme'
import ErrorBoundary from 'src/common-ui/components/ErrorBoundary'
import RuntimeError from 'src/common-ui/components/RuntimeError'
import Popup from './container'
import configureStore from './store'
import { setupRpcConnection } from 'src/util/webextensionRPC'
import { MemexThemeVariant } from '@worldbrain/memex-common/lib/common-ui/styles/types'
import { AnnotationsSidebarInPageEventEmitter } from 'src/sidebar/annotations-sidebar/types'
import { EventEmitter } from 'events'
interface RootProps {
store: ReturnType<typeof configureStore>
getRootElement: () => HTMLElement
}
interface RootState {
themeVariant?: MemexThemeVariant
}
class Root extends React.Component<RootProps, RootState> {
state: RootState = {}
async componentDidMount() {
this.setState({
themeVariant: await loadThemeVariant(),
})
}
render() {
const { themeVariant } = this.state
if (!themeVariant) {
return null
}
return (
<Provider store={this.props.store}>
<ThemeProvider theme={theme({ variant: themeVariant })}>
<ErrorBoundary component={RuntimeError}>
<Popup
getRootElement={this.props.getRootElement}
analyticsBG={null}
/>
</ErrorBoundary>
</ThemeProvider>
</Provider>
)
}
}
function main() {
setupRpcConnection({
browserAPIs: browser,
sideName: 'content-script-popup',
role: 'content',
})
const store = configureStore()
document.getElementById('loader').remove()
ReactDOM.render(
<Root
getRootElement={() => document.getElementById('body')}
store={store}
/>,
document.getElementById('app'),
)
}
main()