Skip to content

Commit

Permalink
refactor: saved queries key
Browse files Browse the repository at this point in the history
  • Loading branch information
dancixx committed Dec 31, 2023
1 parent 73b325d commit c661c59
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
7 changes: 0 additions & 7 deletions src-tauri/src/query_db.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
use std::collections::BTreeMap;

use serde::Serialize;
use tauri::{AppHandle, Manager, Result, State};

use crate::AppState;

#[derive(Default, Serialize)]
pub struct QueryDetails {
pub title: String,
pub sql: String,
}

#[tauri::command]
pub async fn insert_query(key: &str, sql: &str, app: AppHandle) -> Result<()> {
let app_state = app.state::<AppState>();
Expand Down
11 changes: 9 additions & 2 deletions src/sidebar/project.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use leptos::{html::*, *};

use crate::store::projects::ProjectsStore;
use crate::store::{active_project::ActiveProjectStore, projects::ProjectsStore};

use super::schemas;

pub fn component(project_name: String) -> impl IntoView {
let projects_store = use_context::<ProjectsStore>().unwrap();
let active_project_store = use_context::<ActiveProjectStore>().unwrap();
let (show_schemas, set_show_schemas) = create_signal(false);
let delete_project = create_action(move |(project_store, project): &(ProjectsStore, String)| {
let project_store = *project_store;
Expand All @@ -24,7 +25,13 @@ pub fn component(project_name: String) -> impl IntoView {
button()
.classes("hover:font-semibold")
.child(&project_name)
.on(ev::click, move |_| set_show_schemas(!show_schemas())),
.on(ev::click, {
let project_name = project_name.clone();
move |_| {
active_project_store.0.set(Some(project_name.clone()));
set_show_schemas(!show_schemas());
}
}),
)
.child(
button()
Expand Down
6 changes: 3 additions & 3 deletions src/store/query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::BTreeMap;
use std::{collections::BTreeMap, fmt::format};

Check warning

Code scanning / clippy

unused import: fmt::format Warning

unused import: fmt::format

use leptos::{error::Result, *};

Expand Down Expand Up @@ -80,11 +80,11 @@ impl QueryStore {
}

#[allow(dead_code)]
pub async fn insert_query(&self, key: &str) -> Result<()> {
pub async fn insert_query(&self, key: &str, project_name: &str) -> Result<()> {
let editor_state = use_context::<EditorStore>().unwrap();
let sql = editor_state.get_value();
let args = serde_wasm_bindgen::to_value(&InvokeInsertQueryArgs {
key: key.to_string(),
key: format!("{}:{}", project_name, key),
sql,
});
invoke(&Invoke::insert_query.to_string(), args.unwrap_or_default()).await;
Expand Down

0 comments on commit c661c59

Please sign in to comment.