Skip to content

Commit

Permalink
Add moving background to FE's layout (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
sasalatart authored Sep 25, 2024
1 parent f971955 commit d8e0a26
Show file tree
Hide file tree
Showing 9 changed files with 1,011 additions and 798 deletions.
7 changes: 5 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"@heroicons/react": "^2.1.3",
"@react-three/fiber": "^8.17.8",
"@supabase/auth-ui-react": "^0.4.7",
"@supabase/auth-ui-shared": "^0.1.8",
"@supabase/supabase-js": "^2.43.1",
Expand All @@ -25,14 +26,16 @@
"react-dom": "^18.2.0",
"react-hook-form": "^7.51.4",
"react-query": "^3.39.3",
"react-router-dom": "^6.23.1"
"react-router-dom": "^6.23.1",
"three": "^0.168.0"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.13.4",
"@tailwindcss/typography": "^0.5.13",
"@types/lodash": "^4.17.4",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@types/three": "^0.168.0",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react": "^4.2.1",
Expand All @@ -45,7 +48,7 @@
"postcss": "^8.4.38",
"prettier": "3.2.5",
"tailwindcss": "^3.4.3",
"typescript": "^5.2.2",
"typescript": "5.5.4",
"vite": "^5.2.0"
}
}
1,684 changes: 923 additions & 761 deletions client/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/src/layout/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GITHUB_USER_LINK, GITHUB_REPO_LINK } from '@/config';

export function Footer(): JSX.Element {
return (
<footer className="footer footer-center p-4 bg-base-300 text-base-content">
<footer className="footer footer-center p-4 bg-base-300 text-base-content opacity-85">
<aside>
<p>
<a href={GITHUB_USER_LINK} target="_blank" className="link">
Expand Down
3 changes: 2 additions & 1 deletion client/src/layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { Layout } from './layout';
export { CenteredSpinner, InlineSpinner } from './spinner';
export { Layout } from './layout';
export { Pagination } from './pagination';
export { QuestionBadges } from './question-badges';
export { WithSkybox } from './skybox';
5 changes: 3 additions & 2 deletions client/src/layout/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Outlet } from 'react-router-dom';
import { Navbar } from './navbar';
import { Footer } from './footer';
import { WithSkybox } from './skybox';

export function Layout(): JSX.Element {
return (
<div className="bg-primary h-screen flex flex-col">
<WithSkybox>
<Navbar />
<div className="container m-auto">
<div className="m-4">
<Outlet />
</div>
</div>
<Footer />
</div>
</WithSkybox>
);
}
2 changes: 1 addition & 1 deletion client/src/layout/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function Navbar(): JSX.Element {
const { handleLogOut, isLoggingOut } = useContext(SessionContext);

return (
<div className="navbar bg-base-100">
<div className="navbar bg-base-100 opacity-85">
<div className="navbar-start">
<div className="dropdown">
<div tabIndex={0} role="button" className="btn btn-ghost lg:hidden">
Expand Down
40 changes: 40 additions & 0 deletions client/src/layout/skybox/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useRef } from 'react';
import { Canvas, useFrame, useLoader } from '@react-three/fiber';
import * as THREE from 'three';
import skyboxImage from './skybox.jpg';

interface Props {
children: React.ReactNode;
}

export function WithSkybox({ children }: Props): JSX.Element {
return (
<div className="h-screen">
<Canvas
className="absolute top-0 left-0 w-full h-full z-0"
camera={{ position: [0, 0, 0.1], fov: 75, near: 0.1 }}
>
<Skybox />
</Canvas>
<div className="absolute top-0 left-0 w-full h-full flex flex-col z-1">{children}</div>
</div>
);
}

function Skybox(): JSX.Element {
const sphereRef = useRef<THREE.Mesh>(null);
const texture = useLoader(THREE.TextureLoader, skyboxImage);

useFrame(() => {
if (sphereRef.current) {
sphereRef.current.rotation.y += 0.00033; // Adjust the speed as needed
}
});

return (
<mesh ref={sphereRef}>
<sphereGeometry args={[500, 60, 40]} />
<meshBasicMaterial map={texture} side={THREE.BackSide} />
</mesh>
);
}
Binary file added client/src/layout/skybox/skybox.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 36 additions & 30 deletions client/src/screens/login/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,46 @@ import { ThemeSupa } from '@supabase/auth-ui-shared';
import { supabase } from '@/supabase';
import { GITHUB_USER_LINK, GITHUB_REPO_LINK } from '@/config';
import { NapoleonicHatIcon } from '@/icons';
import { WithSkybox } from '@/layout';

export function Login(): JSX.Element {
return (
<div className="h-screen flex flex-col justify-center">
<div className="flex flex-col items-center space-y-2">
<NapoleonicHatIcon height={160} width={200} />
<h1 className="text-2xl font-bold tracking-tight">Quizory</h1>
<h2 className="text-xl text-center">
LLM-generated questions to challenge your knowledge!
</h2>
</div>
<div className="mx-auto mt-4">
<Auth
supabaseClient={supabase}
providers={['google']}
appearance={{ theme: ThemeSupa }}
onlyThirdPartyProviders
/>
</div>
<WithSkybox>
<div className="h-full flex flex-col items-center justify-center">
<div className="card bg-neutral shadow-xl flex flex-col items-center space-y-2 p-8 mx-4 opacity-90">
<NapoleonicHatIcon height={160} width={200} />

<h1 className="text-2xl font-bold tracking-tight">Quizory</h1>

<h2 className="text-xl text-center">
LLM-generated questions to challenge your knowledge!
</h2>

<div className="mx-auto mt-4">
<Auth
supabaseClient={supabase}
providers={['google']}
appearance={{ theme: ThemeSupa }}
onlyThirdPartyProviders
/>
</div>

<div className="flex flex-col items-center mt-4">
<p>
Created by Sebastián Salata R-T{' '}
<a href={GITHUB_USER_LINK} target="_blank" className="link">
(sasalatart)
</a>
</p>
<p>
See code on{' '}
<a href={GITHUB_REPO_LINK} target="_blank" className="link">
GitHub
</a>
</p>
<div className="flex flex-col items-center mt-4">
<p>
Created by Sebastián Salata R-T{' '}
<a href={GITHUB_USER_LINK} target="_blank" className="link">
(sasalatart)
</a>
</p>
<p>
See code on{' '}
<a href={GITHUB_REPO_LINK} target="_blank" className="link">
GitHub
</a>
</p>
</div>
</div>
</div>
</div>
</WithSkybox>
);
}

0 comments on commit d8e0a26

Please sign in to comment.