fetch some nodes

This commit is contained in:
Michael Zhang 2024-02-08 00:03:29 -06:00
parent 1b4e74485b
commit d8eb1502d5
28 changed files with 4972 additions and 688 deletions

3943
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -13,15 +13,15 @@
"license": "MIT",
"dependencies": {
"@tauri-apps/api": "^2.0.0-alpha.11",
"@tauri-apps/plugin-shell": "^2.0.0-alpha.3",
"solid-js": "^1.7.8"
"@tauri-apps/plugin-shell": "^2.0.0-beta.0",
"solid-js": "^1.8.14"
},
"devDependencies": {
"@tauri-apps/cli": "^2.0.0-alpha.17",
"internal-ip": "^7.0.0",
"internal-ip": "^8.0.0",
"sass": "^1.70.0",
"typescript": "^5.0.2",
"vite": "^4.4.4",
"vite-plugin-solid": "^2.7.0"
"typescript": "^5.3.3",
"vite": "^5.0.12",
"vite-plugin-solid": "^2.9.1"
}
}

View file

@ -1,4 +1,4 @@
# Generated by Cargo
# will have compiled files and executables
/target/
/gen/schemas

1550
src-tauri/Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,32 +1,32 @@
[package]
name = "panorama"
version = "0.0.0"
name = "app"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
edition = "2021"
rust-version = "1.70"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "panorama_lib"
name = "app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2.0.0-alpha", features = [] }
tauri-build = { version = "2.0.0-beta.1", features = [] }
[dependencies]
tauri = { version = "2.0.0-alpha", features = [] }
tauri-plugin-window = "2.0.0-alpha"
tauri-plugin-shell = "2.0.0-alpha"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "2.0.0-beta.2", features = [] }
cozo = { version = "0.7.5", features = ["storage-rocksdb"] }
dirs = "5.0.1"
eyre = "0.6.12"
miette = { version = "5.10.0", features = ["backtrace", "fancy", "is-terminal", "serde"] }
[features]
# this feature is used for production builds or when `devPath` points to the filesystem
# this feature is used for production builds or when `devUrl` points to the filesystem
# DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]
custom-protocol = [ "tauri/custom-protocol" ]

View file

@ -1,3 +1,3 @@
fn main() {
tauri_build::build()
tauri_build::build()
}

View file

@ -0,0 +1,16 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default-plugins",
"description": "enables the default permissions",
"windows": ["main"],
"permissions": [
"path:default",
"event:default",
"window:default",
"webview:default",
"app:default",
"resources:default",
"menu:default",
"tray:default"
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 974 B

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 903 B

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 49 KiB

View file

@ -1,12 +1,12 @@
mod schema;
use cozo::{DbInstance, ScriptMutability};
use schema::ensure_schema;
use tauri::State;
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
use crate::schema::ensure_schema;
struct AppState {
db: DbInstance,
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
@ -19,10 +19,29 @@ pub fn run() {
println!("WTF? {:?}", err);
}
let state = AppState { db };
tauri::Builder::default()
.plugin(tauri_plugin_window::init())
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![greet])
.manage(state)
.invoke_handler(tauri::generate_handler![fetch_nodes])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
#[tauri::command]
fn fetch_nodes(state: State<AppState>) -> Vec<String> {
let result = state
.db
.run_script(
"?[id, content] := *node[id, content]",
Default::default(),
ScriptMutability::Immutable,
)
.unwrap();
result
.rows
.iter()
.map(|row| format!("row: {:?}", row[0]))
.collect()
}

View file

@ -2,5 +2,5 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
panorama_lib::run()
app_lib::run();
}

View file

@ -1,9 +1,8 @@
use std::collections::BTreeMap;
use cozo::{DataValue, DbInstance, ScriptMutability};
use miette::Result;
pub fn ensure_schema(db: &DbInstance) -> Result<()> {
// Get existing list of relations to see what we need to create
let existing_relations = db.run_script(
"::relations",
Default::default(),
@ -12,22 +11,22 @@ pub fn ensure_schema(db: &DbInstance) -> Result<()> {
println!("Result: {:?}", existing_relations);
// Create the `node` relation
db.run_script(
"%ignore_error {:create node {id: String, content: String}}",
"%ignore_error { :create node { id: String, => content: String } }",
Default::default(),
ScriptMutability::Mutable,
)?;
let mut create_rule_params = BTreeMap::new();
create_rule_params
.insert(format!("input_data"), DataValue::from(format!("root")));
// Create the root node
db.run_script(
"
%if { len[count(x)] := *node[x, y]; ?[x] := len[z], x = z == 0 }
{ ?[node, content] := $input_data; :put node {id, content} }
%end
{
?[id, content] <- [['root', '']]
:put node {id, content}
}
",
create_rule_params,
Default::default(),
ScriptMutability::Mutable,
)?;

View file

@ -1,43 +1,37 @@
{
"build": {
"beforeDevCommand": "pnpm dev",
"beforeBuildCommand": "pnpm build",
"devPath": "http://localhost:1420",
"distDir": "../dist"
},
"package": {
"productName": "panorama",
"version": "0.0.0"
},
"tauri": {
"bundle": {
"active": true,
"targets": "all",
"identifier": "com.tauri.dev",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
},
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
"app": {
"security": {
"csp": null
},
"windows": [
{
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "panorama",
"width": 800,
"height": 600
"width": 800
}
]
},
"plugins": {
"shell": {
"open": true
}
}
"build": {
"beforeBuildCommand": "npm run build",
"beforeDevCommand": "npm run dev",
"devUrl": "http://localhost:1420",
"frontendDist": "../dist"
},
"bundle": {
"active": true,
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"targets": "all"
},
"identifier": "com.tauri.dev",
"productName": "panorama",
"version": "0.1.0"
}

View file

@ -1,8 +1,15 @@
import NodeContainer from "./components/NodeContainer";
import Sidebar from "./components/Sidebar";
import styles from "./App.module.scss";
import { createEffect } from "solid-js";
import { invoke } from "@tauri-apps/api/core";
function App() {
createEffect(async () => {
const result = await invoke("fetch_nodes");
console.log("helloge", result);
});
return (
<div class={styles.container}>
<Sidebar />