[ABANDONED] React/Redux front end for the Flexor social network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
6.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. import React, { FC, useEffect } from 'react'
  2. import { useSelector, useDispatch } from 'react-redux'
  3. import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
  4. import { handleApiError } from '../api/errors'
  5. import { fetchSelf, setChecked } from '../actions/authentication'
  6. import { setTheme } from '../actions/theme'
  7. import { getAuthenticatedUser } from '../selectors/authentication'
  8. import { getFetching } from '../selectors'
  9. import { LOCAL_STORAGE_ACCESS_TOKEN_KEY } from '../constants'
  10. import { useDeepCompareEffect, useTheme } from '../hooks'
  11. import { AppThunkDispatch } from '../types'
  12. import Footer from './footer'
  13. import Logo from './logo'
  14. import NavigationMenu from './navigation-menu'
  15. import NotificationContainer from './notification-container'
  16. import Search from './search'
  17. import SelfInfo from './self-info'
  18. import Spinner from './spinner'
  19. import About from './pages/about'
  20. import Admin from './pages/admin'
  21. import AdminApps from './pages/admin-apps'
  22. import AdminGroups from './pages/admin-groups'
  23. import Apps from './pages/apps'
  24. import CreateApp from './pages/create-app'
  25. import Developers from './pages/developers'
  26. import EditApp from './pages/edit-app'
  27. import GroupAdmin from './pages/group-admin'
  28. import Groups from './pages/groups'
  29. import Home from './pages/home'
  30. import Login from './pages/login'
  31. import Register from './pages/register'
  32. import RegisterGroup from './pages/register-group'
  33. import Self from './pages/self'
  34. import ViewApp from './pages/view-app'
  35. import ViewGroup from './pages/view-group'
  36. import ViewPost from './pages/view-post'
  37. import ViewUser from './pages/view-user'
  38. import '../styles/app.css'
  39. const App: FC = () => {
  40. const theme = useTheme()
  41. const user = useSelector(getAuthenticatedUser)
  42. const fetching = useSelector(getFetching)
  43. const dispatch = useDispatch<AppThunkDispatch>()
  44. const init = async () => {
  45. if (localStorage.getItem(LOCAL_STORAGE_ACCESS_TOKEN_KEY)) {
  46. try {
  47. await dispatch(fetchSelf())
  48. } catch (err) {
  49. console.log('err', err)
  50. handleApiError(err, dispatch)
  51. }
  52. } else {
  53. dispatch(setChecked())
  54. }
  55. }
  56. useEffect(() => {
  57. init()
  58. }, [])
  59. useDeepCompareEffect(() => {
  60. if (user && user.theme) dispatch(setTheme(user.theme))
  61. }, [user])
  62. useDeepCompareEffect(() => {
  63. document.body.style.backgroundColor = theme.backgroundPrimary
  64. }, [theme])
  65. return (
  66. <Router>
  67. <main style={{ backgroundColor: theme.backgroundPrimary }}>
  68. <div className="logo-container">
  69. <Logo />
  70. </div>
  71. <div className="content-container" style={{ backgroundColor: theme.backgroundPrimary }}>
  72. <div className="content" style={{ borderLeftColor: theme.backgroundSecondary, borderRightColor: theme.backgroundPrimary }}>
  73. <Switch>
  74. <Route path="/c/:id/admin/:tab?">
  75. <GroupAdmin />
  76. </Route>
  77. <Route path="/c/:id/register">
  78. <RegisterGroup />
  79. </Route>
  80. <Route path="/c/:id">
  81. <ViewGroup />
  82. </Route>
  83. <Route path="/a/:id/edit">
  84. <EditApp />
  85. </Route>
  86. <Route path="/a/:id">
  87. <ViewApp />
  88. </Route>
  89. <Route path="/u/:id">
  90. <ViewUser />
  91. </Route>
  92. <Route path="/p/:id">
  93. <ViewPost />
  94. </Route>
  95. <Route path="/login">
  96. <Login />
  97. </Route>
  98. <Route path="/register">
  99. <Register />
  100. </Route>
  101. <Route path="/communities">
  102. <Groups />
  103. </Route>
  104. <Route path="/self">
  105. <Self />
  106. </Route>
  107. <Route path="/apps">
  108. <Apps />
  109. </Route>
  110. <Route path="/developers/create">
  111. <CreateApp />
  112. </Route>
  113. <Route path="/developers">
  114. <Developers />
  115. </Route>
  116. <Route path="/about">
  117. <About />
  118. </Route>
  119. <Route path="/admin/apps">
  120. <AdminApps />
  121. </Route>
  122. <Route path="/admin/groups">
  123. <AdminGroups />
  124. </Route>
  125. <Route path="/admin">
  126. <Admin />
  127. </Route>
  128. <Route path="/">
  129. <Home />
  130. </Route>
  131. </Switch>
  132. </div>
  133. </div>
  134. <div className="menu-container">
  135. <div className="menu" style={{ backgroundColor: theme.backgroundSecondary, borderColor: theme.backgroundPrimary }}>
  136. <Search />
  137. <NavigationMenu />
  138. {fetching && <Spinner />}
  139. <SelfInfo />
  140. <Footer />
  141. </div>
  142. </div>
  143. <NotificationContainer />
  144. </main>
  145. </Router>
  146. )
  147. }
  148. export default App