From 2cbc6e00e06fc27748dbfefd43fe9a27096f48cd Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 3 May 2023 12:46:57 -0600 Subject: [PATCH] Handling situation where React Router may not be available for a Tag Label. --- app/src/App.js | 27 +++++++++++------------ app/src/Tags.js | 36 +++++++++++++++++++++++++------ app/src/components/Channels.js | 2 +- app/src/components/FilePreview.js | 10 +++------ app/src/components/Theme.js | 2 +- app/src/components/VideoPlayer.js | 2 +- app/src/hooks/customHooks.js | 8 +++++++ modules/videos/channel/lib.py | 2 +- 8 files changed, 56 insertions(+), 33 deletions(-) diff --git a/app/src/App.js b/app/src/App.js index b3158035..d0ec9fa6 100644 --- a/app/src/App.js +++ b/app/src/App.js @@ -10,16 +10,16 @@ import {MoreRoute} from "./components/Apps"; import {InventoryRoute} from "./components/Inventory"; import {ArchiveRoute} from "./components/Archive"; import {FilesRoute} from "./components/Files"; -import {useStatusInterval} from "./hooks/customHooks"; +import {StatusProvider} from "./hooks/customHooks"; import {MapRoute} from "./components/Map"; import {MediaContextProvider, mediaStyles, StatusContext, ThemeContext} from "./contexts/contexts"; -import {Header, ThemeWrapper} from "./components/Theme"; +import {Header, ThemeProvider} from "./components/Theme"; import {Dashboard} from "./Dashboard"; import {Donate} from "./components/Donate"; import {useEventsInterval} from "./Events"; import {SemanticToastContainer} from "react-semantic-toasts-2"; -import {FilePreviewWrapper} from "./components/FilePreview"; -import {TagsContext, useTagsInterval} from "./Tags"; +import {FilePreviewProvider} from "./components/FilePreview"; +import {TagsProvider} from "./Tags"; function PageNotFound() { const {t} = useContext(ThemeContext); @@ -76,24 +76,21 @@ const router = createBrowserRouter(createRoutesFromElements()); export default function App() { - const statusValue = useStatusInterval(); - const tagsValue = useTagsInterval(); - useEventsInterval(); - return - - + return + + {/* Context and style to handle switching between mobile/computer. */} {/* Toasts can be on any page. */} - + - + - - - + + + } diff --git a/app/src/Tags.js b/app/src/Tags.js index 9530ff3b..d3b3f909 100644 --- a/app/src/Tags.js +++ b/app/src/Tags.js @@ -32,7 +32,7 @@ import _ from "lodash"; import {HexColorPicker} from "react-colorful"; import {useRecurringTimeout} from "./hooks/customHooks"; import {Media, ThemeContext} from "./contexts/contexts"; -import {Link} from "react-router-dom"; +import {Link, useNavigate} from "react-router-dom"; export const TagsContext = React.createContext({ NameToTagLabel: null, @@ -104,16 +104,30 @@ export function useTags() { } + const TagLabelLink = ({name, props}) => { + const to = `/?tag=${name}`; + const style = {marginLeft: '0.3em', marginRight: '0.3em'}; + try { + // We prefer to use Link to avoid reloading the page, check if React Router is available, so we can use it. + useNavigate(); + return + + + } catch { + // React Router is not available, use anchor. + return + + + } + } + const TagsLinkGroup = ({tagNames, ...props}) => { if (!tagNames || tagNames.length === 0) { return ; } + return - {tagNames.map(i => - - - - )} + {tagNames.map(i => )} } @@ -227,7 +241,7 @@ function EditTagsModal() { onClose={localOnClose} > Edit Tags -
+