Init commit
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<!doctype html>
|
||||
<html lang="en" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<title>Homelab</title>
|
||||
<meta name="theme-color" content="#1e293b" />
|
||||
<!-- iOS: run standalone when added to home screen -->
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
<meta name="apple-mobile-web-app-title" content="Homelab" />
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
||||
<link rel="icon" href="/icon-512.png" />
|
||||
<link rel="manifest" href="/manifest.webmanifest" />
|
||||
</head>
|
||||
<body>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "web",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"gen": "protoc --proto_path=../proto --plugin=protoc-gen-es=./node_modules/.bin/protoc-gen-es --es_out=src/gen --es_opt=target=ts ../proto/homelab/v1/homelab.proto"
|
||||
},
|
||||
"packageManager": "pnpm@10.6.5",
|
||||
"dependencies": {
|
||||
"@bufbuild/protobuf": "^2.14.0",
|
||||
"@connectrpc/connect": "^2.1.2",
|
||||
"@connectrpc/connect-web": "^2.1.2",
|
||||
"@tailwindcss/vite": "^4.3.3",
|
||||
"daisyui": "^5.7.22",
|
||||
"lucide-preact": "^1.35.0",
|
||||
"preact": "^10.29.8",
|
||||
"tailwindcss": "^4.3.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@bufbuild/protoc-gen-es": "^2.14.0",
|
||||
"@preact/preset-vite": "^2.10.6",
|
||||
"typescript": "^7.0.2",
|
||||
"vite": "^8.2.2"
|
||||
}
|
||||
}
|
||||
Generated
+1697
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "Homelab",
|
||||
"short_name": "Homelab",
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#0f172a",
|
||||
"theme_color": "#1e293b",
|
||||
"icons": [
|
||||
{ "src": "/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/* Offline shell: network-first for navigations, cache fallback when offline. */
|
||||
const CACHE = "homelab-shell-v1";
|
||||
|
||||
self.addEventListener("install", (e) => {
|
||||
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(["/", "/index.html"])));
|
||||
});
|
||||
|
||||
self.addEventListener("activate", (e) => {
|
||||
e.waitUntil(
|
||||
caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", (e) => {
|
||||
if (e.request.mode !== "navigate") return;
|
||||
e.respondWith(fetch(e.request).catch(() => caches.match("/index.html")));
|
||||
});
|
||||
@@ -0,0 +1,85 @@
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
import { createClient } from "@connectrpc/connect";
|
||||
import { createConnectTransport } from "@connectrpc/connect-web";
|
||||
import { Dices, Hash, Send } from "lucide-preact";
|
||||
import { HomelabService } from "./gen/homelab/v1/homelab_pb";
|
||||
|
||||
const client = createClient(HomelabService, createConnectTransport({ baseUrl: "" }));
|
||||
|
||||
export function App() {
|
||||
const [lucky, setLucky] = useState<number | null>(null);
|
||||
const [count, setCount] = useState(0);
|
||||
const [name, setName] = useState("");
|
||||
const [greeting, setGreeting] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
client.getLuckyNumber({}).then((r) => setLucky(r.number));
|
||||
}, []);
|
||||
|
||||
const run = async (fn: () => Promise<unknown>) => {
|
||||
try {
|
||||
await fn();
|
||||
setError("");
|
||||
} catch (e) {
|
||||
setError(String(e));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div class="mx-auto max-w-md px-4 pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)]">
|
||||
<div class="navbar px-0">
|
||||
<div class="navbar-start" />
|
||||
<div class="navbar-center">
|
||||
<span class="text-lg font-bold">Homelab</span>
|
||||
</div>
|
||||
<div class="navbar-end" />
|
||||
</div>
|
||||
|
||||
{error && <div role="alert" class="alert alert-error text-sm">{error}</div>}
|
||||
|
||||
<div class="stats w-full shadow bg-base-200 mt-4">
|
||||
<div class="stat">
|
||||
<div class="stat-figure text-primary"><Dices size={28} /></div>
|
||||
<div class="stat-title">Lucky number</div>
|
||||
<div class="stat-value text-primary">{lucky ?? "…"}</div>
|
||||
<div class="stat-desc">set at server start</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="stat-figure text-secondary"><Hash size={28} /></div>
|
||||
<div class="stat-title">Counter</div>
|
||||
<div class="stat-value text-secondary">{count}</div>
|
||||
<div class="stat-actions">
|
||||
<button class="btn btn-sm btn-secondary" onClick={() => run(async () => setCount((await client.incrementCounter({})).value))}>
|
||||
+1
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form
|
||||
class="card bg-base-200 shadow mt-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
run(async () => setGreeting((await client.sayHello({ name })).greeting));
|
||||
}}
|
||||
>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title text-base">Hello</h2>
|
||||
<div class="flex gap-2">
|
||||
<input
|
||||
class="input input-bordered flex-1"
|
||||
value={name}
|
||||
onInput={(e) => setName((e.target as HTMLInputElement).value)}
|
||||
placeholder="NAME"
|
||||
/>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<Send size={16} /> Send
|
||||
</button>
|
||||
</div>
|
||||
{greeting && <p class="text-xl font-semibold">{greeting}</p>}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
@import "tailwindcss";
|
||||
@plugin "daisyui" {
|
||||
themes: dark --default;
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
// @generated by protoc-gen-es v2.14.0 with parameter "target=ts"
|
||||
// @generated from file homelab/v1/homelab.proto (package homelab.v1, syntax proto3)
|
||||
/* eslint-disable */
|
||||
|
||||
import type { GenFile, GenMessage, GenService } from "@bufbuild/protobuf/codegenv2";
|
||||
import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2";
|
||||
import type { Message } from "@bufbuild/protobuf";
|
||||
|
||||
/**
|
||||
* Describes the file homelab/v1/homelab.proto.
|
||||
*/
|
||||
export const file_homelab_v1_homelab: GenFile = /*@__PURE__*/
|
||||
fileDesc("Chhob21lbGFiL3YxL2hvbWVsYWIucHJvdG8SCmhvbWVsYWIudjEiFwoVR2V0THVja3lOdW1iZXJSZXF1ZXN0IigKFkdldEx1Y2t5TnVtYmVyUmVzcG9uc2USDgoGbnVtYmVyGAEgASgDIhkKF0luY3JlbWVudENvdW50ZXJSZXF1ZXN0IikKGEluY3JlbWVudENvdW50ZXJSZXNwb25zZRINCgV2YWx1ZRgBIAEoAyIfCg9TYXlIZWxsb1JlcXVlc3QSDAoEbmFtZRgBIAEoCSIkChBTYXlIZWxsb1Jlc3BvbnNlEhAKCGdyZWV0aW5nGAEgASgJMo8CCg5Ib21lbGFiU2VydmljZRJXCg5HZXRMdWNreU51bWJlchIhLmhvbWVsYWIudjEuR2V0THVja3lOdW1iZXJSZXF1ZXN0GiIuaG9tZWxhYi52MS5HZXRMdWNreU51bWJlclJlc3BvbnNlEl0KEEluY3JlbWVudENvdW50ZXISIy5ob21lbGFiLnYxLkluY3JlbWVudENvdW50ZXJSZXF1ZXN0GiQuaG9tZWxhYi52MS5JbmNyZW1lbnRDb3VudGVyUmVzcG9uc2USRQoIU2F5SGVsbG8SGy5ob21lbGFiLnYxLlNheUhlbGxvUmVxdWVzdBocLmhvbWVsYWIudjEuU2F5SGVsbG9SZXNwb25zZUIqWihwd2EtaG9tZWxhYi1tb24vZ2VuL2hvbWVsYWIvdjE7aG9tZWxhYnYxYgZwcm90bzM");
|
||||
|
||||
/**
|
||||
* @generated from message homelab.v1.GetLuckyNumberRequest
|
||||
*/
|
||||
export type GetLuckyNumberRequest = Message<"homelab.v1.GetLuckyNumberRequest"> & {
|
||||
};
|
||||
|
||||
/**
|
||||
* Describes the message homelab.v1.GetLuckyNumberRequest.
|
||||
* Use `create(GetLuckyNumberRequestSchema)` to create a new message.
|
||||
*/
|
||||
export const GetLuckyNumberRequestSchema: GenMessage<GetLuckyNumberRequest> = /*@__PURE__*/
|
||||
messageDesc(file_homelab_v1_homelab, 0);
|
||||
|
||||
/**
|
||||
* @generated from message homelab.v1.GetLuckyNumberResponse
|
||||
*/
|
||||
export type GetLuckyNumberResponse = Message<"homelab.v1.GetLuckyNumberResponse"> & {
|
||||
/**
|
||||
* @generated from field: int64 number = 1;
|
||||
*/
|
||||
number: bigint;
|
||||
};
|
||||
|
||||
/**
|
||||
* Describes the message homelab.v1.GetLuckyNumberResponse.
|
||||
* Use `create(GetLuckyNumberResponseSchema)` to create a new message.
|
||||
*/
|
||||
export const GetLuckyNumberResponseSchema: GenMessage<GetLuckyNumberResponse> = /*@__PURE__*/
|
||||
messageDesc(file_homelab_v1_homelab, 1);
|
||||
|
||||
/**
|
||||
* @generated from message homelab.v1.IncrementCounterRequest
|
||||
*/
|
||||
export type IncrementCounterRequest = Message<"homelab.v1.IncrementCounterRequest"> & {
|
||||
};
|
||||
|
||||
/**
|
||||
* Describes the message homelab.v1.IncrementCounterRequest.
|
||||
* Use `create(IncrementCounterRequestSchema)` to create a new message.
|
||||
*/
|
||||
export const IncrementCounterRequestSchema: GenMessage<IncrementCounterRequest> = /*@__PURE__*/
|
||||
messageDesc(file_homelab_v1_homelab, 2);
|
||||
|
||||
/**
|
||||
* @generated from message homelab.v1.IncrementCounterResponse
|
||||
*/
|
||||
export type IncrementCounterResponse = Message<"homelab.v1.IncrementCounterResponse"> & {
|
||||
/**
|
||||
* @generated from field: int64 value = 1;
|
||||
*/
|
||||
value: bigint;
|
||||
};
|
||||
|
||||
/**
|
||||
* Describes the message homelab.v1.IncrementCounterResponse.
|
||||
* Use `create(IncrementCounterResponseSchema)` to create a new message.
|
||||
*/
|
||||
export const IncrementCounterResponseSchema: GenMessage<IncrementCounterResponse> = /*@__PURE__*/
|
||||
messageDesc(file_homelab_v1_homelab, 3);
|
||||
|
||||
/**
|
||||
* @generated from message homelab.v1.SayHelloRequest
|
||||
*/
|
||||
export type SayHelloRequest = Message<"homelab.v1.SayHelloRequest"> & {
|
||||
/**
|
||||
* @generated from field: string name = 1;
|
||||
*/
|
||||
name: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Describes the message homelab.v1.SayHelloRequest.
|
||||
* Use `create(SayHelloRequestSchema)` to create a new message.
|
||||
*/
|
||||
export const SayHelloRequestSchema: GenMessage<SayHelloRequest> = /*@__PURE__*/
|
||||
messageDesc(file_homelab_v1_homelab, 4);
|
||||
|
||||
/**
|
||||
* @generated from message homelab.v1.SayHelloResponse
|
||||
*/
|
||||
export type SayHelloResponse = Message<"homelab.v1.SayHelloResponse"> & {
|
||||
/**
|
||||
* @generated from field: string greeting = 1;
|
||||
*/
|
||||
greeting: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Describes the message homelab.v1.SayHelloResponse.
|
||||
* Use `create(SayHelloResponseSchema)` to create a new message.
|
||||
*/
|
||||
export const SayHelloResponseSchema: GenMessage<SayHelloResponse> = /*@__PURE__*/
|
||||
messageDesc(file_homelab_v1_homelab, 5);
|
||||
|
||||
/**
|
||||
* @generated from service homelab.v1.HomelabService
|
||||
*/
|
||||
export const HomelabService: GenService<{
|
||||
/**
|
||||
* @generated from rpc homelab.v1.HomelabService.GetLuckyNumber
|
||||
*/
|
||||
getLuckyNumber: {
|
||||
methodKind: "unary";
|
||||
input: typeof GetLuckyNumberRequestSchema;
|
||||
output: typeof GetLuckyNumberResponseSchema;
|
||||
},
|
||||
/**
|
||||
* @generated from rpc homelab.v1.HomelabService.IncrementCounter
|
||||
*/
|
||||
incrementCounter: {
|
||||
methodKind: "unary";
|
||||
input: typeof IncrementCounterRequestSchema;
|
||||
output: typeof IncrementCounterResponseSchema;
|
||||
},
|
||||
/**
|
||||
* @generated from rpc homelab.v1.HomelabService.SayHello
|
||||
*/
|
||||
sayHello: {
|
||||
methodKind: "unary";
|
||||
input: typeof SayHelloRequestSchema;
|
||||
output: typeof SayHelloResponseSchema;
|
||||
},
|
||||
}> = /*@__PURE__*/
|
||||
serviceDesc(file_homelab_v1_homelab, 0);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { render } from "preact";
|
||||
import { App } from "./App";
|
||||
import "./app.css";
|
||||
|
||||
render(<App />, document.body);
|
||||
|
||||
if ("serviceWorker" in navigator && import.meta.env.PROD) {
|
||||
navigator.serviceWorker.register("/sw.js");
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact",
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"skipLibCheck": true,
|
||||
"types": ["vite/client"]
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { defineConfig } from "vite";
|
||||
import preact from "@preact/preset-vite";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [preact(), tailwindcss()],
|
||||
server: {
|
||||
proxy: {
|
||||
// Connect RPC calls in dev go straight to the Go server.
|
||||
"/homelab.v1.HomelabService": "http://localhost:8080",
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user