Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface HeaderProps {

export default function Header(props: HeaderProps) {
return (
<div className="pointer-events-none fixed z-10 flex h-14 w-full items-center p-2">
<div className="pointer-events-none fixed z-10 flex justify-between h-14 w-full items-center p-2">
<Home />
<NavBar devices={props.devices} />
<Menu />
Expand Down
275 changes: 227 additions & 48 deletions app/components/header/menu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,237 @@
// import * as Dialog from '@radix-ui/react-dialog';
import { Bars3Icon } from '@heroicons/react/24/outline'
import { Link, useLocation } from "@remix-run/react";
import React from 'react';
import { Form, Link, useNavigation, useSearchParams } from "@remix-run/react";
// import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { useToast } from "@/components/ui/use-toast";
import { useLoaderData } from "@remix-run/react";
import type { loader } from "~/routes/explore";
import {
Bars3Icon,
UserCircleIcon,
CpuChipIcon,
Cog6ToothIcon,
ArrowRightOnRectangleIcon,
ArrowLeftOnRectangleIcon,
PlusCircleIcon,
GlobeAltIcon,
PuzzlePieceIcon,
QuestionMarkCircleIcon,
EnvelopeIcon,
IdentificationIcon,
LockClosedIcon,
CurrencyEuroIcon,
UserGroupIcon,
UserIcon,
ArrowTopRightOnSquareIcon,
} from "@heroicons/react/24/outline";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";

export function useFirstRender() {
const firstRender = useRef(true);

useEffect(() => {
firstRender.current = false;
}, []);

return firstRender.current;
}

export default function Menu() {
const [searchParams] = useSearchParams();
// @ts-ignore
const redirectTo = (searchParams.size > 0 ? "/explore?" + searchParams.toString() : "/explore")
const data = useLoaderData<typeof loader>();
const [open, setOpen] = useState(false);
const { toast } = useToast();
const navigation = useNavigation();
const isLoggingOut = Boolean(navigation.state === "submitting");
const [timeToToast, setTimeToToast] = useState<Boolean>(false);

const [isOpen, setIsOpen] = React.useState(false);
const toggleDrawer = () => setIsOpen(!isOpen);
const { t } = useTranslation("menu");

const location = useLocation();
const firstRender = useFirstRender();

useEffect(() => {
if (!firstRender && !timeToToast) {
setTimeToToast(true);
} else if (!firstRender && timeToToast) {
if (data.user === null) {
toast({
description: t("toast_logout_success"),
});
}
if (data.user !== null) {
const creationDate = Date.parse(data.user.createdAt);
const now = Date.now();
const diff = now - creationDate;
if (diff < 10000) {
toast({
description: t("toast_user_creation_success"),
});
setTimeout(() => {
toast({
description: t("toast_login_success"),
});
}, 100);
} else {
toast({
description: t("toast_login_success"),
});
}
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [data.user, toast, firstRender]);

return (
// <div className="box-border w-10 h-10 pointer-events-auto">
// <Dialog.Root>
// <Dialog.Trigger asChild>
// <button type="button" className="w-10 h-10 rounded-full text-black text-center hover:bg-gray-200 bg-white">
// <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-6 h-6 mx-auto">
// <path strokeLinecap="round" strokeLinejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" />
// </svg>
// </button>
// </Dialog.Trigger>
// <Dialog.Portal>
// <Dialog.Overlay className="bg-black opacity-25 fixed inset-0 z-50" />
// <Dialog.Content className="data-[state=open]:animate-sidebarOpen data-[state=closed]:animate-sidebarClose fixed inset-y-0 right-0 w-1/2 h-[100%] rounded-l-[1.25rem] bg-white p-[25px] shadow-[hsl(206_22%_7%_/_35%)_0px_10px_38px_-10px,_hsl(206_22%_7%_/_20%)_0px_10px_20px_-15px] focus:outline-none z-50">
// {/* Fill me with customized content */}
// <Link to="/impressum">
// Impressum
// </Link>
// <Dialog.Close asChild>
// <button
// className="absolute top-[10px] right-[10px] inline-flex h-[25px] w-[25px] items-center justify-center"
// aria-label="Close"
// >
// <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-6 h-6 mx-auto">
// <path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
// </svg>
// </button>
// </Dialog.Close>
// </Dialog.Content>
// </Dialog.Portal>
// </Dialog.Root>
// </div>

<div className="box-border w-10 h-10 pointer-events-auto">
<Link to="sidebar" state={location.pathname}>
<button type="button" className="w-10 h-10 rounded-full text-black text-center hover:bg-gray-100 bg-white border border-gray-100" onClick={toggleDrawer}>
{/* <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-6 h-6 mx-auto">
<path strokeLinecap="round" strokeLinejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" />
</svg> */}
<Bars3Icon className="w-6 h-6 mx-auto"/>
</button>
</Link>
</div>
<DropdownMenu open={open} onOpenChange={setOpen}>
<DropdownMenuTrigger asChild>
<div className="pointer-events-auto box-border h-10 w-10">
<button
type="button"
className="h-10 w-10 rounded-full border border-gray-100 bg-white text-center text-black hover:bg-gray-100"
>
{data.user === null ? (
<Bars3Icon className="mx-auto h-6 w-6" />
) : (
<UserIcon className="mx-auto h-6 w-6" />
)}
</button>
</div>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56" align="end" forceMount>
<DropdownMenuLabel className="font-normal">
{data.user === null ? (
<div className="flex flex-col space-y-1">
<p className="text-sm font-medium leading-none">{t("title")}</p>
<p className="text-xs leading-none text-muted-foreground">
{t("subtitle")}
</p>
</div>
) : (
<div className="flex flex-col space-y-1">
<p className="text-sm font-medium leading-none">Max Mustermann</p>
<p className="text-xs leading-none text-muted-foreground">
{data.user.email}
</p>
</div>
)}
</DropdownMenuLabel>
<DropdownMenuSeparator />
{data.user !== null ? (
<DropdownMenuGroup>
<DropdownMenuItem>
<UserCircleIcon className="mr-2 h-5 w-5" />
<span>{t("profile_label")}</span>
</DropdownMenuItem>
<DropdownMenuItem>
<Cog6ToothIcon className="mr-2 h-5 w-5" />
<span>{t("settings_label")}</span>
</DropdownMenuItem>
<DropdownMenuItem>
<CpuChipIcon className="mr-2 h-5 w-5" />
<span>{t("my_devices_label")}</span>
</DropdownMenuItem>
<DropdownMenuItem>
<PlusCircleIcon className="mr-2 h-5 w-5" />
<span>{t("add_device_label")}</span>
</DropdownMenuItem>
<DropdownMenuSeparator />
</DropdownMenuGroup>
) : null}
<DropdownMenuGroup>
<Link to="https://docs.sensebox.de/" target="_blank">
<DropdownMenuItem>
<PuzzlePieceIcon className="mr-2 h-5 w-5" />
<span>{t("tutorials_label")}</span>
<ArrowTopRightOnSquareIcon className="ml-auto h-4 w-4 text-gray-300" />
</DropdownMenuItem>
</Link>
<Link to="https://docs.opensensemap.org/" target="_blank">
<DropdownMenuItem>
<GlobeAltIcon className="mr-2 h-5 w-5" />
<span>{t("api_docs_label")}</span>
<ArrowTopRightOnSquareIcon className="ml-auto h-4 w-4 text-gray-300" />
</DropdownMenuItem>
</Link>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem>
<QuestionMarkCircleIcon className="mr-2 h-5 w-5" />
<span>{t("faq_label")}</span>
</DropdownMenuItem>
<DropdownMenuItem>
<EnvelopeIcon className="mr-2 h-5 w-5" />
<span>{t("contact_label")}</span>
</DropdownMenuItem>
<DropdownMenuItem>
<IdentificationIcon className="mr-2 h-5 w-5" />
<span>{t("imprint_label")}</span>
</DropdownMenuItem>
<DropdownMenuItem>
<LockClosedIcon className="mr-2 h-5 w-5" />
<span>{t("data_protection_label")}</span>
</DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem>
<CurrencyEuroIcon className="mr-2 h-5 w-5" />
<span>{t("donate_label")}</span>
</DropdownMenuItem>
<DropdownMenuItem>
<UserGroupIcon className="mr-2 h-5 w-5" />
<span>{t("promotion_label")}</span>
</DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuGroup>
{data.user === null ? (
<Link
to={{
pathname: "login",
search: searchParams.toString(),
}}
onClick={() => setOpen(false)}
>
<button className="relative flex w-full cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors hover:bg-accent focus:bg-accent focus:text-accent-foreground">
<ArrowRightOnRectangleIcon className="mr-2 h-5 w-5" />
<span className="text-green-100">{t("login_label")}</span>
</button>
</Link>
) : (
<Form
action="/logout"
method="post"
onSubmit={() => {
setOpen(false);
// toast({
// description: "Logging out ...",
// });
}}
>
<input type="hidden" name="redirectTo" value={redirectTo} />
<button
type="submit"
className="relative flex w-full cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors hover:bg-accent focus:bg-accent focus:text-accent-foreground"
disabled={isLoggingOut}
>
<ArrowLeftOnRectangleIcon className="mr-2 h-5 w-5" />
<span className="text-red-500">{t("logout_label")}</span>
</button>
</Form>
)}
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
);
}
Loading