-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from kieler/175-frontend-improve-user-navigation
Improve user navigation on the frontend
- Loading branch information
Showing
19 changed files
with
194 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use client"; | ||
|
||
import { SelectionDialog } from "@/app/components/track_selection"; | ||
|
||
/** | ||
* A modal track selection dialog that will be overlayed over the rest of the page | ||
*/ | ||
export default function SelectTrackModal() { | ||
|
||
return <SelectionDialog modal={true} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* By default, there is no modal present | ||
*/ | ||
export default function Default() { | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 8 additions & 11 deletions
19
Website/src/app/components/header.tsx → ...src/app/components/layout/currentUser.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,30 @@ | ||
"use client"; | ||
|
||
import Link from "next/link"; | ||
import { useContext } from "react"; | ||
import { UsernameContext } from "@/app/components/username-provider"; | ||
import Link from "next/link"; | ||
|
||
/** | ||
* The header for the web page | ||
* A component showing the name of the currently logged-in user, with a logout link, | ||
* or a login link if the user is not logged-in. | ||
*/ | ||
export default function Header() { | ||
export function CurrentUser({ className }: { className?: string }) { | ||
const username = useContext(UsernameContext); | ||
|
||
return ( | ||
<header className={"flex flex-row w-full flex-initial justify-items-center p-2"}> | ||
<div> | ||
<Link href={"/"}>RailTrail Admin interface</Link> | ||
</div> | ||
<div className={"grow"} /> | ||
<> | ||
{username ? ( | ||
<div> | ||
<div className={className}> | ||
Hello {username} –{" "} | ||
<Link href={"/logout"} prefetch={false}> | ||
Logout | ||
</Link> | ||
</div> | ||
) : ( | ||
<div> | ||
<div className={className}> | ||
<Link href={"/login"}>Login</Link> | ||
</div> | ||
)} | ||
</header> | ||
</> | ||
); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Link from "next/link"; | ||
import { CurrentUser } from "@/app/components/layout/currentUser"; | ||
import SmartNavigation from "@/app/components/layout/smart_navigation"; | ||
|
||
/** | ||
* The header for the web page | ||
*/ | ||
export default function Header() { | ||
return ( | ||
<header | ||
className={ | ||
"flex flex-row w-full items-center justify-around p-2 flex-wrap bg-white dark:bg-slate-900 gap-2" | ||
}> | ||
<div className={"mr-auto"}> | ||
<Link href={"/"}>RailTrail Verwaltung</Link> | ||
</div> | ||
<CurrentUser className={"ml-auto md:order-last"} /> | ||
{/* Force a line break for small devices */} | ||
<div className={"w-full md:hidden"} /> | ||
|
||
<SmartNavigation href={"/map"}>Karte</SmartNavigation> | ||
<SmartNavigation href={"/list"}>Liste</SmartNavigation> | ||
<SmartNavigation href={"/mapList"} className={"px-2 border-2 border-transparent hidden sm:block"}> | ||
Karte + Liste | ||
</SmartNavigation> | ||
|
||
<SmartNavigation href={"/management"}>Datenverwaltung</SmartNavigation> | ||
</header> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use client"; | ||
|
||
import Link, { LinkProps } from "next/link"; | ||
import { usePathname } from "next/navigation"; | ||
import { PropsWithChildren } from "react"; | ||
|
||
/** | ||
* A navigation link that has a different style when the user is on the page it links to, or on a sub-page | ||
* @param href The URL to navigate to | ||
* @param className CSS classes for the enclosing div | ||
* @param activeClassName Additional CSS classes for the enclosing div, when active | ||
* @param linkClassName The CSS classes for the anchor tag | ||
* @param children The contents in the anchor tag | ||
* @param props Other options applicable to <Link> | ||
* @constructor | ||
*/ | ||
export default function SmartNavigation({ | ||
href, | ||
className = "px-2 border-2 border-transparent", | ||
linkClassName, | ||
children, | ||
...props | ||
}: PropsWithChildren<LinkProps & { href: string; className?: string; linkClassName?: string }>) { | ||
// get the path of the currently open page | ||
const currentPath = usePathname(); | ||
|
||
// and determine if we are currently on that path | ||
const active = (currentPath === href || currentPath?.startsWith(href + "/")) ?? false; | ||
|
||
const activeClassName = "bg-neutral-500/20 !border-gray-500 rounded"; | ||
|
||
return ( | ||
<div className={className + (active ? " " + activeClassName : "")}> | ||
<Link href={href} className={linkClassName} {...props}> | ||
{children} | ||
</Link> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Link from "next/link"; | ||
|
||
/** | ||
* A link that somewhat resembles a button to select a different track. | ||
*/ | ||
export function SelectTrackButton() { | ||
return ( | ||
<Link | ||
href={"/select_track"} | ||
className={"bg-gray-200 dark:bg-slate-600 border-2 border-gray-500 rounded px-2 py-1 no-a-style"}> | ||
Andere Strecke wählen | ||
</Link> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.