Compare commits

...

3 Commits

21 changed files with 572 additions and 41 deletions

331
Cargo.lock generated
View File

@ -409,6 +409,15 @@ version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
[[package]]
name = "bincode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [
"serde 1.0.217",
]
[[package]]
name = "bindgen"
version = "0.69.5"
@ -581,7 +590,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
name = "changeset"
version = "0.1.0"
dependencies = [
"uuid 0.8.2",
"uuid 1.13.1",
]
[[package]]
@ -722,6 +731,16 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "console_error_panic_hook"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
dependencies = [
"cfg-if",
"wasm-bindgen",
]
[[package]]
name = "const-oid"
version = "0.9.6"
@ -1559,8 +1578,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"js-sys",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
"wasm-bindgen",
]
[[package]]
@ -1704,6 +1725,154 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
[[package]]
name = "gloo"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d15282ece24eaf4bd338d73ef580c6714c8615155c4190c781290ee3fa0fd372"
dependencies = [
"gloo-console",
"gloo-dialogs",
"gloo-events",
"gloo-file",
"gloo-history",
"gloo-net 0.5.0",
"gloo-render",
"gloo-storage",
"gloo-timers",
"gloo-utils",
"gloo-worker",
]
[[package]]
name = "gloo-console"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a17868f56b4a24f677b17c8cb69958385102fa879418052d60b50bc1727e261"
dependencies = [
"gloo-utils",
"js-sys",
"serde 1.0.217",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "gloo-dialogs"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4748e10122b01435750ff530095b1217cf6546173459448b83913ebe7815df"
dependencies = [
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "gloo-events"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27c26fb45f7c385ba980f5fa87ac677e363949e065a083722697ef1b2cc91e41"
dependencies = [
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "gloo-file"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97563d71863fb2824b2e974e754a81d19c4a7ec47b09ced8a0e6656b6d54bd1f"
dependencies = [
"gloo-events",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "gloo-history"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "903f432be5ba34427eac5e16048ef65604a82061fe93789f2212afc73d8617d6"
dependencies = [
"getrandom 0.2.15",
"gloo-events",
"gloo-utils",
"serde 1.0.217",
"serde-wasm-bindgen",
"serde_urlencoded",
"thiserror 1.0.69",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "gloo-net"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43aaa242d1239a8822c15c645f02166398da4f8b5c4bae795c1f5b44e9eee173"
dependencies = [
"futures-channel",
"futures-core",
"futures-sink",
"gloo-utils",
"http 0.2.12",
"js-sys",
"pin-project",
"serde 1.0.217",
"serde_json",
"thiserror 1.0.69",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
]
[[package]]
name = "gloo-net"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06f627b1a58ca3d42b45d6104bf1e1a03799df472df00988b6ba21accc10580"
dependencies = [
"futures-channel",
"futures-core",
"futures-sink",
"gloo-utils",
"http 1.2.0",
"js-sys",
"pin-project",
"serde 1.0.217",
"serde_json",
"thiserror 1.0.69",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
]
[[package]]
name = "gloo-render"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56008b6744713a8e8d98ac3dcb7d06543d5662358c9c805b4ce2167ad4649833"
dependencies = [
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "gloo-storage"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbc8031e8c92758af912f9bc08fbbadd3c6f3cfcbf6b64cdf3d6a81f0139277a"
dependencies = [
"gloo-utils",
"js-sys",
"serde 1.0.217",
"serde_json",
"thiserror 1.0.69",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "gloo-timers"
version = "0.3.0"
@ -1716,6 +1885,50 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "gloo-utils"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b5555354113b18c547c1d3a98fbf7fb32a9ff4f6fa112ce823a21641a0ba3aa"
dependencies = [
"js-sys",
"serde 1.0.217",
"serde_json",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "gloo-worker"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "085f262d7604911c8150162529cefab3782e91adb20202e8658f7275d2aefe5d"
dependencies = [
"bincode",
"futures",
"gloo-utils",
"gloo-worker-macros",
"js-sys",
"pinned",
"serde 1.0.217",
"thiserror 1.0.69",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
]
[[package]]
name = "gloo-worker-macros"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "956caa58d4857bc9941749d55e4bd3000032d8212762586fa5705632967140e7"
dependencies = [
"proc-macro-crate 1.3.1",
"proc-macro2",
"quote",
"syn 2.0.96",
]
[[package]]
name = "gm-control-panel"
version = "0.1.0"
@ -2407,6 +2620,26 @@ dependencies = [
"tiff 0.9.1",
]
[[package]]
name = "implicit-clone"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bd41bf647018e1da0e32dac34d02135d61d7204cee650e4633eddbd0b23ec38"
dependencies = [
"implicit-clone-derive",
"indexmap",
]
[[package]]
name = "implicit-clone-derive"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9311685eb9a34808bbb0608ad2fcab9ae216266beca5848613e95553ac914e3b"
dependencies = [
"quote",
"syn 2.0.96",
]
[[package]]
name = "indent_write"
version = "2.2.0"
@ -3303,6 +3536,17 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pinned"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a829027bd95e54cfe13e3e258a1ae7b645960553fb82b75ff852c29688ee595b"
dependencies = [
"futures",
"rustversion",
"thiserror 1.0.69",
]
[[package]]
name = "piper"
version = "0.2.4"
@ -3443,6 +3687,16 @@ dependencies = [
"log 0.4.25",
]
[[package]]
name = "prettyplease"
version = "0.2.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6924ced06e1f7dfe3fa48d57b9f74f55d8915f5036121bef647ef4b204895fac"
dependencies = [
"proc-macro2",
"syn 2.0.96",
]
[[package]]
name = "proc-macro-crate"
version = "1.3.1"
@ -4019,6 +4273,17 @@ dependencies = [
"serde_derive",
]
[[package]]
name = "serde-wasm-bindgen"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8302e169f0eddcc139c70f139d19d6467353af16f9fce27e8c30158036a1e16b"
dependencies = [
"js-sys",
"serde 1.0.217",
"wasm-bindgen",
]
[[package]]
name = "serde_derive"
version = "1.0.217"
@ -4795,6 +5060,23 @@ dependencies = [
"tokio",
]
[[package]]
name = "tokise"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fae352452702497bdbde0ce9c79a27fa488c73be42c77e0e9ee4a1b5cce97596"
dependencies = [
"futures",
"gloo",
"num_cpus",
"once_cell",
"pin-project",
"pinned",
"tokio",
"tokio-stream",
"wasm-bindgen-futures",
]
[[package]]
name = "toml"
version = "0.8.2"
@ -5601,6 +5883,53 @@ dependencies = [
"winapi",
]
[[package]]
name = "yew"
version = "0.21.0"
source = "git+https://github.com/yewstack/yew/#69e3b5f8140180acd1c2de41e421960cbacf768f"
dependencies = [
"console_error_panic_hook",
"futures",
"gloo",
"implicit-clone",
"indexmap",
"js-sys",
"rustversion",
"serde 1.0.217",
"slab",
"thiserror 1.0.69",
"tokio",
"tokise",
"tracing",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"yew-macro",
]
[[package]]
name = "yew-app"
version = "0.1.0"
dependencies = [
"gloo-net 0.6.0",
"serde 1.0.217",
"wasm-bindgen-futures",
"yew",
]
[[package]]
name = "yew-macro"
version = "0.21.0"
source = "git+https://github.com/yewstack/yew/#69e3b5f8140180acd1c2de41e421960cbacf768f"
dependencies = [
"once_cell",
"prettyplease",
"proc-macro-error",
"proc-macro2",
"quote",
"syn 2.0.96",
]
[[package]]
name = "yoke"
version = "0.7.5"

View File

@ -33,4 +33,4 @@ members = [
"tree",
"visions/server",
"gm-dash/server"
]
, "visions/yew-app"]

View File

@ -25,6 +25,7 @@
pkgs.cargo-watch
pkgs.clang
pkgs.crate2nix
pkgs.trunk
pkgs.glib
pkgs.gst_all_1.gst-plugins-bad
pkgs.gst_all_1.gst-plugins-base

View File

@ -2,8 +2,11 @@
"name": "visions-client",
"version": "0.0.1",
"description": "Shared data types for Visions",
"main": "visions.js",
"types": "dist/lib.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"/dist"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},

View File

@ -1,4 +1,4 @@
import { Connection } from './lib'
import { Connection } from './index'
describe('what happens in an authentication', () => {
it('handles a successful response', async () => {

View File

@ -11,5 +11,5 @@
"strict": true,
"skipLibCheck": true
},
"include": ["gen", "src"]
"include": ["src/**/*"]
}

View File

@ -1,15 +0,0 @@
/*
Generated by typeshare 1.13.0
*/
export type SessionId = string;
export interface AuthRequest {
username: string;
password: string;
}
export type AuthResponse =
| { type: "Success", content: SessionId }
| { type: "PasswordReset", content: SessionId };

2
visions/types/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
gen/
dist/

View File

@ -4,4 +4,5 @@ tasks:
build:
cmds:
- npm install typescript
- typeshare --lang typescript --output-file dist/lib.ts ../server/src
- typeshare --lang typescript --output-file gen/index.ts ../server/src
- npx tsc

View File

@ -2,8 +2,11 @@
"name": "visions-types",
"version": "0.0.1",
"description": "Shared data types for Visions",
"main": "visions.js",
"types": "dist/lib.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"/dist"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},

View File

@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"target": "es6",
"module": "es6",
"moduleResolution": "node",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
@ -9,7 +10,7 @@
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"include": ["./gen/lib.ts"]
"skipLibCheck": true,
"rootDir": "./gen"
}
}

View File

@ -5,11 +5,10 @@ tasks:
cmds:
- npm run fmt
dev:
build:
cmds:
# - cd ../visions-types && task build
- npm install
- npm run dev
- npx tsc --watch
test:
cmds:

11
visions/ui/index.html Normal file
View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> My first web component with typescript </title>
</head>
<body>
<app-component name="TypeScript"></app-component>
<script type="module" src="./dist/app-component.js"></script>
</body>
</html>

View File

@ -9,12 +9,37 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"lit": "^3.2.1"
"lit": "^3.2.1",
"visions-client": "file:../client",
"visions-types": "file:../types"
},
"devDependencies": {
"typescript": "^5.7.3"
}
},
"../client": {
"name": "visions-client",
"version": "0.0.1",
"license": "ISC",
"dependencies": {
"visions-types": "file:../types"
},
"devDependencies": {
"@types/jest": "^29.5.14",
"jest": "^29.7.0",
"prettier": "^3.5.1",
"ts-jest": "^29.2.5",
"typescript": "^5.7.3"
}
},
"../types": {
"name": "visions-types",
"version": "0.0.1",
"license": "ISC",
"dependencies": {
"typescript": "^5.7.3"
}
},
"node_modules/@lit-labs/ssr-dom-shim": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.3.0.tgz",
@ -73,6 +98,14 @@
"engines": {
"node": ">=14.17"
}
},
"node_modules/visions-client": {
"resolved": "../client",
"link": true
},
"node_modules/visions-types": {
"resolved": "../types",
"link": true
}
}
}

View File

@ -13,6 +13,8 @@
"typescript": "^5.7.3"
},
"dependencies": {
"lit": "^3.2.1"
"lit": "^3.2.1",
"visions-client": "file:../client",
"visions-types": "file:../types"
}
}

