-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Subject: added display name to SidePanel
- Loading branch information
Man Luu
authored and
Man Luu
committed
Mar 16, 2024
1 parent
edaf332
commit bcd5474
Showing
7 changed files
with
100 additions
and
100 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 |
---|---|---|
@@ -1,45 +1,63 @@ | ||
import { Link } from '@remix-run/react'; | ||
import { Link } from "@remix-run/react"; | ||
|
||
import { useTheme } from '~/utils/Navbar/ThemeProvider'; | ||
|
||
import type { ContextProps } from '../utils/types/ContextProps.type'; | ||
import { useTheme } from "~/utils/Navbar/ThemeProvider"; | ||
|
||
import type { ContextProps } from "../utils/types/ContextProps.type"; | ||
|
||
type Props = { | ||
sidePanelIsShown: boolean; | ||
setSidePanelIsShown: React.Dispatch<React.SetStateAction<boolean>>; | ||
user: ContextProps["user"]; | ||
supabase: ContextProps["supabase"] | ||
supabase: ContextProps["supabase"]; | ||
}; | ||
|
||
export default function SidePanel( | ||
{sidePanelIsShown, setSidePanelIsShown, user, supabase} | ||
: Props){ | ||
export default function SidePanel({ | ||
sidePanelIsShown, | ||
setSidePanelIsShown, | ||
user, | ||
supabase, | ||
}: Props) { | ||
const [theme, setTheme] = useTheme(); | ||
const toggleTheme = () => { | ||
setTheme((prevTheme) => (prevTheme === "light" ? "dark" : "light")); | ||
}; | ||
|
||
const logout = async () => { | ||
const {error} = await supabase.auth.signOut(); | ||
const { error } = await supabase.auth.signOut(); | ||
if (error) alert("Error while logging out."); | ||
} | ||
|
||
return <div | ||
className={(sidePanelIsShown ? "right-0" : "-right-96") + | ||
` fixed h-screen transition-[right] ease-in-out duration-500 | ||
w-96 max-w-full bg-gray-800 flex flex-col items-center` | ||
}> | ||
<button className='btn' | ||
onClick={()=>setSidePanelIsShown(false)}>CLOSE</button> | ||
<button className='btn' onClick={toggleTheme}>Theme: {theme}</button> | ||
|
||
{user? <div className='flex flex-col mt-12'> | ||
<p>Logged in as {user.email}</p> | ||
<button className='btn' onClick={logout}>Log out</button> | ||
</div> : <Link to="/login"> | ||
<button className='btn'>Login</button> | ||
</Link>} | ||
|
||
</div> | ||
} | ||
}; | ||
|
||
// TEST // | ||
console.log(user); | ||
// TEST // | ||
|
||
return ( | ||
<div | ||
className={ | ||
(sidePanelIsShown ? "right-0" : "-right-96") + | ||
` fixed flex h-screen w-96 max-w-full | ||
flex-col items-center bg-gray-800 transition-[right] duration-500 ease-in-out` | ||
} | ||
> | ||
<button className="btn" onClick={() => setSidePanelIsShown(false)}> | ||
CLOSE | ||
</button> | ||
<button className="btn" onClick={toggleTheme}> | ||
Theme: {theme} | ||
</button> | ||
|
||
{user ? ( | ||
<div className="mt-12 flex flex-col"> | ||
<p>Logged in as {user.user_metadata.full_name}!</p> | ||
<button className="btn" onClick={logout}> | ||
Log out | ||
</button> | ||
</div> | ||
) : ( | ||
<Link to="/login"> | ||
<button className="btn">Login</button> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ export default function LoginForm({ | |
}) { | ||
const fillDemoAcc = () => { | ||
setEmail("[email protected]"); | ||
setPassword("123+Ab"); | ||
setPassword("Test!123"); | ||
}; | ||
|
||
return ( | ||
|
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,9 @@ | ||
import { useOutletContext } from "@remix-run/react"; | ||
|
||
export default function testRouteInner() { | ||
const { parentState } = useOutletContext<{ parentState: boolean }>(); | ||
|
||
if (!parentState) return; | ||
|
||
return <div> Test Router Inner </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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Outlet } from "@remix-run/react"; | ||
import { useState } from "react"; | ||
|
||
export default function testRoute() { | ||
const [parentState, setParentState] = useState<boolean>(false); | ||
|
||
return ( | ||
<div> | ||
Test Route | ||
<button | ||
onClick={() => { | ||
setParentState(!parentState); | ||
}} | ||
> | ||
{" "} | ||
Click here{" "} | ||
</button> | ||
<Outlet context={{ parentState }} /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
import {describe, it, expect} from "vitest" | ||
import {render, screen} from '@testing-library/react' | ||
import {userEvent} from "@testing-library/user-event" | ||
import "@testing-library/jest-dom" | ||
import { describe, it, expect } from "vitest"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { userEvent } from "@testing-library/user-event"; | ||
import "@testing-library/jest-dom"; | ||
|
||
import Index from '../routes/_index'; | ||
import Index from "../routes/_index"; | ||
|
||
|
||
describe('App', () => { | ||
|
||
it('clicks to change text', async () => { | ||
describe("App", () => { | ||
it("clicks to change text", async () => { | ||
// ARRANGE | ||
render(<Index/>) | ||
render(<Index />); | ||
|
||
// ACT | ||
await userEvent.click(screen.getByText('click here')) | ||
await screen.findByRole('heading') | ||
|
||
// ASSERT | ||
expect(screen.getByRole('heading')).toHaveTextContent("done") | ||
}) | ||
await userEvent.click(screen.getByText("click here")); | ||
await screen.findByRole("heading"); | ||
|
||
}) | ||
// ASSERT | ||
expect(screen.getByRole("heading")).toHaveTextContent("done"); | ||
}); | ||
}); |
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,51 +0,0 @@ | ||
export type Json = | ||
| string | ||
| number | ||
| boolean | ||
| null | ||
| { [key: string]: Json | undefined } | ||
| Json[] | ||
|
||
export interface Database { | ||
public: { | ||
Tables: { | ||
profiles: { | ||
Row: { | ||
created_at: string | ||
id: string | ||
username: string | null | ||
} | ||
Insert: { | ||
created_at?: string | ||
id: string | ||
username?: string | null | ||
} | ||
Update: { | ||
created_at?: string | ||
id?: string | ||
username?: string | null | ||
} | ||
Relationships: [ | ||
{ | ||
foreignKeyName: "profiles_id_fkey" | ||
columns: ["id"] | ||
referencedRelation: "users" | ||
referencedColumns: ["id"] | ||
} | ||
] | ||
} | ||
} | ||
Views: { | ||
[_ in never]: never | ||
} | ||
Functions: { | ||
[_ in never]: never | ||
} | ||
Enums: { | ||
[_ in never]: never | ||
} | ||
CompositeTypes: { | ||
[_ in never]: never | ||
} | ||
} | ||
} | ||