Skip to content

Commit

Permalink
made the logged not-logget menu work
Browse files Browse the repository at this point in the history
  • Loading branch information
baufaker committed Apr 10, 2024
1 parent 835d64f commit e96b27b
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 18 deletions.
9 changes: 8 additions & 1 deletion components/header/Drawers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ const Aside = (
);

function Drawers({ menu, searchbar, children, platform }: Props) {
const { displayCart, displayMenu, displaySearchDrawer } = useUI();
const { displayCart, displayMenu, displaySearchDrawer, user } = useUI();

console.log({ userDrawers: user.value });

//if user is not loggedin, use the public navitems in the menu
if (localStorage.getItem("AccessToken") == "") {
menu.items = menu.publicItems || [];
}

return (
<>
Expand Down
41 changes: 34 additions & 7 deletions components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export interface Props {
*/
navItems?: SiteNavigationElement[] | null;

/**
* @title Public Navigation items
* @description Navigation items used both on mobile and desktop menus
*/
publicNavItems?: SiteNavigationElement[] | null;

/** @title Logo */
logo?: Logo;

Expand Down Expand Up @@ -69,6 +75,28 @@ function Header({
url: "/",
},
],
publicNavItems = [
{
"@type": "SiteNavigationElement",
name: "Feminino",
url: "/",
},
{
"@type": "SiteNavigationElement",
name: "Masculino",
url: "/",
},
{
"@type": "SiteNavigationElement",
name: "Sale",
url: "/",
},
{
"@type": "SiteNavigationElement",
name: "Linktree",
url: "/",
},
],
logo = {
src:
"https://ozksgdmyrqcxcwhnbepg.supabase.co/storage/v1/object/public/assets/2291/986b61d4-3847-4867-93c8-b550cb459cc7",
Expand All @@ -82,24 +110,23 @@ function Header({
device,
}: SectionProps<typeof loader>) {
const platform = usePlatform();
const items = navItems ?? [];

return (
<>
<header style={{ height: headerHeight }}>
<Drawers
menu={{ items, logo: logoMenu }}
menu={{
items: navItems || [],
publicItems: publicNavItems ||
[],
logo: logoMenu,
}}
searchbar={searchbar}
platform={platform}
>
<div class="bg-base-100 w-full z-50">
<Navbar
device={device}
items={items}
searchbar={searchbar && { ...searchbar, platform }}
logo={logo}
logoPosition={logoPosition}
buttons={buttons}
/>
</div>
</Drawers>
Expand Down
1 change: 1 addition & 0 deletions components/header/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { SiteNavigationElement } from "apps/commerce/types.ts";

export interface Props {
items: SiteNavigationElement[];
publicItems?: SiteNavigationElement[];
logo?: Logo;
}

Expand Down
10 changes: 1 addition & 9 deletions components/header/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Props as SearchbarProps } from "../../components/search/Searchbar.tsx";
import { MenuButton, SearchButton } from "../../islands/Header/Buttons.tsx";
import { usePlatform } from "../../sdk/usePlatform.tsx";
import type { SiteNavigationElement } from "apps/commerce/types.ts";
import Image from "apps/website/components/Image.tsx";
import NavItem from "./NavItem.tsx";
Expand All @@ -9,17 +8,10 @@ import { Buttons, Logo } from "../../components/header/Header.tsx";

// Make it sure to render it on the server only. DO NOT render it on an island
function Navbar(
{ items, searchbar, logo, buttons, logoPosition = "left", device }: {
items: SiteNavigationElement[];
searchbar?: SearchbarProps;
{ logo }: {
logo?: Logo;
buttons?: Buttons;
logoPosition?: "left" | "center";
device: "mobile" | "desktop" | "tablet";
},
) {
const platform = usePlatform();

return (
<div
style={{ height: navbarHeight }}
Expand Down
16 changes: 15 additions & 1 deletion components/ui/PrivatePageControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Props {
}

function PrivatePageControl(props: Props) {
const { updatedData, uploadedFile } = useUI();
const { updatedData, uploadedFile, user } = useUI();

async function isLogged({ accessToken }: { accessToken: string }) {
if (accessToken === "") {
Expand All @@ -28,10 +28,24 @@ function PrivatePageControl(props: Props) {
}).then((r) => r.json());

const username = response.data.Username;

user.value = {
id: username,
name: response.data.UserAttributes.find((
a: { Name: string; Value: string },
) => a.Name === "name").Value,
email: response.dataProfile.email,
plan: response.dataProfile.plan,
};

console.log({ userhere: user.value });

updatedData.value = response.dataProfile.updatedData;
uploadedFile.value = response.dataProfile.uploadedFile;

if (!username) {
user.value = null;
localStorage.setItem("AccessToken", "");
window.location.href = "/";
}

Expand Down
9 changes: 9 additions & 0 deletions sdk/useUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

import { signal } from "@preact/signals";

export type UserSession = {
id: string;
name: string;
email: string;
plan: string;
};

const displayCart = signal(false);
const displayMenu = signal(false);
const displaySearchPopup = signal(false);
Expand All @@ -16,6 +23,7 @@ const displayConfirmCancelSubscription = signal(false);
const displayPlanLimit = signal(false);
const updatedData = signal(true);
const uploadedFile = signal(true);
const user = signal<UserSession | null>(null);

const state = {
displayCart,
Expand All @@ -29,6 +37,7 @@ const state = {
displayNewTicketModal,
displayConfirmDeleteDoc,
displayConfirmCancelSubscription,
user,
};

// Keyboard event listeners
Expand Down

0 comments on commit e96b27b

Please sign in to comment.