[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.

179 lines
6.7 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. // app.tsx
  2. // Copyright (C) 2020 Dwayne Harris
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License for more details.
  11. // You should have received a copy of the GNU General Public License
  12. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. import React, { FC, useEffect } from 'react'
  14. import { useSelector, useDispatch } from 'react-redux'
  15. import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
  16. import { handleApiError } from '../api/errors'
  17. import { fetchSelf, setChecked } from '../actions/authentication'
  18. import { setTheme } from '../actions/theme'
  19. import { getAuthenticatedUser } from '../selectors/authentication'
  20. import { getFetching } from '../selectors'
  21. import { LOCAL_STORAGE_ACCESS_TOKEN_KEY } from '../constants'
  22. import { useDeepCompareEffect, useTheme } from '../hooks'
  23. import { AppThunkDispatch } from '../types'
  24. import Footer from './footer'
  25. import Logo from './logo'
  26. import NavigationMenu from './navigation-menu'
  27. import NotificationContainer from './notification-container'
  28. import Search from './search'
  29. import SelfInfo from './self-info'
  30. import Spinner from './spinner'
  31. import About from './pages/about'
  32. import Admin from './pages/admin'
  33. import AdminApps from './pages/admin-apps'
  34. import AdminGroups from './pages/admin-groups'
  35. import Apps from './pages/apps'
  36. import CreateApp from './pages/create-app'
  37. import Developers from './pages/developers'
  38. import EditApp from './pages/edit-app'
  39. import GroupAdmin from './pages/group-admin'
  40. import Groups from './pages/groups'
  41. import Home from './pages/home'
  42. import Login from './pages/login'
  43. import Register from './pages/register'
  44. import RegisterGroup from './pages/register-group'
  45. import Self from './pages/self'
  46. import ViewApp from './pages/view-app'
  47. import ViewGroup from './pages/view-group'
  48. import ViewPost from './pages/view-post'
  49. import ViewUser from './pages/view-user'
  50. import '../styles/app.css'
  51. const App: FC = () => {
  52. const theme = useTheme()
  53. const user = useSelector(getAuthenticatedUser)
  54. const fetching = useSelector(getFetching)
  55. const dispatch = useDispatch<AppThunkDispatch>()
  56. const init = async () => {
  57. if (localStorage.getItem(LOCAL_STORAGE_ACCESS_TOKEN_KEY)) {
  58. try {
  59. await dispatch(fetchSelf())
  60. } catch (err) {
  61. console.log('err', err)
  62. handleApiError(err, dispatch)
  63. }
  64. } else {
  65. dispatch(setChecked())
  66. }
  67. }
  68. useEffect(() => {
  69. init()
  70. }, [])
  71. useDeepCompareEffect(() => {
  72. if (user && user.theme) dispatch(setTheme(user.theme))
  73. }, [user])
  74. useDeepCompareEffect(() => {
  75. document.body.style.backgroundColor = theme.backgroundPrimary
  76. }, [theme])
  77. return (
  78. <Router>
  79. <main style={{ backgroundColor: theme.backgroundPrimary }}>
  80. <div className="logo-container">
  81. <Logo />
  82. </div>
  83. <div className="content-container" style={{ backgroundColor: theme.backgroundPrimary }}>
  84. <div className="content" style={{ borderLeftColor: theme.backgroundSecondary, borderRightColor: theme.backgroundPrimary }}>
  85. <Switch>
  86. <Route path="/c/:id/admin/:tab?">
  87. <GroupAdmin />
  88. </Route>
  89. <Route path="/c/:id/register">
  90. <RegisterGroup />
  91. </Route>
  92. <Route path="/c/:id">
  93. <ViewGroup />
  94. </Route>
  95. <Route path="/a/:id/edit">
  96. <EditApp />
  97. </Route>
  98. <Route path="/a/:id">
  99. <ViewApp />
  100. </Route>
  101. <Route path="/u/:id">
  102. <ViewUser />
  103. </Route>
  104. <Route path="/p/:id">
  105. <ViewPost />
  106. </Route>
  107. <Route path="/login">
  108. <Login />
  109. </Route>
  110. <Route path="/register">
  111. <Register />
  112. </Route>
  113. <Route path="/communities">
  114. <Groups />
  115. </Route>
  116. <Route path="/self">
  117. <Self />
  118. </Route>
  119. <Route path="/apps">
  120. <Apps />
  121. </Route>
  122. <Route path="/developers/create">
  123. <CreateApp />
  124. </Route>
  125. <Route path="/developers">
  126. <Developers />
  127. </Route>
  128. <Route path="/about">
  129. <About />
  130. </Route>
  131. <Route path="/admin/apps">
  132. <AdminApps />
  133. </Route>
  134. <Route path="/admin/groups">
  135. <AdminGroups />
  136. </Route>
  137. <Route path="/admin">
  138. <Admin />
  139. </Route>
  140. <Route path="/">
  141. <Home />
  142. </Route>
  143. </Switch>
  144. </div>
  145. </div>
  146. <div className="menu-container">
  147. <div className="menu" style={{ backgroundColor: theme.backgroundSecondary, borderColor: theme.backgroundPrimary }}>
  148. <Search />
  149. <NavigationMenu />
  150. {fetching && <Spinner />}
  151. <SelfInfo />
  152. <Footer />
  153. </div>
  154. </div>
  155. <NotificationContainer />
  156. </main>
  157. </Router>
  158. )
  159. }
  160. export default App