From 806909420161c8e9c09d1d1ace9d29dc648f5500 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Mon, 10 Apr 2023 11:16:25 -0700 Subject: [PATCH] Upgrade deno core --- src-tauri/Cargo.lock | 12 ++++++------ src-tauri/Cargo.toml | 2 +- src-web/components/Sidebar.tsx | 32 ++++++++++++++++++++------------ 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 4a57dc25..6569d46b 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -679,9 +679,9 @@ dependencies = [ [[package]] name = "deno_core" -version = "0.178.0" +version = "0.179.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d58bd9e43979857fd26f4696f8e9f39fb645539ef3e604264521b408daf1d92b" +checksum = "8c9307ca2299cb7b0bdaa345cbdc82a252a8e4e5a4463e28f44c715d55e460fb" dependencies = [ "anyhow", "bytes", @@ -704,9 +704,9 @@ dependencies = [ [[package]] name = "deno_ops" -version = "0.56.0" +version = "0.57.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f494a90671467e3de74b557b3c1fe805aad87c7239580d2be8f2dddde971824" +checksum = "04610f07342fbb33a2b7ea7aa16a95ab71adb13a0ce858a8d1a1414660a83e3e" dependencies = [ "once_cell", "pmutil", @@ -3161,9 +3161,9 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.89.0" +version = "0.90.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9541cff99b1b9da15461aada44f09577af1f614add71f2fedc250c7e650a0383" +checksum = "916ca7852a4c5f0ba59ce4a46301bf7c7ad573c2c89a0fe67e90fe30dcbd6f7d" dependencies = [ "bytes", "derive_more", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index a5f94fdb..f09a6ab1 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -25,7 +25,7 @@ http = "0.2.8" reqwest = { version = "0.11.14", features = ["json"] } tokio = { version = "1.25.0", features = ["sync"] } futures = "0.3.26" -deno_core = "0.178.0" +deno_core = "0.179.0" deno_ast = { version = "0.25.0", features = ["transpiling"] } sqlx = { version = "0.6.2", features = ["sqlite", "runtime-tokio-rustls", "json", "chrono", "time", "offline"] } uuid = "1.3.0" diff --git a/src-web/components/Sidebar.tsx b/src-web/components/Sidebar.tsx index 77c8b893..8d54836f 100644 --- a/src-web/components/Sidebar.tsx +++ b/src-web/components/Sidebar.tsx @@ -1,5 +1,5 @@ import classnames from 'classnames'; -import type { ForwardedRef, KeyboardEvent } from 'react'; +import type { ForwardedRef } from 'react'; import React, { forwardRef, Fragment, memo, useCallback, useMemo, useRef, useState } from 'react'; import type { XYCoord } from 'react-dnd'; import { useDrag, useDrop } from 'react-dnd'; @@ -45,7 +45,8 @@ export const Sidebar = memo(function Sidebar({ className }: Props) { const focusActiveRequest = useCallback( (forcedIndex?: number) => { const index = forcedIndex ?? requests.findIndex((r) => r.id === activeRequestId); - setSelectedIndex(index >= 0 ? index : 0); + if (index < 0) return; + setSelectedIndex(index >= 0 ? index : undefined); setHasFocus(true); sidebarRef.current?.focus(); }, @@ -66,12 +67,27 @@ export const Sidebar = memo(function Sidebar({ className }: Props) { const handleFocus = useCallback(() => focusActiveRequest(), [focusActiveRequest]); const handleBlur = useCallback(() => setHasFocus(false), []); + const handleDeleteKey = useCallback( + (e: KeyboardEvent) => { + if (!hasFocus) return; + e.preventDefault(); + + const selectedRequest = requests[selectedIndex ?? -1]; + if (selectedRequest === undefined) return; + deleteAnyRequest.mutate(selectedRequest.id); + }, + [deleteAnyRequest, hasFocus, requests, selectedIndex], + ); + + useKeyPressEvent('Backspace', handleDeleteKey); + useKeyPressEvent('Delete', handleDeleteKey); useTauriEvent( 'focus_sidebar', () => { if (hidden) return; - focusActiveRequest(); + // Select 0 index on focus if none selected + focusActiveRequest(selectedIndex ?? 0); }, [focusActiveRequest, hidden], ); @@ -112,14 +128,6 @@ export const Sidebar = memo(function Sidebar({ className }: Props) { [hasFocus, requests, selectedIndex], ); - useKeyPressEvent('Backspace', (e) => { - if (!hasFocus) return; - e.preventDefault(); - const selectedRequest = requests[selectedIndex ?? -1]; - if (selectedRequest === undefined) return; - deleteAnyRequest.mutate(selectedRequest.id); - }); - return (
) => { + async (e: React.KeyboardEvent) => { e.stopPropagation(); switch (e.key) { case 'Enter':