Skip to content

Commit

Permalink
add profile layout in header
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartaithan committed May 13, 2023
1 parent 1900bb5 commit 8835633
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 16 deletions.
7 changes: 5 additions & 2 deletions components/BoardColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ interface IBoardColumnProps {
}

const useStyles = createStyles(
({ radius, colors, spacing }, { column }: { column: BOARD_COLUMNS }) => {
(
{ radius, colors, spacing, fontSizes },
{ column }: { column: BOARD_COLUMNS }
) => {
const { color, shade } = columnColors[column];
return {
column: {
Expand Down Expand Up @@ -57,7 +60,7 @@ const useStyles = createStyles(
},
label: {
color: colors.secondary[9],
fontSize: 14,
fontSize: fontSizes.sm,
":before": {
content: "''",
width: 8,
Expand Down
39 changes: 36 additions & 3 deletions components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { type IHeaderLink } from "@/models/LinkModel";
import { useProfiles } from "@/providers/ProfileProvider";
import {
Container,
Flex,
Header as MantineHeader,
Title,
createStyles,
UnstyledButton,
Badge,
Button,
} from "@mantine/core";
import Image from "next/image";
import Link from "next/link";
import { useRouter } from "next/router";
import { type FC } from "react";
import { User } from "tabler-icons-react";

const HEADER_HEIGHT = 64;
const HEADER_HEIGHT = 48;

const links: IHeaderLink[] = [
{
Expand All @@ -33,7 +39,7 @@ const links: IHeaderLink[] = [
},
];

const useStyles = createStyles(({ colors, spacing, radius }) => ({
const useStyles = createStyles(({ colors, spacing, radius, fontSizes }) => ({
root: {
width: "100%",
minHeight: HEADER_HEIGHT,
Expand All @@ -52,6 +58,7 @@ const useStyles = createStyles(({ colors, spacing, radius }) => ({
gap: spacing.xs,
},
link: {
fontSize: fontSizes.sm,
fontWeight: 500,
textDecoration: "none",
padding: "2px 8px",
Expand All @@ -76,6 +83,7 @@ const useStyles = createStyles(({ colors, spacing, radius }) => ({
const Header: FC = () => {
const { classes, cx } = useStyles();
const { pathname } = useRouter();
const { psn, isAuth } = useProfiles();

return (
<MantineHeader className={classes.root} height={HEADER_HEIGHT}>
Expand All @@ -100,7 +108,32 @@ const Header: FC = () => {
);
})}
</Flex>
<Flex className={classes.profile}>Profile</Flex>
{isAuth && (
<UnstyledButton className={classes.profile}>
<Badge mr="sm" radius="sm">
{psn?.onlineId ?? "[Not Found]"}
</Badge>
<Image
width={30}
height={30}
src={psn?.avatarUrls[0].avatarUrl ?? ""}
alt="avatar"
/>
</UnstyledButton>
)}
{!isAuth && (
<Link href="/signIn" passHref>
<Button
size="xs"
leftIcon={<User size="0.75rem" />}
variant="light"
compact
component="a"
>
Sign in
</Button>
</Link>
)}
</Container>
</MantineHeader>
);
Expand Down
6 changes: 3 additions & 3 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useSession } from "@supabase/auth-helpers-react";

const Home: IPage = () => {
const session = useSession();
const { profiles, updatePSNProfile } = useProfiles();
const { profile, psn, updatePSNProfile } = useProfiles();

return (
<Flex
Expand Down Expand Up @@ -33,15 +33,15 @@ const Home: IPage = () => {
size={8}
style={{ whiteSpace: "break-spaces", wordBreak: "break-all" }}
>
profile: {JSON.stringify(profiles.profile, null, 2)}
profile: {JSON.stringify(profile, null, 2)}
</Text>
<Text
component="pre"
w={400}
size={8}
style={{ whiteSpace: "break-spaces", wordBreak: "break-all" }}
>
psn_profile: {JSON.stringify(profiles.psn, null, 2)}
psn_profile: {JSON.stringify(psn, null, 2)}
</Text>
</Group>
</Flex>
Expand Down
13 changes: 9 additions & 4 deletions providers/ProfileProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
type NullableProfile,
type NullablePSNProfile,
} from "@/models/AuthModel";
import { useUser } from "@supabase/auth-helpers-react";
import {
type FC,
type PropsWithChildren,
Expand All @@ -21,13 +22,15 @@ interface IProfilesState {
profile: NullableProfile;
}

interface IProfileContext {
profiles: IProfilesState;
interface IProfileContext extends IProfilesState {
isAuth: boolean;
updatePSNProfile: () => void;
}

const initialContextValue: IProfileContext = {
profiles: { psn: null, profile: null },
psn: null,
profile: null,
isAuth: false,
updatePSNProfile: () => null,
};

Expand All @@ -40,6 +43,7 @@ const ProfileProvider: FC<IProfileProvider> = (props) => {
profile: initialProfile ?? null,
};
const [profiles, setProfiles] = useState<IProfilesState>(initialProfiles);
const user = useUser();

const updatePSNProfile = (): void => {
API.get("/auth/profile")
Expand All @@ -53,7 +57,8 @@ const ProfileProvider: FC<IProfileProvider> = (props) => {
};

const exposed: IProfileContext = {
profiles,
...profiles,
isAuth: profiles.psn !== null && user !== null,
updatePSNProfile,
};

Expand Down
8 changes: 4 additions & 4 deletions styles/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ const ModalStyles: (
theme: MantineTheme,
params: unknown,
context: ContextStylesParams
) => Record<string, CSSObject> = ({ radius }) => ({
) => Record<string, CSSObject> = ({ radius, fontSizes }) => ({
content: {
borderRadius: radius.lg,
},
title: {
fontSize: 14,
fontSize: fontSizes.sm,
fontWeight: 500,
},
});

const BadgeStyles: BadgeProps["styles"] = () => ({
const BadgeStyles: BadgeProps["styles"] = ({ fontSizes }) => ({
root: {
padding: "2px 6px",
fontSize: 12,
fontSize: fontSizes.xs,
fontWeight: 500,
textTransform: "unset",
},
Expand Down

0 comments on commit 8835633

Please sign in to comment.