initial commit
This commit is contained in:
commit
33aaf78f7d
20 changed files with 433 additions and 0 deletions
28
.gitignore
vendored
Normal file
28
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
dist
|
||||
.wrangler
|
||||
.output
|
||||
.vercel
|
||||
.netlify
|
||||
.vinxi
|
||||
app.config.timestamp_*.js
|
||||
|
||||
# Environment
|
||||
.env
|
||||
.env*.local
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
*.launch
|
||||
.settings/
|
||||
|
||||
# Temp
|
||||
gitignore
|
||||
|
||||
# System Files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
32
README.md
Normal file
32
README.md
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# SolidStart
|
||||
|
||||
Everything you need to build a Solid project, powered by [`solid-start`](https://start.solidjs.com);
|
||||
|
||||
## Creating a project
|
||||
|
||||
```bash
|
||||
# create a new project in the current directory
|
||||
npm init solid@latest
|
||||
|
||||
# create a new project in my-app
|
||||
npm init solid@latest my-app
|
||||
```
|
||||
|
||||
## Developing
|
||||
|
||||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
|
||||
# or start the server and open the app in a new browser tab
|
||||
npm run dev -- --open
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
Solid apps are built with _presets_, which optimise your project for deployment to different environments.
|
||||
|
||||
By default, `npm run build` will generate a Node app that you can run with `npm start`. To use a different preset, add it to the `devDependencies` in `package.json` and specify in your `app.config.js`.
|
||||
|
||||
## This project was created with the [Solid CLI](https://github.com/solidjs-community/solid-cli)
|
||||
3
app.config.ts
Normal file
3
app.config.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import { defineConfig } from "@solidjs/start/config";
|
||||
|
||||
export default defineConfig({});
|
||||
BIN
bun.lockb
Normal file
BIN
bun.lockb
Normal file
Binary file not shown.
25
package.json
Normal file
25
package.json
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "example-basic",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vinxi dev",
|
||||
"build": "vinxi build",
|
||||
"start": "vinxi start",
|
||||
"version": "vinxi version"
|
||||
},
|
||||
"dependencies": {
|
||||
"@solid-primitives/context": "^0.3.2",
|
||||
"@solid-primitives/event-listener": "^2.4.3",
|
||||
"@solidjs/meta": "^0.29.4",
|
||||
"@solidjs/router": "^0.15.0",
|
||||
"@solidjs/start": "^1.1.0",
|
||||
"better-auth": "^1.3.11",
|
||||
"open-props": "^1.7.16",
|
||||
"solid-icons": "^1.1.0",
|
||||
"solid-js": "^1.9.5",
|
||||
"vinxi": "^0.5.7"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
}
|
||||
}
|
||||
BIN
public/favicon.ico
Normal file
BIN
public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 664 B |
23
src/app.tsx
Normal file
23
src/app.tsx
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { MetaProvider, Title } from "@solidjs/meta";
|
||||
import { Router } from "@solidjs/router";
|
||||
import { FileRoutes } from "@solidjs/start/router";
|
||||
import { Suspense } from "solid-js";
|
||||
import { ThemeContextProvider } from "./features/theme";
|
||||
import "./app.css";
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<Router
|
||||
root={(props) => (
|
||||
<MetaProvider>
|
||||
<Title>Amarth Portal</Title>
|
||||
<Suspense>
|
||||
<ThemeContextProvider>{props.children}</ThemeContextProvider>
|
||||
</Suspense>
|
||||
</MetaProvider>
|
||||
)}
|
||||
>
|
||||
<FileRoutes />
|
||||
</Router>
|
||||
);
|
||||
}
|
||||
21
src/components/Counter.css
Normal file
21
src/components/Counter.css
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
.increment {
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
padding: 1em 2em;
|
||||
color: #335d92;
|
||||
background-color: rgba(68, 107, 158, 0.1);
|
||||
border-radius: 2em;
|
||||
border: 2px solid rgba(68, 107, 158, 0);
|
||||
outline: none;
|
||||
width: 200px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.increment:focus {
|
||||
border: 2px solid #335d92;
|
||||
}
|
||||
|
||||
.increment:active {
|
||||
background-color: rgba(68, 107, 158, 0.2);
|
||||
}
|
||||
11
src/components/Counter.tsx
Normal file
11
src/components/Counter.tsx
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { createSignal } from "solid-js";
|
||||
import "./Counter.css";
|
||||
|
||||
export default function Counter() {
|
||||
const [count, setCount] = createSignal(0);
|
||||
return (
|
||||
<button class="increment" onClick={() => setCount(count() + 1)} type="button">
|
||||
Clicks: {count()}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
4
src/entry-client.tsx
Normal file
4
src/entry-client.tsx
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// @refresh reload
|
||||
import { mount, StartClient } from "@solidjs/start/client";
|
||||
|
||||
mount(() => <StartClient />, document.getElementById("app")!);
|
||||
21
src/entry-server.tsx
Normal file
21
src/entry-server.tsx
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// @refresh reload
|
||||
import { createHandler, StartServer } from "@solidjs/start/server";
|
||||
|
||||
export default createHandler(() => (
|
||||
<StartServer
|
||||
document={({ assets, children, scripts }) => (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
{assets}
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">{children}</div>
|
||||
{scripts}
|
||||
</body>
|
||||
</html>
|
||||
)}
|
||||
/>
|
||||
));
|
||||
88
src/features/theme/context.ts
Normal file
88
src/features/theme/context.ts
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
import {
|
||||
ContextProviderProps,
|
||||
createContextProvider,
|
||||
} from "@solid-primitives/context";
|
||||
import { action, createAsyncStore, query, useAction } from "@solidjs/router";
|
||||
import { createStore } from "solid-js/store";
|
||||
import { useSession } from "vinxi/http";
|
||||
|
||||
export enum ColorScheme {
|
||||
Auto = "light dark",
|
||||
Light = "light",
|
||||
Dark = "dark",
|
||||
}
|
||||
|
||||
export interface State {
|
||||
colorScheme: ColorScheme;
|
||||
hue: number;
|
||||
}
|
||||
|
||||
const getSession = async () => {
|
||||
"use server";
|
||||
|
||||
return useSession<State>({
|
||||
password: process.env.SESSION_SECRET!,
|
||||
});
|
||||
};
|
||||
|
||||
export const getState = query(async () => {
|
||||
"use server";
|
||||
|
||||
const session = await getSession();
|
||||
|
||||
if (Object.getOwnPropertyNames(session.data).length === 0) {
|
||||
await session.update({
|
||||
colorScheme: ColorScheme.Auto,
|
||||
hue: 0,
|
||||
});
|
||||
}
|
||||
|
||||
return session.data;
|
||||
}, "color-scheme");
|
||||
|
||||
const setState = action(async (state: State) => {
|
||||
"use server";
|
||||
|
||||
const session = await getSession();
|
||||
await session.update((prev) => ({ ...prev, ...state }));
|
||||
}, "color-scheme");
|
||||
|
||||
interface ThemeContextType {
|
||||
readonly theme: State;
|
||||
setColorScheme(colorScheme: ColorScheme): void;
|
||||
setHue(colorScheme: number): void;
|
||||
}
|
||||
|
||||
const [ThemeContextProvider, useTheme] = createContextProvider<
|
||||
ThemeContextType,
|
||||
ContextProviderProps
|
||||
>(
|
||||
(props) => {
|
||||
const updateState = useAction(setState);
|
||||
const state = createAsyncStore(() => getState());
|
||||
|
||||
return {
|
||||
get theme() {
|
||||
return state.latest ?? { colorScheme: null };
|
||||
},
|
||||
|
||||
setColorScheme(colorScheme) {
|
||||
// updateState({ colorScheme, hue: state.latest!.hue });
|
||||
},
|
||||
setHue(hue) {
|
||||
// updateState({ hue, colorScheme: state.latest!.colorScheme });
|
||||
},
|
||||
};
|
||||
},
|
||||
{
|
||||
theme: {
|
||||
colorScheme: ColorScheme.Auto,
|
||||
hue: 180,
|
||||
},
|
||||
|
||||
setColorScheme(colorScheme) {},
|
||||
setHue(hue) {},
|
||||
},
|
||||
);
|
||||
|
||||
export { ThemeContextProvider, useTheme };
|
||||
4
src/features/theme/index.ts
Normal file
4
src/features/theme/index.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
|
||||
export { ThemeContextProvider, useTheme } from './context';
|
||||
export { ColorSchemePicker } from './picker';
|
||||
9
src/features/theme/picker.module.css
Normal file
9
src/features/theme/picker.module.css
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
.picker {
|
||||
grid-template-columns: auto 1fr;
|
||||
}
|
||||
|
||||
.hue {
|
||||
display: flex;
|
||||
flex-flow: row;
|
||||
align-items: center;
|
||||
}
|
||||
69
src/features/theme/picker.tsx
Normal file
69
src/features/theme/picker.tsx
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import {
|
||||
WiMoonAltFirstQuarter,
|
||||
WiMoonAltFull,
|
||||
WiMoonAltNew,
|
||||
} from "solid-icons/wi";
|
||||
import {
|
||||
Component,
|
||||
createEffect,
|
||||
For,
|
||||
Match,
|
||||
on,
|
||||
Setter,
|
||||
Switch,
|
||||
} from "solid-js";
|
||||
import { ColorScheme, useTheme } from "./context";
|
||||
import css from "./picker.module.css";
|
||||
import { Select } from "~/components/select";
|
||||
|
||||
const colorSchemes: Record<ColorScheme, keyof typeof ColorScheme> =
|
||||
Object.fromEntries(
|
||||
Object.entries(ColorScheme).map(([k, v]) => [v, k])
|
||||
) as any;
|
||||
|
||||
export const ColorSchemePicker: Component = (props) => {
|
||||
const themeContext = useTheme();
|
||||
|
||||
const setScheme: Setter<ColorScheme> = (next) => {
|
||||
if (typeof next === "function") {
|
||||
next = next();
|
||||
}
|
||||
|
||||
themeContext.setColorScheme(next);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<label aria-label="Color scheme picker">
|
||||
<Select
|
||||
id="color-scheme-picker"
|
||||
class={css.picker}
|
||||
value={themeContext.theme.colorScheme}
|
||||
setValue={setScheme}
|
||||
values={colorSchemes}
|
||||
>
|
||||
{(k, v) => (
|
||||
<>
|
||||
<Switch>
|
||||
<Match when={k === ColorScheme.Auto}>
|
||||
<WiMoonAltFirstQuarter />
|
||||
</Match>
|
||||
<Match when={k === ColorScheme.Light}>
|
||||
<WiMoonAltNew />
|
||||
</Match>
|
||||
<Match when={k === ColorScheme.Dark}>
|
||||
<WiMoonAltFull />
|
||||
</Match>
|
||||
</Switch>
|
||||
{v}
|
||||
</>
|
||||
)}
|
||||
</Select>
|
||||
</label>
|
||||
|
||||
{/* <label class={css.hue} aria-label="Hue slider">
|
||||
<input type="range" min="0" max="360" value={theme.hue} onInput={e => setHue(e.target.valueAsNumber)} />
|
||||
</label> */}
|
||||
</>
|
||||
);
|
||||
};
|
||||
1
src/global.d.ts
vendored
Normal file
1
src/global.d.ts
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/// <reference types="@solidjs/start/env" />
|
||||
41
src/routes/(shell).tsx
Normal file
41
src/routes/(shell).tsx
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { Meta } from "@solidjs/meta";
|
||||
import { query, createAsync } from "@solidjs/router";
|
||||
import { createEffect, on, ParentProps } from "solid-js";
|
||||
import { getRequestEvent } from "solid-js/web";
|
||||
import { auth } from "~/auth.server";
|
||||
import { Shell } from "~/features/shell";
|
||||
import { useTheme } from "~/features/theme";
|
||||
import { User } from "~/features/user";
|
||||
|
||||
const load = query(async (): Promise<User | undefined> => {
|
||||
"use server";
|
||||
|
||||
const session = await auth.api.getSession(getRequestEvent()!.request);
|
||||
|
||||
if (session === null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const { username, name, email, image = null } = session.user;
|
||||
|
||||
return { username, name, email, image };
|
||||
}, "session");
|
||||
|
||||
export const route = {
|
||||
async preload() {
|
||||
return load();
|
||||
},
|
||||
};
|
||||
|
||||
export default function ShellPage(props: ParentProps) {
|
||||
const user = createAsync(() => load());
|
||||
const themeContext = useTheme();
|
||||
|
||||
return (
|
||||
<Shell user={user()}>
|
||||
<Meta name="color-scheme" content={themeContext.theme.colorScheme} />
|
||||
|
||||
{props.children}
|
||||
</Shell>
|
||||
);
|
||||
}
|
||||
19
src/routes/(shell)/[...404].tsx
Normal file
19
src/routes/(shell)/[...404].tsx
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { Title } from "@solidjs/meta";
|
||||
import { HttpStatusCode } from "@solidjs/start";
|
||||
|
||||
export default function NotFound() {
|
||||
return (
|
||||
<main>
|
||||
<Title>Not Found</Title>
|
||||
<HttpStatusCode code={404} />
|
||||
<h1>Page Not Found</h1>
|
||||
<p>
|
||||
Visit{" "}
|
||||
<a href="https://start.solidjs.com" target="_blank">
|
||||
start.solidjs.com
|
||||
</a>{" "}
|
||||
to learn how to build SolidStart apps.
|
||||
</p>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
15
src/routes/(shell)/index.tsx
Normal file
15
src/routes/(shell)/index.tsx
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { Title } from "@solidjs/meta";
|
||||
|
||||
export const route = {
|
||||
preload: async () => ({}),
|
||||
};
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<>
|
||||
<Title>Home</Title>
|
||||
|
||||
<div>HOME PAGE</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
19
tsconfig.json
Normal file
19
tsconfig.json
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"jsx": "preserve",
|
||||
"jsxImportSource": "solid-js",
|
||||
"allowJs": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"types": ["vinxi/types/client"],
|
||||
"isolatedModules": true,
|
||||
"paths": {
|
||||
"~/*": ["./src/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue