-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
draft(react): react + vite integration
- Loading branch information
1 parent
7bd95b0
commit a03b362
Showing
22 changed files
with
3,431 additions
and
239 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
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,12 @@ | ||
import * as React from "react"; | ||
import { useState } from "react"; | ||
import { CharacterList } from "./pages/CharacterList"; | ||
|
||
function App() { | ||
// In a full application, this would probably be the page router, but for now | ||
// we'll just abstract it as a simple component call | ||
|
||
return <CharacterList />; | ||
} | ||
|
||
export default App; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 * as React from "react"; | ||
|
||
export function Button({ children, onClick, href }: any) { | ||
if (href) { | ||
<a href={href}>{children}</a>; | ||
} | ||
|
||
return <button onClick={onClick}>{children}</button>; | ||
} |
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,37 @@ | ||
import * as React from "react"; | ||
|
||
function NavLink({ href, children }: any) { | ||
return ( | ||
<li className="text-zinc-100"> | ||
<a href={href}>{children}</a> | ||
</li> | ||
); | ||
} | ||
|
||
export function Header() { | ||
return ( | ||
<nav className="bg-zinc-900 flex justify-between px-4 py-3 border-b-[1px] border-zinc-400"> | ||
<div className="shrink-0 pr-2"> | ||
<a href="/"> | ||
<img | ||
src="/images/logo.png" | ||
style={{ | ||
height: 50, | ||
width: 282, | ||
}} | ||
alt="Wanderer's Guide" | ||
></img> | ||
</a> | ||
</div> | ||
<ul className="flex gap-6 items-center"> | ||
<NavLink>Home</NavLink> | ||
<NavLink>Characters</NavLink> | ||
<NavLink>Builds</NavLink> | ||
<NavLink>Homebrew</NavLink> | ||
<NavLink>GM Tools</NavLink> | ||
<NavLink>Browse</NavLink> | ||
<NavLink>Profile</NavLink> | ||
</ul> | ||
</nav> | ||
); | ||
} |
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 @@ | ||
export * from "./Header"; |
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,7 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
.test { | ||
color: black; | ||
} |
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,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
<title>Wanderer's Guide</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
|
||
<script type="module"> | ||
import RefreshRuntime from "http://localhost:5173/@react-refresh"; | ||
RefreshRuntime.injectIntoGlobalHook(window); | ||
window.$RefreshReg$ = () => {}; | ||
window.$RefreshSig$ = () => (type) => type; | ||
window.__vite_plugin_react_preamble_installed__ = true; | ||
</script> | ||
<script type="module" src="http://localhost:5173/@vite/client"></script> | ||
<script type="module" src="http://localhost:5173/app/main.tsx"></script> | ||
</body> | ||
</html> |
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,12 @@ | ||
import "vite/modulepreload-polyfill"; | ||
|
||
import React from "react"; | ||
import ReactDOM from "react-dom/client"; | ||
import App from "./App"; | ||
import "./index.css"; | ||
|
||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
); |
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,73 @@ | ||
import * as React from "react"; | ||
import { Header } from "../../components"; | ||
import { CharacterCard } from "./components/CharacterCard"; | ||
import { UserPlusIcon, ArrowUpTrayIcon } from "@heroicons/react/24/solid"; | ||
|
||
export function CharacterList() { | ||
const [state, setState] = React.useState<any>({ | ||
status: "idle", | ||
characters: [], | ||
}); | ||
|
||
console.log("satte: ", state); | ||
|
||
React.useEffect(() => { | ||
setState({ | ||
...state, | ||
status: "loading", | ||
}); | ||
|
||
fetch("/api/profile/characters") | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
console.log("data: ", data); | ||
setState({ | ||
...state, | ||
status: "success", | ||
characters: data, | ||
}); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<div className="bg-zinc-900 h-full min-h-screen px-4 text-zinc-200"> | ||
<Header /> | ||
|
||
<main> | ||
<section className="flex justify-between border-b border-zinc-600 items-center py-3"> | ||
<h1 className="text-3xl">Characters</h1> | ||
|
||
<div className="flex gap-2"> | ||
<a | ||
className="is-size-3 is-pulled-right" | ||
href="/profile/characters/add" | ||
> | ||
<UserPlusIcon height={32} /> | ||
</a> | ||
<button> | ||
<ArrowUpTrayIcon height={32} /> | ||
</button> | ||
</div> | ||
</section> | ||
|
||
<section> | ||
{state.status === "loading" && <div>Loading...</div>} | ||
|
||
{state.status === "success" && state.characters.length === 0 && ( | ||
<div>No characters found</div> | ||
)} | ||
|
||
{state.status === "success" && state.characters.length > 0 && ( | ||
<div className="flex flex-wrap gap-3 py-4"> | ||
{state.characters.map((character: any) => { | ||
return ( | ||
<CharacterCard key={character.id} character={character} /> | ||
); | ||
})} | ||
</div> | ||
)} | ||
</section> | ||
</main> | ||
</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,80 @@ | ||
import * as React from "react"; | ||
import { | ||
PencilIcon, | ||
WrenchIcon, | ||
EllipsisHorizontalIcon, | ||
TrashIcon, | ||
} from "@heroicons/react/24/solid"; | ||
|
||
function CardTab({ href, onClick, children }: any) { | ||
if (href) { | ||
return ( | ||
<a | ||
href={href} | ||
className="flex justify-center flex-1 py-2 px-4 hover:bg-zinc-700" | ||
> | ||
{children} | ||
</a> | ||
); | ||
} | ||
|
||
return ( | ||
<button | ||
onClick={onClick} | ||
className="flex justify-center flex-1 py-2 px-4 hover:bg-zinc-700" | ||
> | ||
{children} | ||
</button> | ||
); | ||
} | ||
|
||
export function CharacterCard({ character }: any) { | ||
return ( | ||
<div className="w-full sm:max-w-[300px] bg-neutral-800"> | ||
<a | ||
href={`/profile/characters/${character.id}`} | ||
className="flex flex-col p-4 gap-3 hover:bg-zinc-700" | ||
> | ||
<p className="text-xl">{character.name}</p> | ||
<div className="flex items-center gap-2 text-opacity-75 text-sm"> | ||
<p>Lvl {character.level}</p> | ||
{character.heritageName && ( | ||
<> | ||
<span>|</span> | ||
<p>{character.heritageName}</p> | ||
</> | ||
)} | ||
{character.className && ( | ||
<> | ||
<span>|</span> | ||
<p>{character.className}</p> | ||
</> | ||
)} | ||
</div> | ||
</a> | ||
<div className="flex bg-neutral-800 border-t border-zinc-700"> | ||
<CardTab | ||
href={`/profile/characters/builder/basics/?id=${character.id}`} | ||
> | ||
{character.isPlayable ? ( | ||
<span className="flex gap-2 items-center"> | ||
<p className="text-sm">Edit</p> | ||
<PencilIcon height={16} /> | ||
</span> | ||
) : ( | ||
<span className="flex gap-2 items-center"> | ||
<p className="text-sm">Continue</p> | ||
<WrenchIcon height={16} /> | ||
</span> | ||
)} | ||
</CardTab> | ||
<CardTab onClick={() => {}}> | ||
<EllipsisHorizontalIcon height={16} /> | ||
</CardTab> | ||
<CardTab onClick={() => {}}> | ||
<TrashIcon height={16} /> | ||
</CardTab> | ||
</div> | ||
</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 @@ | ||
export * from "./CharacterListPage"; |
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 @@ | ||
/// <reference types="vite/client" /> |
Oops, something went wrong.