Skip to content

Commit

Permalink
Navigate to route /${selectedSpace}
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbroman committed Jul 12, 2023
1 parent 234b929 commit 29a1fc1
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 40 deletions.
4 changes: 2 additions & 2 deletions lexicon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@urbit/http-api": "^2.3.0",
"react-router-dom": "^6.4.3",
"react-router-dom": "^6.14.1",
"zustand": "^4.3.8"
},
"peerDependencies": {
Expand All @@ -31,4 +31,4 @@
"babel-loader": "^8.3.0",
"babel-plugin-styled-components": "^2.0.7"
}
}
}
69 changes: 38 additions & 31 deletions lexicon/src/Lexicon.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { useEffect } from 'react';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import {
BrowserRouter,
Navigate,
redirect,
Route,
Routes,
} from 'react-router-dom';
import { createGlobalStyle } from 'styled-components';

import {
Expand Down Expand Up @@ -28,6 +34,7 @@ const GlobalStyle = createGlobalStyle`
outline: none;
}
`;

declare global {
interface Window {
ship: string;
Expand Down Expand Up @@ -296,37 +303,37 @@ export const Lexicon = ({
useEffect(() => {
setShipName(shipName);
}, [shipName]);

useEffect(() => {
// Start at the root path.
redirect('/');
}, []);

if (!api) return null;

return (
<>
<main
style={{
overflowY: 'auto',
height: '100vh',
backgroundColor: 'transparent',
}}
>
<GlobalStyle />
<Router>
<Routes>
<Route element={<Navigation selectedSpace={selectedSpace} />}>
<Route
path="/index.html/:ship/:group/:word"
element={<WordPage />}
/>
<Route path="/index.html/:ship/:group" element={<HomePage />} />
<Route
path="/index.html/dict/:word"
element={<DictionaryPage />}
/>
<Route
path="/index.html"
element={<p>don't mind me just redirecting over here</p>}
/>
</Route>
</Routes>
</Router>
</main>
</>
<main
style={{
overflowY: 'auto',
height: '100vh',
backgroundColor: 'transparent',
}}
>
<GlobalStyle />
<BrowserRouter>
<Routes>
<Route element={<Navigation selectedSpace={selectedSpace} />}>
<Route path="/:ship/:group/:word" element={<WordPage />} />
<Route path="/:ship/:group" element={<HomePage />} />
<Route path="/dict/:word" element={<DictionaryPage />} />
<Route
path="/"
element={<p>don't mind me just redirecting over here</p>}
/>
</Route>
</Routes>
<Navigate to={selectedSpace} />
</BrowserRouter>
</main>
);
};
2 changes: 1 addition & 1 deletion trove/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"mime": "^3.0.0",
"moment": "^2.29.4",
"react-dnd-html5-backend": "^16.0.1",
"react-router-dom": "^6.4.3",
"react-router-dom": "^6.14.1",
"styled-components": "^5.3.6",
"styled-system": "^5.1.5",
"urbit-ob": "^5.0.1",
Expand Down
22 changes: 17 additions & 5 deletions trove/src/Trove.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { useEffect } from 'react';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import {
BrowserRouter,
Navigate,
redirect,
Route,
Routes,
} from 'react-router-dom';
import { createTheme, ThemeProvider } from '@mui/material/styles';

import { trovePreload } from '../../app/src/os/services/ship/trove.service';
Expand Down Expand Up @@ -53,6 +59,11 @@ export const Trove = ({
const space = useTroveStore((store: TroveStore) => store.space);
const setApi = useTroveStore((store: TroveStore) => store.setApi);

useEffect(() => {
// Start at the root path.
redirect('/');
}, []);

useEffect(() => {
//subscribe to updates here
TroveIPC.UIUpdates();
Expand Down Expand Up @@ -90,11 +101,11 @@ export const Trove = ({
}}
>
<ThemeProvider theme={muiTheme}>
<Router>
<BrowserRouter>
<Routes>
<Route element={<Navigation selectedSpace={selectedSpace} />}>
<Route
path="index.html/:ship/:group"
path="/:ship/:group"
element={
<Home
useStorage={useStorage}
Expand All @@ -104,14 +115,15 @@ export const Trove = ({
}
/>
<Route
path="index.html/"
path="/"
element={
<>Enter a space in the url example: ...apps/trove/~zod/our</>
}
/>
</Route>
</Routes>
</Router>
<Navigate to={selectedSpace} />
</BrowserRouter>
</ThemeProvider>
</main>
);
Expand Down
1 change: 1 addition & 0 deletions trove/src/components/NavigationHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { WrappedBackground } from '../components';
import { splitLastOccurrence } from '../helpers';
import useTroveStore, { TroveStore } from '../store/troveStore';
import { theme } from '../theme';

export const NavigationHeader = () => {
const currentSpace = useTroveStore((store: TroveStore) => store.currentSpace);
const [stlfDisplay, setStflDisplay] = useState<string>('');
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17274,7 +17274,7 @@ react-remove-scroll@2.5.5:
use-callback-ref "^1.3.0"
use-sidecar "^1.1.2"

react-router-dom@^6.4.3:
react-router-dom@^6.14.1:
version "6.14.1"
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.14.1.tgz#0ad7ba7abdf75baa61169d49f096f0494907a36f"
integrity sha512-ssF6M5UkQjHK70fgukCJyjlda0Dgono2QGwqGvuk7D+EDGHdacEN3Yke2LTMjkrpHuFwBfDFsEjGVXBDmL+bWw==
Expand Down

0 comments on commit 29a1fc1

Please sign in to comment.