From 3ac14d7dcad0f58adccf114cadc4626421f0e3b5 Mon Sep 17 00:00:00 2001 From: familyfriendlymikey Date: Mon, 5 Sep 2022 17:45:37 -0400 Subject: [PATCH] polish bang history --- app/api.imba | 46 ++++++++++++++++---- app/components/app-bang.imba | 74 ++++++++++++++++++-------------- app/components/app-home.imba | 3 +- app/components/app-settings.imba | 5 +++ app/config.imba | 1 + 5 files changed, 87 insertions(+), 42 deletions(-) diff --git a/app/api.imba b/app/api.imba index af79bdc..4200bc2 100644 --- a/app/api.imba +++ b/app/api.imba @@ -5,7 +5,7 @@ import db from './db' import state from './state' import config from './config' -import { omit, orderBy } from 'lodash' +import { find, omit, orderBy } from 'lodash' import { nanoid } from 'nanoid' import fzi from 'fzi' import { evaluate as eval_math } from 'mathjs' @@ -36,7 +36,7 @@ export default new class api def put_link link try await db.links.update link.id, link - if config.data.default_bang.id is link.id + if link.is_bang and config.data.default_bang.id is link.id config.set_default_bang link await reload_db! catch e @@ -69,6 +69,14 @@ export default new class api def reload_db state.links = await db.links.toArray() + if state.active_bang + let id = state.active_bang.id + state.active_bang = find state.links, { id } + let id = config.data.default_bang.id + let link = find state.links, { id } + if link + config.data.default_bang = link + config.save! sort_links! def increment_link_frequency link @@ -235,12 +243,10 @@ export default new class api state.active_bang or config.data.default_bang get encoded_bang_query - let history_item = sorted_bang_history[state.bang_selection_index] - "{bang.url}{window.encodeURIComponent(history_item or state.query)}" + "{bang.url}{window.encodeURIComponent(state.query)}" get encoded_bang_query_nourl - let history_item = sorted_bang_history[state.bang_selection_index] - "{window.encodeURIComponent(history_item or state.query)}" + "{window.encodeURIComponent(state.query)}" def update_history bang let text @@ -265,14 +271,19 @@ export default new class api bang.history.splice(i, 1) try await put_link bang + state.bang_selection_index = Math.min state.bang_selection_index, sorted_bang_history.length - 1 catch e err "updating bang history", e def handle_bang + return if state.loading + if state.bang_selection_index > -1 + state.query = sorted_bang_history[state.bang_selection_index] + state.bang_selection_index = -1 + return await increment_link_frequency bang - let to_navigate = encoded_bang_query await update_history bang - window.location.href = to_navigate + window.location.href = encoded_bang_query def unset_active_bang state.active_bang = no @@ -286,3 +297,22 @@ export default new class api get sorted_bang_history fzi.sort state.query, bang.history + + def delete_bang_history + bang.history = [] + try + await put_link bang + state.bang_selection_index = -1 + catch e + err "deleting bang history", e + config.data.default_bang.history = [] + config.save! + + def delete_all_bang_history + return unless window.confirm "Are you sure you want to delete all bang history?" + try + await db.links.toCollection!.modify! do |link| link.history = [] + await reload_db! + catch e + err "deleting some link histories", e + imba.commit! diff --git a/app/components/app-bang.imba b/app/components/app-bang.imba index 8a26d39..d9464ae 100644 --- a/app/components/app-bang.imba +++ b/app/components/app-bang.imba @@ -10,32 +10,23 @@ tag app-bang result.push <> <.tip @click=api.handle_bang - @hotkey('return').capture.if(!state.loading)=api.handle_bang + @hotkey('return').force=api.handle_bang > <.tip-hotkey> "Return" - <.tip-content> "Search History Item" + <.tip-content> "Use History Item" else result.push <> <.tip @click=api.handle_bang - @hotkey('return').capture.if(!state.loading)=api.handle_bang + @hotkey('return').force=api.handle_bang > <.tip-hotkey> "Return" <.tip-content> "Search" - if state.bang_selection_index > -1 - result.push <> - <.tip - @click=api.delete_bang_history_item - @hotkey('shift+backspace').capture.if(!state.loading)=api.delete_bang_history_item - > - <.tip-hotkey> "Shift + Backspace" - <.tip-content> "Delete History Item" - result.push <> <.tip.ellipsis @click=api.handle_add_link - @hotkey('shift+return').capture.if(!state.loading)=api.handle_add_link + @hotkey('shift+return').force=api.handle_add_link > <.tip-hotkey> "Shift + Return" <.tip-content.ellipsis> @@ -50,21 +41,31 @@ tag app-bang else "\"{sq.join " "}\"" - result.push <> - if state.active_bang + if state.bang_selection_index > -1 + result.push <> + <.tip + @click=api.delete_bang_history_item + @hotkey('shift+backspace').force=api.delete_bang_history_item + > + <.tip-hotkey> "Shift + Backspace" + <.tip-content> "Delete History Item" + + if state.active_bang + result.push <> <.tip @click=api.unset_active_bang - @hotkey('esc').capture.if(!state.loading)=api.unset_active_bang + @hotkey('esc').force=api.unset_active_bang > <.tip-hotkey> "Esc" <.tip-content> "Back" - else - <.tip.noclick> - <.tip-hotkey> "Paste (If Input Empty)" - <.tip-content> "Instant Search" result.push <> - <.tip @click.if(!loading)=api.handle_cut> + <.tip@click=(api.delete_bang_history! and $tips.show_more = no)> + <.tip-hotkey> "Click" + <.tip-content> "Delete Bang History" + + result.push <> + <.tip @click=api.handle_cut> if api.math_result <.tip-hotkey> "Cut (Math, If No Selection)" <.tip-content> "Cut Math Result" @@ -72,11 +73,10 @@ tag app-bang <.tip-hotkey> "Cut (If No Selection)" <.tip-content> "Cut All Text" - if state.active_bang - result.push <> - <.tip.noclick> - <.tip-hotkey> "Paste (If Input Empty)" - <.tip-content> "Instant Search" + result.push <> + <.tip.noclick> + <.tip-hotkey> "Paste (If Input Empty)" + <.tip-content> "Instant Search" result @@ -88,17 +88,20 @@ tag app-bang @hotkey("down").force=api.increment_bang_selection_index @hotkey("shift+tab").force=api.decrement_bang_selection_index > - css w:100% d:flex fld:column gap:15px + css w:100% d:flex fld:column gap:15px ofy:hidden unless $tips.show_more - <.bang.selected + <.bang + .selected=(state.bang_selection_index is -1) + [c:#FAD4AB]=(state.bang_selection_index is -1) + @pointerover=(state.bang_selection_index = -1) @click=api.handle_bang > css d:flex fld:row jc:space-between ai:center - px:16px py:11px rd:5px cursor:pointer c:#FAD4AB + px:16px py:11px rd:5px cursor:pointer c:blue3 <.link-left> css d:flex fl:1 ofy:hidden @@ -106,7 +109,7 @@ tag app-bang css w:20px h:20px mr:10px rd:3px - <.display-name> api.encoded_bang_query_nourl + <.display-name> "...{api.encoded_bang_query_nourl}" css fs:20px of:hidden text-overflow:ellipsis <.link-right> @@ -116,9 +119,14 @@ tag app-bang css fs:15px ml:7px <.history> - css d:flex fld:column jc:start ai:center + css d:flex fld:column jc:start ai:center ofy:auto for item, index in api.sorted_bang_history - <.item [c:#FAD4AB]=(state.bang_selection_index is index)> item + <.item + @pointerover=(state.bang_selection_index = index) + @click=api.handle_bang + [c:#FAD4AB]=(state.bang_selection_index is index) + .selected=(state.bang_selection_index is index) + > item css w:100% fs:17px c:blue3 rd:5px p:10px 10px - box-sizing:border-box + box-sizing:border-box cursor:pointer diff --git a/app/components/app-home.imba b/app/components/app-home.imba index 1d7bbfb..7df7c1f 100644 --- a/app/components/app-home.imba +++ b/app/components/app-home.imba @@ -4,7 +4,8 @@ tag app-home $home-input.focus! def blur - setTimeout(&, 100) do $home-input.focus! + # setTimeout(&, 100) do $home-input.focus! + p! def handle_paste e return unless config.data.enable_search_on_paste diff --git a/app/components/app-settings.imba b/app/components/app-settings.imba index cd4fbc7..149f4be 100644 --- a/app/components/app-settings.imba +++ b/app/components/app-settings.imba @@ -144,3 +144,8 @@ tag app-settings <.settings-button @click.if(!loading)=handle_toggle_light_theme> config.data.enable_dark_theme ? "DISABLE DARK THEME" : "ENABLE DARK THEME" + + <.settings-container> + + <.settings-button @click=api.delete_all_bang_history> + "DELETE ALL BANG HISTORY" diff --git a/app/config.imba b/app/config.imba index 5c48560..d3d236a 100644 --- a/app/config.imba +++ b/app/config.imba @@ -23,6 +23,7 @@ export default new class config this.data.default_bang.icon ??= "data:image/x-icon;base64,AAABAAIAEBAAAAEAIABoBAAAJgAAACAgAAABACAAqBAAAI4EAAAoAAAAEAAAACAAAAABACAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///zD9/f2W/f392P39/fn9/f35/f391/39/ZT+/v4uAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/v7+Cf39/Zn///////////////////////////////////////////39/ZX///8IAAAAAAAAAAAAAAAA/v7+Cf39/cH/////+v35/7TZp/92ul3/WKs6/1iqOv9yuFn/rNWd//j79v///////f39v////wgAAAAAAAAAAP39/Zn/////7PXp/3G3WP9TqDT/U6g0/1OoNP9TqDT/U6g0/1OoNP+Or1j//vDo///////9/f2VAAAAAP///zD/////+vz5/3G3V/9TqDT/WKo6/6LQkf/U6cz/1urO/6rUm/+Zo0r/8IZB//adZ////v7///////7+/i79/f2Y/////4nWzf9Lqkj/Vqo4/9Xqzv///////////////////////ebY//SHRv/0hUL//NjD///////9/f2U/f392v////8sxPH/Ebzt/43RsP/////////////////////////////////4roL/9IVC//i1jf///////f391/39/fr/////Cr37/wW8+/+16/7/////////////////9IVC//SFQv/0hUL/9IVC//SFQv/3pnX///////39/fn9/f36/////wu++/8FvPv/tuz+//////////////////SFQv/0hUL/9IVC//SFQv/0hUL/96p7///////9/f35/f392/////81yfz/CrL5/2uk9v///////////////////////////////////////////////////////f392P39/Zn/////ks/7/zdS7P84Rur/0NT6///////////////////////9/f////////////////////////39/Zb+/v4y//////n5/v9WYu3/NUPq/ztJ6/+VnPT/z9L6/9HU+v+WnfT/Ul7t/+Hj/P////////////////////8wAAAAAP39/Z3/////6Or9/1hj7v81Q+r/NUPq/zVD6v81Q+r/NUPq/zVD6v9sdvD////////////9/f2YAAAAAAAAAAD///8K/f39w//////5+f7/paz2/11p7v88Suv/Okfq/1pm7v+iqfX/+fn+///////9/f3B/v7+CQAAAAAAAAAAAAAAAP///wr9/f2d///////////////////////////////////////////9/f2Z/v7+CQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP7+/jL9/f2Z/f392/39/fr9/f36/f392v39/Zj///8wAAAAAAAAAAAAAAAAAAAAAPAPAADAAwAAgAEAAIABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIABAACAAQAAwAMAAPAPAAAoAAAAIAAAAEAAAAABACAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP7+/g3+/v5X/f39mf39/cj9/f3q/f39+f39/fn9/f3q/f39yP39/Zn+/v5W////DAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP7+/iT9/f2c/f399f/////////////////////////////////////////////////////9/f31/f39mv7+/iMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP7+/gn9/f2K/f39+////////////////////////////////////////////////////////////////////////////f39+v39/Yf///8IAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD+/v4k/f390v////////////////////////////////////////////////////////////////////////////////////////////////39/dD///8iAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////MP39/er//////////////////////////+r05v+v16H/gsBs/2WxSf9Wqjj/Vqk3/2OwRv99vWX/pdKV/97u2P////////////////////////////39/ej+/v4vAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP7+/iT9/f3q/////////////////////+v15/+Pxnv/VKk2/1OoNP9TqDT/U6g0/1OoNP9TqDT/U6g0/1OoNP9TqDT/U6g0/36+Z//d7tf///////////////////////39/ej///8iAAAAAAAAAAAAAAAAAAAAAAAAAAD///8K/f390//////////////////////E4bn/XKw+/1OoNP9TqDT/U6g0/1OoNP9TqDT/U6g0/1OoNP9TqDT/U6g0/1OoNP9TqDT/U6g0/1apN/+x0pv///////////////////////39/dD///8IAAAAAAAAAAAAAAAAAAAAAP39/Yv/////////////////////sdij/1OoNP9TqDT/U6g0/1OoNP9TqDT/U6g0/1OoNP9TqDT/U6g0/1OoNP9TqDT/U6g0/1OoNP9TqDT/YKU1/8qOPv/5wZ////////////////////////39/YcAAAAAAAAAAAAAAAD+/v4l/f39+////////////////8Lgt/9TqDT/U6g0/1OoNP9TqDT/U6g0/1OoNP9utlT/n86N/7faqv+426v/pdKV/3u8ZP9UqDX/U6g0/3egN//jiUH/9IVC//SFQv/82MP//////////////////f39+v7+/iMAAAAAAAAAAP39/Z3////////////////q9Ob/W6w+/1OoNP9TqDT/U6g0/1OoNP9nskz/zOXC/////////////////////////////////+Dv2v+osWP/8YVC//SFQv/0hUL/9IVC//WQVP/++fb//////////////////f39mgAAAAD+/v4O/f399v///////////////4LHj/9TqDT/U6g0/1OoNP9TqDT/dblc//L58P/////////////////////////////////////////////8+v/3p3f/9IVC//SFQv/0hUL/9IVC//rIqf/////////////////9/f31////DP7+/ln////////////////f9v7/Cbz2/zOwhv9TqDT/U6g0/2KwRv/v9+z///////////////////////////////////////////////////////738//1kFT/9IVC//SFQv/0hUL/9plg///////////////////////+/v5W/f39nP///////////////4jf/f8FvPv/Bbz7/yG1s/9QqDz/vN2w//////////////////////////////////////////////////////////////////rHqP/0hUL/9IVC//SFQv/0hUL//vDn//////////////////39/Zn9/f3L////////////////R878/wW8+/8FvPv/Bbz7/y7C5P/7/fr//////////////////////////////////////////////////////////////////ere//SFQv/0hUL/9IVC//SFQv/718H//////////////////f39yP39/ez///////////////8cwvv/Bbz7/wW8+/8FvPv/WNL8///////////////////////////////////////0hUL/9IVC//SFQv/0hUL/9IVC//SFQv/0hUL/9IVC//SFQv/0hUL/9IVC//rIqv/////////////////9/f3q/f39+v///////////////we9+/8FvPv/Bbz7/wW8+/993P3///////////////////////////////////////SFQv/0hUL/9IVC//SFQv/0hUL/9IVC//SFQv/0hUL/9IVC//SFQv/0hUL/+cGf//////////////////39/fn9/f36////////////////B737/wW8+/8FvPv/Bbz7/33c/f//////////////////////////////////////9IVC//SFQv/0hUL/9IVC//SFQv/0hUL/9IVC//SFQv/0hUL/9IVC//SFQv/6xaX//////////////////f39+f39/e3///////////////8cwvv/Bbz7/wW8+/8FvPv/WdP8///////////////////////////////////////0hUL/9IVC//SFQv/0hUL/9IVC//SFQv/0hUL/9IVC//SFQv/0hUL/9IVC//vVv//////////////////9/f3q/f39y////////////////0bN/P8FvPv/Bbz7/wW8+/8hrvn/+/v///////////////////////////////////////////////////////////////////////////////////////////////////////////////////39/cj9/f2c////////////////ht/9/wW8+/8FvPv/FZP1/zRJ6/+zuPf//////////////////////////////////////////////////////////////////////////////////////////////////////////////////f39mf7+/lr////////////////d9v7/B7n7/yB38f81Q+r/NUPq/0hV7P/u8P3////////////////////////////////////////////////////////////////////////////////////////////////////////////+/v5X////D/39/ff///////////////9tkPT/NUPq/zVD6v81Q+r/NUPq/2Fs7//y8v7////////////////////////////////////////////09f7//////////////////////////////////////////////////f399f7+/g0AAAAA/f39n////////////////+Tm/P89Suv/NUPq/zVD6v81Q+r/NUPq/1Bc7f/IzPn/////////////////////////////////x8v5/0xY7P+MlPP////////////////////////////////////////////9/f2cAAAAAAAAAAD+/v4n/f39/P///////////////7W69/81Q+r/NUPq/zVD6v81Q+r/NUPq/zVD6v9ZZe7/k5v0/6609/+vtff/lJv0/1pm7v81Q+r/NUPq/zVD6v+GjvL//v7//////////////////////////////f39+/7+/iQAAAAAAAAAAAAAAAD9/f2N/////////////////////6Cn9f81Q+r/NUPq/zVD6v81Q+r/NUPq/zVD6v81Q+r/NUPq/zVD6v81Q+r/NUPq/zVD6v81Q+r/NUPq/zVD6v+BivL////////////////////////////9/f2KAAAAAAAAAAAAAAAAAAAAAP7+/gv9/f3V/////////////////////7W69/8+S+v/NUPq/zVD6v81Q+r/NUPq/zVD6v81Q+r/NUPq/zVD6v81Q+r/NUPq/zVD6v81Q+r/P0zr/7q/+P///////////////////////f390v7+/gkAAAAAAAAAAAAAAAAAAAAAAAAAAP7+/ib9/f3r/////////////////////+Xn/P94gfH/NkTq/zVD6v81Q+r/NUPq/zVD6v81Q+r/NUPq/zVD6v81Q+r/NkTq/3Z/8f/l5/z///////////////////////39/er+/v4kAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP7+/jL9/f3r///////////////////////////k5vz/nqX1/2p08P9IVez/OEbq/zdF6v9GU+z/aHLv/5qh9f/i5Pz////////////////////////////9/f3q////MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP7+/ib9/f3V/////////////////////////////////////////////////////////////////////////////////////////////////f390v7+/iQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///wr9/f2N/f39/P///////////////////////////////////////////////////////////////////////////f39+/39/Yv+/v4JAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD+/v4n/f39n/39/ff//////////////////////////////////////////////////////f399v39/Z3+/v4lAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/v7+Dv7+/lr9/f2c/f39y/39/e39/f36/f39+v39/ez9/f3L/f39nP7+/ln+/v4OAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP/AA///AAD//AAAP/gAAB/wAAAP4AAAB8AAAAPAAAADgAAAAYAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAABgAAAAcAAAAPAAAAD4AAAB/AAAA/4AAAf/AAAP/8AAP//wAP/" this.data.default_bang.id ??= "FEJbsKLUMwHbazbqW3c4i" this.data.default_bang.history ??= [] + this.data.default_bang.is_bang ??= yes p "config:", this.data