diff --git a/postcss.config.js b/postcss.config.js index 3bf778b7..a3f5603f 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -1,8 +1,7 @@ // eslint-disable-next-line no-undef module.exports = { - plugins: { - tailwindcss: {}, - autoprefixer: {}, - } + plugins: { + tailwindcss: {}, + autoprefixer: {} } - \ No newline at end of file +} diff --git a/rollup.config.js b/rollup.config.js index 30cd35a8..e868bf42 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,21 +2,21 @@ import postcss from 'rollup-plugin-postcss' import typescript from 'rollup-plugin-typescript2' export default { - input: 'src/index.tsx', - output: [ - { - dir: 'dist/', - format: 'esm', - exports: 'named', - sourcemap: true, - strict: false - } - ], - plugins: [ - postcss({ - plugins: [] - }), - typescript(), - ], - external: ['react', 'react-dom', 'leaflet', 'react-leaflet', 'react-toastify' , 'react-string-replace', 'react-toastify/dist/ReactToastify.css','tw-elements' ,'react-router-dom', 'react-leaflet-cluster', '@tanstack/react-query', 'tributejs', 'prop-types', 'leaflet/dist/leaflet.css', '@heroicons/react/20/solid'] - } \ No newline at end of file + input: 'src/index.tsx', + output: [ + { + dir: 'dist/', + format: 'esm', + exports: 'named', + sourcemap: true, + strict: false + } + ], + plugins: [ + postcss({ + plugins: [] + }), + typescript() + ], + external: ['react', 'react-dom', 'leaflet', 'react-leaflet', 'react-toastify', 'react-string-replace', 'react-toastify/dist/ReactToastify.css', 'tw-elements', 'react-router-dom', 'react-leaflet-cluster', '@tanstack/react-query', 'tributejs', 'prop-types', 'leaflet/dist/leaflet.css', '@heroicons/react/20/solid'] +} diff --git a/src/Components/AppShell/AppShell.tsx b/src/Components/AppShell/AppShell.tsx index c388d922..be317061 100644 --- a/src/Components/AppShell/AppShell.tsx +++ b/src/Components/AppShell/AppShell.tsx @@ -2,11 +2,10 @@ import * as React from 'react' import NavBar from './NavBar' import { SetAssetsApi } from './SetAssetsApi' import { AssetsApi } from '../../types' -import { ContextWrapper } from './ContextWrapper'; +import { ContextWrapper } from './ContextWrapper' - -export function AppShell({ appName, children, assetsApi, userType }: { appName: string, children: React.ReactNode, assetsApi: AssetsApi, userType: string }) { - return ( +export function AppShell ({ appName, children, assetsApi, userType }: { appName: string, children: React.ReactNode, assetsApi: AssetsApi, userType: string }) { + return (
@@ -16,5 +15,5 @@ export function AppShell({ appName, children, assetsApi, userType }: { appName:
- ) + ) } diff --git a/src/Components/AppShell/Content.tsx b/src/Components/AppShell/Content.tsx index 3631f58a..f4625187 100644 --- a/src/Components/AppShell/Content.tsx +++ b/src/Components/AppShell/Content.tsx @@ -4,7 +4,7 @@ type ContentProps = { children?: React.ReactNode; } -export function Content({children} : ContentProps) { +export function Content ({ children } : ContentProps) { return (
{children} diff --git a/src/Components/AppShell/ContextWrapper.tsx b/src/Components/AppShell/ContextWrapper.tsx index 01468225..ddb54697 100644 --- a/src/Components/AppShell/ContextWrapper.tsx +++ b/src/Components/AppShell/ContextWrapper.tsx @@ -10,24 +10,23 @@ import { PermissionsProvider } from '../Map/hooks/usePermissions' import { SelectPositionProvider } from '../Map/hooks/useSelectPosition' import { TagsProvider } from '../Map/hooks/useTags' import { AssetsProvider } from './hooks/useAssets' -import { useContext, createContext } from 'react'; -import { BrowserRouter as Router, useLocation } from 'react-router-dom'; - +import { useContext, createContext } from 'react' +import { BrowserRouter as Router, useLocation } from 'react-router-dom' // Helper context to determine if the ContextWrapper is already present. -const ContextCheckContext = createContext(false); +const ContextCheckContext = createContext(false) // eslint-disable-next-line react/prop-types export const ContextWrapper = ({ children }) => { - const isWrapped = useContext(ContextCheckContext); + const isWrapped = useContext(ContextCheckContext) // Check if we are already inside a Router - let location; + let location try { // eslint-disable-next-line react-hooks/rules-of-hooks - location = useLocation(); + location = useLocation() } catch (e) { - location = null; + location = null } // Case 1: Only the Router is missing, but ContextWrapper is already provided @@ -36,7 +35,7 @@ export const ContextWrapper = ({ children }) => { {children} - ); + ) } // Case 2: Neither Router nor ContextWrapper is present @@ -49,7 +48,7 @@ export const ContextWrapper = ({ children }) => { - ); + ) } // Case 3: Only ContextWrapper is missing @@ -58,16 +57,16 @@ export const ContextWrapper = ({ children }) => { {children} - ); + ) } // Case 4: Both Router and ContextWrapper are already present - return children; -}; + return children +} // eslint-disable-next-line react/prop-types export const Wrappers = ({ children }) => { - const queryClient = new QueryClient(); + const queryClient = new QueryClient() return ( @@ -103,5 +102,5 @@ export const Wrappers = ({ children }) => { - ); -}; \ No newline at end of file + ) +} diff --git a/src/Components/AppShell/NavBar.tsx b/src/Components/AppShell/NavBar.tsx index e09be0ce..ebde697d 100644 --- a/src/Components/AppShell/NavBar.tsx +++ b/src/Components/AppShell/NavBar.tsx @@ -1,72 +1,64 @@ -import { useAuth } from "../Auth" -import { Link, useLocation } from "react-router-dom"; -import { toast } from "react-toastify"; +import { useAuth } from '../Auth' +import { Link, useLocation } from 'react-router-dom' +import { toast } from 'react-toastify' import QuestionMarkIcon from '@heroicons/react/24/outline/QuestionMarkCircleIcon' -import { useEffect, useRef, useState } from "react"; -import { useItems } from "../Map/hooks/useItems"; -import { Item } from "../../types"; +import { useEffect, useRef, useState } from 'react' +import { useItems } from '../Map/hooks/useItems' +import { Item } from '../../types' +export default function NavBar ({ appName, userType }: { appName: string, userType: string }) { + const { isAuthenticated, user, logout } = useAuth() -export default function NavBar({ appName, userType}: { appName: string, userType: string }) { - - - const { isAuthenticated, user, logout } = useAuth(); - - const [userProfile, setUserProfile] = useState({}as Item); - const items = useItems(); + const [userProfile, setUserProfile] = useState({}as Item) + const items = useItems() useEffect(() => { - const profile = user && items.find(i => (i.user_created?.id === user.id) && i.layer?.itemType.name === userType); - profile ? setUserProfile(profile) : setUserProfile({id: crypto.randomUUID(), name: user?.first_name, text: ""}); + const profile = user && items.find(i => (i.user_created?.id === user.id) && i.layer?.itemType.name === userType) + profile ? setUserProfile(profile) : setUserProfile({ id: crypto.randomUUID(), name: user?.first_name, text: '' }) // eslint-disable-next-line react-hooks/exhaustive-deps }, [user, items]) useEffect(() => { - + }, [userProfile]) - - const nameRef = useRef(null); - const [nameWidth, setNameWidth] = useState(0); - const location = useLocation(); + + const nameRef = useRef(null) + const [nameWidth, setNameWidth] = useState(0) + const location = useLocation() const [showNav, setShowNav] = useState(false) - - useEffect(() => { - showNav && nameRef && setNameWidth(nameRef.current.scrollWidth) + showNav && nameRef && setNameWidth(nameRef.current.scrollWidth) }, [nameRef, appName, showNav]) - - - useEffect(() => { - const params = new URLSearchParams(location.search); - const embedded = params.get("embedded"); - embedded!="true" && setShowNav(true) - }, [location]); - + const params = new URLSearchParams(location.search) + const embedded = params.get('embedded') + embedded != 'true' && setShowNav(true) + }, [location]) const onLogout = () => { toast.promise( logout(), { success: { - render() { + render () { return `Bye bye` }, // other options - icon: "πŸ‘‹", + icon: 'πŸ‘‹' }, error: { - render( {data} ) { + render ({ data }) { return `${data}` - }, + } }, pending: 'logging out ..' - }); + }) } - if(showNav) return ( + if (showNav) { + return ( <>
-
-

{appName}

+
+

{appName}

- - - {isAuthenticated ? -
- + {isAuthenticated + ?
+ { userProfile?.image &&
- +
} -
{userProfile.name||user?.first_name}
+
{userProfile.name || user?.first_name}
- : -
+ :
-
+
Login
-
+
Sign Up
@@ -126,11 +115,10 @@ export default function NavBar({ appName, userType}: { appName: string, userType -
    -
  • Login
  • -
  • Sign Up
  • +
  • Login
  • +
  • Sign Up
@@ -139,6 +127,6 @@ export default function NavBar({ appName, userType}: { appName: string, userType
- ) - else return (<>) + ) + } else return (<>) } diff --git a/src/Components/AppShell/SetAssetsApi.tsx b/src/Components/AppShell/SetAssetsApi.tsx index 410d3063..e4874d47 100644 --- a/src/Components/AppShell/SetAssetsApi.tsx +++ b/src/Components/AppShell/SetAssetsApi.tsx @@ -1,15 +1,14 @@ import { useSetAssetApi } from './hooks/useAssets' -import { AssetsApi } from '../../types'; -import { useEffect } from 'react'; +import { AssetsApi } from '../../types' +import { useEffect } from 'react' -export const SetAssetsApi = ({assetsApi}:{assetsApi: AssetsApi}) => { - const setAssetsApi = useSetAssetApi(); +export const SetAssetsApi = ({ assetsApi }:{assetsApi: AssetsApi}) => { + const setAssetsApi = useSetAssetApi() - useEffect(() => { - setAssetsApi(assetsApi) + useEffect(() => { + setAssetsApi(assetsApi) // eslint-disable-next-line react-hooks/exhaustive-deps - }, [assetsApi]) - + }, [assetsApi]) return ( <> diff --git a/src/Components/AppShell/SideBar.tsx b/src/Components/AppShell/SideBar.tsx index 7b1754c5..59a9a2d5 100644 --- a/src/Components/AppShell/SideBar.tsx +++ b/src/Components/AppShell/SideBar.tsx @@ -1,13 +1,12 @@ -import { useRef, useState } from 'react' -import { useEffect } from 'react' -import { NavLink, useLocation } from 'react-router-dom'; +import { useRef, useState, useEffect } from 'react' +import { NavLink, useLocation } from 'react-router-dom' import { Sidenav, - initTE, -} from "tw-elements"; -import SidebarSubmenu from './SidebarSubmenu'; -import ChevronRightIcon from '@heroicons/react/24/outline/ChevronRightIcon'; -import * as React from 'react'; + initTE +} from 'tw-elements' +import SidebarSubmenu from './SidebarSubmenu' +import ChevronRightIcon from '@heroicons/react/24/outline/ChevronRightIcon' +import * as React from 'react' type route = { path: string; @@ -18,53 +17,46 @@ type route = { blank?: boolean } - -export function SideBar({ routes, bottomRoutes }: { routes: route[], bottomRoutes?: route[] }) { - +export function SideBar ({ routes, bottomRoutes }: { routes: route[], bottomRoutes?: route[] }) { // prevent react18 from calling useEffect twice const init = useRef(false) - const location = useLocation(); - - const [instance, setInstance] = useState(null); - const [slim, setSlim] = useState(false); - + const location = useLocation() + const [instance, setInstance] = useState(null) + const [slim, setSlim] = useState(false) const toggleSlim = () => { - setSlim(!slim); - instance.toggleSlim(); + setSlim(!slim) + instance.toggleSlim() } - - useEffect(() => { if (!init.current) { - initTE({ Sidenav }); + initTE({ Sidenav }) const instance = Sidenav.getInstance( - document.getElementById("sidenav") - ); - setInstance(instance); - instance.toggleSlim(); - init.current = true; + document.getElementById('sidenav') + ) + setInstance(instance) + instance.toggleSlim() + init.current = true } }, []) const [embedded, setEmbedded] = useState(true) - useEffect(() => { - const params = new URLSearchParams(location.search); - const embedded = params.get("embedded"); - embedded != "true" && setEmbedded(false) - }, [location]); + const params = new URLSearchParams(location.search) + const embedded = params.get('embedded') + embedded != 'true' && setEmbedded(false) + }, [location]) - const params = new URLSearchParams(window.location.search); + const params = new URLSearchParams(window.location.search) return (