View File

@ -0,0 +1,21 @@
import {html, css, LitElement} from 'lit';
import {customElement, property} from 'lit/decorators.js';
export class SimpleGreeting extends LitElement {
static styles = css`p { color: blue }`;
name: String;
static properties = {
name: { type: String }
};
constructor() {
super();
this.name = 'Somebody';
}
render() {
return html`<p>Hello, ${this.name}!</p>`;
}
}

View File

@ -1,5 +1,4 @@
import { Client } from 'visions-client'
import { ActionDispatch } from 'react'
export type AuthState =
| { type: 'unauthed' }
@ -13,9 +12,9 @@ export const initialState = (): State => ({
auth: { type: 'unauthed' },
})
export const sessionId = (state: State) => string | undefined {
if (state.type === 'authed') {
return state.sessionId
export const sessionId = (state: State): string | undefined => {
if (state.auth.type === 'authed') {
return state.auth.sessionId
} else {
return undefined
}
@ -37,16 +36,13 @@ export const reducer = (state: State, action: Action) => {
export class Controller {
client: Client
state: State
dispatch: ActionDispatch<[action: Action]>
constructor(
client: Client,
state: State,
dispatch: ActionDispatch<[action: Action]>,
) {
this.client = client
this.state = state
this.dispatch = dispatch
}
// On any request, there are four options.
@ -58,6 +54,7 @@ export class Controller {
let response = await this.client.auth(username, password)
switch (response.status) {
case 'ok': {
/*
this.dispatch({
type: 'set-auth',
content: {
@ -65,6 +62,7 @@ export class Controller {
sessionId: response.content.content,
},
})
*/
return
}
}

View File

@ -0,0 +1,11 @@
[package]
name = "yew-app"
version = "0.1.0"
edition = "2021"
[dependencies]
gloo-net = "0.6.0"
serde = { version = "1.0.217", features = ["derive"] }
wasm-bindgen-futures = "0.4.50"
yew = { git = "https://github.com/yewstack/yew/", features = ["csr"] }

View File

@ -0,0 +1,5 @@
<!doctype html>
<html lang="en">
<head></head>
<body></body>
</html>

126
visions/yew-app/src/main.rs Normal file
View File

@ -0,0 +1,126 @@
use yew::prelude::*;
use serde::Deserialize;
use gloo_net::http::Request;
#[derive(Clone, PartialEq, Deserialize)]
struct Video {
id: usize,
title: String,
speaker: String,
url: String,
}
#[derive(Properties, PartialEq)]
struct VideosListProps {
videos: Vec<Video>,
on_click: Callback<Video>,
}
/*
fn videos() -> Vec<Video> {
vec![
Video {
id: 1,
title: "Building and breaking things".to_string(),
speaker: "John Doe".to_string(),
url: "https://youtu.be/PsaFVLr8t4E".to_string(),
},
Video {
id: 2,
title: "The development process".to_string(),
speaker: "Jane Smith".to_string(),
url: "https://youtu.be/PsaFVLr8t4E".to_string(),
},
Video {
id: 3,
title: "The Web 7.0".to_string(),
speaker: "Matt Miller".to_string(),
url: "https://youtu.be/PsaFVLr8t4E".to_string(),
},
Video {
id: 4,
title: "Mouseless development".to_string(),
speaker: "Tom Jerry".to_string(),
url: "https://youtu.be/PsaFVLr8t4E".to_string(),
},
]
}
*/
#[function_component(VideosList)]
fn videos_list(VideosListProps { videos, on_click }: &VideosListProps) -> Html {
let on_click = on_click.clone();
videos
.iter()
.map(|video| {
let on_video_select = {
let on_click = on_click.clone();
let video = video.clone();
Callback::from(move |_| on_click.emit(video.clone()))
};
html! {
<p key={video.id} onclick={on_video_select}>{format!("{}: {}", video.speaker, video.title)}</p>
}
})
.collect()
}
#[derive(Properties, PartialEq)]
struct VideosDetailsProps {
video: Video,
}
#[function_component(VideoDetails)]
fn video_details(VideosDetailsProps { video }: &VideosDetailsProps) -> Html {
html! {
<div>
<h3>{video.title.clone()}</h3>
<img src="https://via.placeholder.com/640x360.png?text=Video+Player+Placeholder" alt="video thumbnail" />
</div>
}
}
#[function_component(App)]
fn app() -> Html {
let videos = use_state(|| vec![]);
{
let videos = videos.clone();
use_effect_with((), move |_| {
let videos = videos.clone();
wasm_bindgen_futures::spawn_local(async move {
let response = Request::get("/tutorial/data.json").send().await;
println!("response: {:?}", response);
let response = response.unwrap();
let fetched_videos: Vec<Video> = response.json().await.unwrap();
videos.set(fetched_videos);
});
|| ()
});
}
let selected_video = use_state(|| None);
let on_video_select = {
let selected_video = selected_video.clone();
Callback::from(move |video: Video| selected_video.set(Some(video)))
};
let details = selected_video.as_ref().map(|video| html! {
<VideoDetails video={video.clone()} />
});
html! {
<>
<h1>{ "RustConf Explorer" }</h1>
<div>
<h3>{"Videos to watch"}</h3>
<VideosList videos={(*videos).clone()} on_click={on_video_select.clone()} />
</div>
{ for details }
</>
}
}
fn main() {
yew::Renderer::<App>::new().render();
}