Init commit
This commit is contained in:
@@ -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");
|
||||
}
|
||||
Reference in New Issue
Block a user