diff --git a/src-tauri/sqlx-data.json b/src-tauri/sqlx-data.json index 1308143a..66284071 100644 --- a/src-tauri/sqlx-data.json +++ b/src-tauri/sqlx-data.json @@ -78,6 +78,108 @@ }, "query": "\n DELETE FROM http_requests\n WHERE id = ?\n " }, + "5aa070e61995f8b1724efaa94c5f0cef5a4be6efda5d70354ad449d7d4b5aee4": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Text" + }, + { + "name": "model", + "ordinal": 1, + "type_info": "Text" + }, + { + "name": "workspace_id", + "ordinal": 2, + "type_info": "Text" + }, + { + "name": "request_id", + "ordinal": 3, + "type_info": "Text" + }, + { + "name": "updated_at", + "ordinal": 4, + "type_info": "Datetime" + }, + { + "name": "created_at", + "ordinal": 5, + "type_info": "Datetime" + }, + { + "name": "url", + "ordinal": 6, + "type_info": "Text" + }, + { + "name": "status", + "ordinal": 7, + "type_info": "Int64" + }, + { + "name": "status_reason", + "ordinal": 8, + "type_info": "Text" + }, + { + "name": "content_length", + "ordinal": 9, + "type_info": "Int64" + }, + { + "name": "body", + "ordinal": 10, + "type_info": "Blob" + }, + { + "name": "body_path", + "ordinal": 11, + "type_info": "Text" + }, + { + "name": "elapsed", + "ordinal": 12, + "type_info": "Int64" + }, + { + "name": "error", + "ordinal": 13, + "type_info": "Text" + }, + { + "name": "headers!: sqlx::types::Json>", + "ordinal": 14, + "type_info": "Text" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + false, + false, + true, + true, + true, + true, + false, + true, + false + ], + "parameters": { + "Right": 1 + } + }, + "query": "\n SELECT id, model, workspace_id, request_id, updated_at, created_at, url,\n status, status_reason, content_length, body, body_path, elapsed, error,\n headers AS \"headers!: sqlx::types::Json>\"\n FROM http_responses\n WHERE request_id = ?\n ORDER BY created_at DESC\n " + }, "62475fd9483fb5eda01c937949da2ef66ac7005b4be06b87aa6210d462348aca": { "describe": { "columns": [], @@ -528,108 +630,6 @@ }, "query": "\n UPDATE workspaces SET (name, updated_at) =\n (?, CURRENT_TIMESTAMP) WHERE id = ?;\n " }, - "e7bba61f8d60fb021c027d829b070e7087041e0f30252754aaaa85223b614896": { - "describe": { - "columns": [ - { - "name": "id", - "ordinal": 0, - "type_info": "Text" - }, - { - "name": "model", - "ordinal": 1, - "type_info": "Text" - }, - { - "name": "workspace_id", - "ordinal": 2, - "type_info": "Text" - }, - { - "name": "request_id", - "ordinal": 3, - "type_info": "Text" - }, - { - "name": "updated_at", - "ordinal": 4, - "type_info": "Datetime" - }, - { - "name": "created_at", - "ordinal": 5, - "type_info": "Datetime" - }, - { - "name": "url", - "ordinal": 6, - "type_info": "Text" - }, - { - "name": "status", - "ordinal": 7, - "type_info": "Int64" - }, - { - "name": "status_reason", - "ordinal": 8, - "type_info": "Text" - }, - { - "name": "content_length", - "ordinal": 9, - "type_info": "Int64" - }, - { - "name": "body", - "ordinal": 10, - "type_info": "Blob" - }, - { - "name": "body_path", - "ordinal": 11, - "type_info": "Text" - }, - { - "name": "elapsed", - "ordinal": 12, - "type_info": "Int64" - }, - { - "name": "error", - "ordinal": 13, - "type_info": "Text" - }, - { - "name": "headers!: sqlx::types::Json>", - "ordinal": 14, - "type_info": "Text" - } - ], - "nullable": [ - false, - false, - false, - false, - false, - false, - false, - false, - true, - true, - true, - true, - false, - true, - false - ], - "parameters": { - "Right": 1 - } - }, - "query": "\n SELECT id, model, workspace_id, request_id, updated_at, created_at, url,\n status, status_reason, content_length, body, body_path, elapsed, error,\n headers AS \"headers!: sqlx::types::Json>\"\n FROM http_responses\n WHERE request_id = ?\n ORDER BY created_at ASC\n " - }, "f116d8cf9aad828135bb8c3a4c8b8e6b857ae13303989e9133a33b2d1cf20e96": { "describe": { "columns": [], diff --git a/src-tauri/src/models.rs b/src-tauri/src/models.rs index 910ec826..32783eec 100644 --- a/src-tauri/src/models.rs +++ b/src-tauri/src/models.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::fs; use rand::distributions::{Alphanumeric, DistString}; use serde::{Deserialize, Serialize}; @@ -516,7 +517,7 @@ pub async fn find_responses( headers AS "headers!: sqlx::types::Json>" FROM http_responses WHERE request_id = ? - ORDER BY created_at ASC + ORDER BY created_at DESC "#, request_id, ) @@ -529,6 +530,13 @@ pub async fn delete_response(id: &str, pool: &Pool) -> Result, ) -> Result<(), sqlx::Error> { - let _ = sqlx::query!( - r#" - DELETE FROM http_responses - WHERE request_id = ? - "#, - request_id, - ) - .execute(pool) - .await; - + for r in find_responses(request_id, pool).await? { + delete_response(&r.id, pool).await?; + } Ok(()) } diff --git a/src-web/components/GlobalHooks.tsx b/src-web/components/GlobalHooks.tsx index 4a345e59..ab30f79b 100644 --- a/src-web/components/GlobalHooks.tsx +++ b/src-web/components/GlobalHooks.tsx @@ -35,7 +35,8 @@ export function GlobalHooks() { } if (!shouldIgnoreModel(payload)) { - queryClient.setQueryData(queryKey, (values) => [...(values ?? []), payload]); + // Order newest first + queryClient.setQueryData(queryKey, (values) => [payload, ...(values ?? [])]); } }); diff --git a/src-web/components/ResponsePane.tsx b/src-web/components/ResponsePane.tsx index 5677a54a..1e2c8c53 100644 --- a/src-web/components/ResponsePane.tsx +++ b/src-web/components/ResponsePane.tsx @@ -41,7 +41,7 @@ export const ResponsePane = memo(function ResponsePane({ style, className }: Pro const responses = useResponses(activeRequestId); const activeResponse: HttpResponse | null = pinnedResponseId ? responses.find((r) => r.id === pinnedResponseId) ?? null - : responses[responses.length - 1] ?? null; + : responses[0] ?? null; const [viewMode, setViewMode] = useResponseViewMode(activeResponse?.requestId); const deleteResponse = useDeleteResponse(activeResponse?.id ?? null); const deleteAllResponses = useDeleteResponses(activeResponse?.requestId); @@ -138,7 +138,7 @@ export const ResponsePane = memo(function ResponsePane({ style, className }: Pro disabled: responses.length === 0, }, { type: 'separator', label: 'History' }, - ...responses.slice(0, 10).map((r) => ({ + ...responses.slice(0, 20).map((r) => ({ key: r.id, label: ( @@ -146,7 +146,8 @@ export const ResponsePane = memo(function ResponsePane({ style, className }: Pro {r.elapsed}ms ), - leftSlot: activeResponse?.id === r.id ? : <>, + leftSlot: + activeResponse?.id === r.id ? : , onSelect: () => setPinnedResponseId(r.id), })), ]} diff --git a/src-web/components/core/DurationTag.tsx b/src-web/components/core/DurationTag.tsx index d4bb3964..ae7f6777 100644 --- a/src-web/components/core/DurationTag.tsx +++ b/src-web/components/core/DurationTag.tsx @@ -18,8 +18,8 @@ export function DurationTag({ millis }: Props) { } return ( - <> + {Math.round(num * 10) / 10} {unit} - + ); } diff --git a/src-web/components/core/SizeTag.tsx b/src-web/components/core/SizeTag.tsx index 69f62340..50c26279 100644 --- a/src-web/components/core/SizeTag.tsx +++ b/src-web/components/core/SizeTag.tsx @@ -21,8 +21,8 @@ export function SizeTag({ contentLength }: Props) { } return ( - <> + {Math.round(num * 10) / 10} {unit} - + ); }