diff --git a/src-tauri/plugins/plugin.ts b/src-tauri/plugins/plugin.ts index c68da85e..f7f1b883 100644 --- a/src-tauri/plugins/plugin.ts +++ b/src-tauri/plugins/plugin.ts @@ -1,5 +1 @@ -console.log('---------------------------'); -console.log('- 👋 Hello from plugin.ts -'); -console.log('---------------------------'); - -Deno.core.opAsync('op_hello', 'World'); +Deno.core.opAsync('op_hello', 'Deno'); diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index e5db4138..e9fc5bae 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -23,8 +23,6 @@ use tokio::sync::Mutex; use window_ext::WindowExt; -use crate::models::HttpRequestHeader; - mod models; mod runtime; mod window_ext; @@ -41,13 +39,13 @@ pub struct CustomResponse { pub status_reason: Option<&'static str>, } -#[tauri::command] -async fn load_db(db_instance: State<'_, Mutex>>) -> Result<(), String> { +async fn migrate_db(db_instance: &Mutex>) -> Result<(), String> { let pool = &*db_instance.lock().await; let m = Migrator::new(Path::new("./migrations")) .await .expect("Failed to load migrations"); m.run(pool).await.expect("Failed to run migrations"); + println!("Migrations ran"); Ok(()) } @@ -137,22 +135,49 @@ async fn send_request( } #[tauri::command] -async fn upsert_request( - id: Option<&str>, +async fn create_request( workspace_id: &str, name: &str, - url: &str, - body: Option<&str>, - headers: Vec, - method: &str, db_instance: State<'_, Mutex>>, ) -> Result { let pool = &*db_instance.lock().await; - models::upsert_request(id, workspace_id, name, method, body, url, headers, pool) + let headers = Vec::new(); + models::upsert_request(None, workspace_id, name, "GET", None, "", headers, pool) .await .map_err(|e| e.to_string()) } +#[tauri::command] +async fn update_request( + request: models::HttpRequest, + db_instance: State<'_, Mutex>>, +) -> Result { + let pool = &*db_instance.lock().await; + + // TODO: Figure out how to make this better + let b2; + let body = match request.body { + Some(b) => { + b2 = b; + Some(b2.as_str()) + } + None => None, + }; + + models::upsert_request( + Some(request.id.as_str()), + request.workspace_id.as_str(), + request.name.as_str(), + request.method.as_str(), + body, + request.url.as_str(), + request.headers.0, + pool, + ) + .await + .map_err(|e| e.to_string()) +} + #[tauri::command] async fn requests( workspace_id: &str, @@ -245,7 +270,9 @@ fn main() { .connect(url.as_str()) .await .expect("Failed to connect to database"); - app.manage(Mutex::new(pool)); + let m = Mutex::new(pool); + migrate_db(&m).await.expect("Failed to migrate database"); + app.manage(m); Ok(()) }) }) @@ -277,11 +304,11 @@ fn main() { }) .invoke_handler(tauri::generate_handler![ greet, - load_db, workspaces, requests, send_request, - upsert_request, + create_request, + update_request, responses, delete_response, delete_all_responses, diff --git a/src-web/components/Button.tsx b/src-web/components/Button.tsx index c7637cfd..525c78ff 100644 --- a/src-web/components/Button.tsx +++ b/src-web/components/Button.tsx @@ -42,7 +42,7 @@ export const Button = forwardRef(function Button( justify === 'center' && 'justify-center', size === 'md' && 'h-10 px-4', size === 'sm' && 'h-8 px-3 text-sm', - size === 'xs' && 'h-6 px-2 text-sm', + size === 'xs' && 'h-7 px-3 text-sm', color === undefined && 'hover:bg-gray-500/[0.1] text-gray-800 hover:text-gray-900', color === 'primary' && 'bg-blue-500 hover:bg-blue-500/90 text-white', color === 'secondary' && 'bg-violet-500 hover:bg-violet-500/90 text-white', diff --git a/src-web/components/Editor/extensions.ts b/src-web/components/Editor/extensions.ts index 0dba71f2..47127d03 100644 --- a/src-web/components/Editor/extensions.ts +++ b/src-web/components/Editor/extensions.ts @@ -47,12 +47,12 @@ export const myHighlightStyle = HighlightStyle.define([ color: '#757b93', fontStyle: 'italic', }, - { tag: [t.name, t.tagName, t.angleBracket, t.docString], color: '#4699de' }, + { tag: [t.name, t.tagName, t.angleBracket, t.docString], color: 'hsl(var(--color-blue-500))' }, { tag: [t.variableName], color: '#31c434' }, { tag: [t.bool], color: '#e864f6' }, - { tag: [t.attributeName], color: '#a773ff' }, - { tag: [t.attributeValue], color: '#ff964b' }, - { tag: [t.string], color: '#e8b045' }, + { tag: [t.attributeName], color: 'hsl(var(--color-violet-500))' }, + { tag: [t.attributeValue], color: 'hsl(var(--color-orange-500))' }, + { tag: [t.string], color: 'hsl(var(--color-yellow-500))' }, { tag: [t.keyword, t.meta], color: '#45e8a4' }, ]); diff --git a/src-web/components/Sidebar.tsx b/src-web/components/Sidebar.tsx index a99369aa..e8836154 100644 --- a/src-web/components/Sidebar.tsx +++ b/src-web/components/Sidebar.tsx @@ -31,7 +31,7 @@ export function Sidebar({ className, activeRequestId, workspaceId, requests, ... onClick={() => createRequest.mutate({ name: 'Test Request' })} /> - + {requests.map((r) => ( ))} @@ -42,12 +42,12 @@ export function Sidebar({ className, activeRequestId, workspaceId, requests, ... function SidebarItem({ request, active }: { request: HttpRequest; active: boolean }) { return ( -
  • +