Skip to content

Commit

Permalink
fix: mobile view login button (#230)
Browse files Browse the repository at this point in the history
conditionally render login / write review depending on login status of user
  • Loading branch information
AlvinLingg authored Aug 27, 2024
1 parent cd3b1df commit f33445f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
11 changes: 8 additions & 3 deletions src/common/components/CoreLayout/CoreLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { type PropsWithChildren } from "react";
import { Sidebar } from "../Sidebar";
import { MobileHeader } from "@/common/components/MobileHeader";
import { getServerAuthSession } from "@/server/auth";

interface CoreLayoutProps extends PropsWithChildren {}

export const CoreLayout = ({ children }: CoreLayoutProps) => {
export async function CoreLayout({ children }: CoreLayoutProps) {
const session = await getServerAuthSession();
return (
<div className="flex h-dvh flex-col">
<MobileHeader className="flex-shrink-0 sm:hidden" />
<MobileHeader
className="flex-shrink-0 sm:hidden"
isLoggedIn={!!session}
/>
<div className="flex flex-1 overflow-hidden">
<aside className="relative hidden shrink-0 overflow-y-auto border-r border-border-default bg-surface-base sm:block">
<Sidebar />
Expand All @@ -18,4 +23,4 @@ export const CoreLayout = ({ children }: CoreLayoutProps) => {
</div>
</div>
);
};
}
37 changes: 25 additions & 12 deletions src/common/components/MobileHeader/MobileHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"use client";

import { Button } from "@/common/components/Button";
import { AfterclassIcon } from "@/common/components/CustomIcon";
import { AfterclassIcon, PlusIcon } from "@/common/components/CustomIcon";
import { Sidebar } from "@/common/components/Sidebar";
import { cn } from "@/common/functions";
import { Icon } from "@iconify-icon/react";
import Link from "next/link";
import { useState, type ComponentPropsWithoutRef } from "react";

export interface MobileHeaderProps extends ComponentPropsWithoutRef<"header"> {}
export interface MobileHeaderProps extends ComponentPropsWithoutRef<"header"> {
isLoggedIn: boolean;
}

export const MobileHeader = ({ ...props }: MobileHeaderProps) => {
export const MobileHeader = ({ isLoggedIn, ...props }: MobileHeaderProps) => {
const [isSidebarOpen, setIsSidebarOpen] = useState(false);
return (
<>
Expand Down Expand Up @@ -45,15 +47,26 @@ export const MobileHeader = ({ ...props }: MobileHeaderProps) => {
/>
</button>

{/* TODO: Add logged in state */}
<Button
variant="secondary"
size="sm"
as="a"
href="/account/auth/login"
>
Login
</Button>
{isLoggedIn ? (
<Button
variant="secondary"
size="sm"
as="a"
href="/submit"
iconLeft={<PlusIcon />}
>
Write a review
</Button>
) : (
<Button
variant="secondary"
size="sm"
as="a"
href="/account/auth/login"
>
Login
</Button>
)}
</div>
</header>

Expand Down

0 comments on commit f33445f

Please sign in to comment.