From 3b016afb8598653c57d594df531bc1db480cab48 Mon Sep 17 00:00:00 2001 From: familyfriendlymikey Date: Sat, 3 Sep 2022 19:25:27 -0400 Subject: [PATCH] refactor --- app/components/app-bang.imba | 18 ++-- app/components/app-community-links.imba | 108 +++++++++++++----------- app/components/app-edit.imba | 12 +-- app/components/app-links.imba | 20 ++--- app/components/app-settings.imba | 41 ++++----- 5 files changed, 103 insertions(+), 96 deletions(-) diff --git a/app/components/app-bang.imba b/app/components/app-bang.imba index 0f3d379..8775c88 100644 --- a/app/components/app-bang.imba +++ b/app/components/app-bang.imba @@ -1,9 +1,9 @@ tag app-bang get tips - let tips = [] + let result = [] - tips.push <> + result.push <> <.tip @click=api.handle_bang @hotkey('return').capture.if(!state.loading)=api.handle_bang @@ -11,7 +11,7 @@ tag app-bang <.tip-hotkey> "Return" <.tip-content> "Search" - tips.push <> + result.push <> <.tip @click=api.handle_add_link @hotkey('shift+return').capture.if(!state.loading)=api.handle_add_link @@ -29,7 +29,7 @@ tag app-bang else "\"{sq.join " "}\"" - tips.push <> + result.push <> if state.active_bang <.tip @click=api.unset_active_bang @@ -42,7 +42,7 @@ tag app-bang <.tip-hotkey> "Paste (If Input Empty)" <.tip-content> "Instant Search" - tips.push <> + result.push <> <.tip @click.if(!state.loading)=api.toggle_effective_names @hotkey('tab').capture.if(!state.loading)=api.toggle_effective_names @@ -50,7 +50,7 @@ tag app-bang <.tip-hotkey> "Tab" <.tip-content> "Toggle Effective Names" - tips.push <> + result.push <> <.tip @click.if(!loading)=api.handle_cut> if api.math_result <.tip-hotkey> "Cut (Math, If No Selection)" @@ -59,7 +59,7 @@ tag app-bang <.tip-hotkey> "Cut (If No Selection)" <.tip-content> "Cut All Text" - tips.push <> + result.push <> <.tip @click.if(!state.loading)=refs.settings.open @hotkey('shift+tab').capture.if(!state.loading)=refs.settings.open @@ -68,12 +68,12 @@ tag app-bang <.tip-content> "Toggle Settings" if state.active_bang - tips.push <> + result.push <> <.tip.noclick> <.tip-hotkey> "Paste (If Input Empty)" <.tip-content> "Instant Search" - tips + result def render diff --git a/app/components/app-community-links.imba b/app/components/app-community-links.imba index 9c3de74..0f1b07d 100644 --- a/app/components/app-community-links.imba +++ b/app/components/app-community-links.imba @@ -1,11 +1,15 @@ let p = console.log import links from '../assets/community_links' +import fzi from 'fzi' tag app-community-links - active = no + active = yes selection_index = 0 + def mount + $cli.focus! + def open active = yes @@ -29,55 +33,57 @@ tag app-community-links await api.reload_db! imba.commit! + get tips + let result = [] + + result.push <> + <.tip @click=close> + <.tip-hotkey> "Esc" + <.tip-content> "Exit Community Links" + + result.push <> + <.tip @click=handle_shift_return> + <.tip-hotkey> "Shift + Return Or Click" + <.tip-content> "Add To Your Links" + + result.push <> + <.tip.noclick + @hotkey('down').capture.if(!state.loading)=increment_selection_index + @hotkey('up').capture.if(!state.loading)=decrement_selection_index + > + <.tip-hotkey> "Up/Down Arrow" + <.tip-content> "Move Selection" + + result + def render - - - css self - d:flex fld:column jc:start fl:1 - w:100% ofy:auto pt:15px - - css .link - d:flex fld:row jc:space-between ai:center - px:16px py:11px rd:5px cursor:pointer c:blue3 - min-height:35px - - css .link-left - fl:1 - - css .link-right - fl:1 - overflow-wrap:anywhere - word-break:break-all - - css .bang - c:#FAD4AB - - css .selected - bg:blue3/5 - - <.tips> - <.tip[jc:start ta:center fl:1] - @click=handle_esc - > - <.tip-hotkey> "Esc" - <.tip-content> "Exit Community Links" - <.tip[jc:end ta:center fl:1] - @click=handle_shift_return - > - <.tip-hotkey> "Shift + Return" - <.tip-content> "Add To Your Links" - - for link_text, index in links - <.link - .selected=(selection_index == index) - @pointerover=(selection_index = index) - @click=(add_community_link(link_text)) - > - let { url, rest } = get_link_obj link_text - <.link-left .bang=rest.startsWith("!")> rest - <.link-right> url + + css d:flex fld:column jc:start gap:15px fl:1 w:100% ofy:hidden + +
+ + + + + <.links> + css ofy:auto + + for link_text, index in links + <.link + .selected=(selection_index == index) + @pointerover=(selection_index = index) + @click=(add_community_link(link_text)) + > + css d:flex fld:row jc:space-between ai:center px:16px + py:11px rd:5px cursor:pointer c:blue3 min-height:35px + + let { url, rest } = get_link_obj link_text + + <.link-left> rest + css fl:1 + if rest.startsWith("!") + css c:#FAD4AB + + <.link-right> url + css fl:1 overflow-wrap:anywhere word-break:break-all diff --git a/app/components/app-edit.imba b/app/components/app-edit.imba index 561c00a..29191f4 100644 --- a/app/components/app-edit.imba +++ b/app/components/app-edit.imba @@ -33,9 +33,9 @@ tag app-edit err "saving link", e get tips - let tips = [] + let result = [] - tips.push <> + result.push <> <.tip @click=handle_delete @hotkey('shift+backspace').capture.if(!state.loading)=handle_delete @@ -43,7 +43,7 @@ tag app-edit <.tip-hotkey> "Shift + Backspace" <.tip-content> "Delete Link" - tips.push <> + result.push <> <.tip @click=save @hotkey('return').capture.if(!state.loading)=save @@ -52,12 +52,12 @@ tag app-edit <.tip-content> "Update Link" if link.is_bang - tips.push <> + result.push <> <.tip @click=handle_click_set_default_bang> <.tip-hotkey> "Click" <.tip-content> "Set Default Bang" - tips.push <> + result.push <> <.tip @click=close @hotkey('esc').capture.if(!state.loading)=close @@ -65,7 +65,7 @@ tag app-edit <.tip-hotkey> "Esc" <.tip-content> "Cancel" - tips + result def render diff --git a/app/components/app-links.imba b/app/components/app-links.imba index a15ef4f..7d884fd 100644 --- a/app/components/app-links.imba +++ b/app/components/app-links.imba @@ -12,9 +12,9 @@ tag app-links refs.edit.open api.selected_link get tips - let tips = [] + let result = [] - tips.push <> + result.push <> <.tip @click=api.handle_add_link @hotkey('shift+return').capture.if(!state.loading)=api.handle_add_link @@ -32,7 +32,7 @@ tag app-links else "\"{sq.join " "}\"" - tips.push <> + result.push <> <.tip @click=api.handle_click_link @hotkey('return').force.if(!loading)=api.handle_click_link @@ -40,7 +40,7 @@ tag app-links <.tip-hotkey> "Return" <.tip-content> "Navigate To Link" - tips.push <> + result.push <> <.tip @click=handle_edit @hotkey('shift+backspace').capture.if(!state.loading)=handle_edit @@ -48,7 +48,7 @@ tag app-links <.tip-hotkey> "Shift + Backspace" <.tip-content> "Edit Link" - tips.push <> + result.push <> <.tip @click.if(!state.loading)=api.toggle_effective_names @hotkey('tab').capture.if(!state.loading)=api.toggle_effective_names @@ -56,7 +56,7 @@ tag app-links <.tip-hotkey> "Tab" <.tip-content> "Toggle Effective Names" - tips.push <> + result.push <> <.tip @click.if(!state.loading)=refs.settings.open @hotkey('shift+tab').capture.if(!state.loading)=refs.settings.open @@ -64,7 +64,7 @@ tag app-links <.tip-hotkey> "Shift + Tab" <.tip-content> "Toggle Settings" - tips.push <> + result.push <> <.tip @click.if(!loading)=api.handle_cut> if api.math_result <.tip-hotkey> "Cut (Math, If No Selection)" @@ -73,7 +73,7 @@ tag app-links <.tip-hotkey> "Cut (If No Selection)" <.tip-content> "Cut All Text" - tips.push <> + result.push <> <.tip.noclick @hotkey('down').capture.if(!state.loading)=api.increment_link_selection_index @hotkey('up').capture.if(!state.loading)=api.decrement_link_selection_index @@ -81,12 +81,12 @@ tag app-links <.tip-hotkey> "Up/Down Arrow" <.tip-content> "Move Selection" - tips.push <> + result.push <> <.tip.noclick> <.tip-hotkey> "Paste (If Input Empty)" <.tip-content> "Instant Search" - tips + result def render diff --git a/app/components/app-settings.imba b/app/components/app-settings.imba index 1b83555..d7a2741 100644 --- a/app/components/app-settings.imba +++ b/app/components/app-settings.imba @@ -76,7 +76,8 @@ tag app-settings def render - + + css w:100% css .settings-container d:flex fld:row jc:space-around ai:center @@ -94,19 +95,23 @@ tag app-settings if refs.community-links.active + else <.settings-container> + <.settings-button @click=close @hotkey("esc")=close @hotkey("shift+tab")=close > "BACK" + <.settings-container> - <.settings-button - @click.if(!loading)=$community-links.open - > + + <.settings-button @click.if(!loading)=(refs.community-links.open! and close!)> "VIEW COMMUNITY LINKS" + <.settings-container> + "IMPORT" - <.settings-button - @click.if(!loading)=handle_click_export - > "EXPORT" + + <.settings-button @click.if(!loading)=handle_click_export> + "EXPORT" + <.settings-container> - <.settings-button - @click.if(!loading)=handle_click_github - > "TUTORIAL" - <.settings-button - @click.if(!loading)=handle_click_github - > "GITHUB" + + <.settings-button @click.if(!loading)=handle_click_github> + "TUTORIAL" + + <.settings-button @click.if(!loading)=handle_click_github> + "GITHUB" <.settings-container> <.settings-button @click=handle_click_toggle_tips> - let t= p config.data config.data.enable_tips ? "DISABLE TIPS" : "ENABLE TIPS" <.settings-button @click=handle_click_toggle_buttons> @@ -137,12 +142,8 @@ tag app-settings <.settings-container> - <.settings-button - @click=handle_click_toggle_search_on_paste - > + <.settings-button @click=handle_click_toggle_search_on_paste> config.data.enable_search_on_paste ? "DISABLE SEARCH ON PASTE" : "ENABLE SEARCH ON PASTE" - <.settings-button - @click.if(!loading)=handle_toggle_light_theme - > + <.settings-button @click.if(!loading)=handle_toggle_light_theme> config.data.enable_dark_theme ? "DISABLE DARK THEME" : "ENABLE DARK THEME"