From a7fbb8f95a98fada7003e2c2141764b04ea75f33 Mon Sep 17 00:00:00 2001 From: familyfriendlymikey Date: Tue, 6 Sep 2022 17:40:16 -0400 Subject: [PATCH] refactor tips for , abstract tip into --- app/components/app-edit.imba | 62 ++++++++++++++++-------------- app/components/app-links.imba | 9 ++--- app/components/app-tips.imba | 72 +++++++++++++++++------------------ 3 files changed, 72 insertions(+), 71 deletions(-) diff --git a/app/components/app-edit.imba b/app/components/app-edit.imba index cb82bb9..efbf377 100644 --- a/app/components/app-edit.imba +++ b/app/components/app-edit.imba @@ -34,36 +34,42 @@ tag app-edit get tips let result = [] - - result.push <> - <.tip - @click=handle_delete - @hotkey('shift+backspace').force=handle_delete - > - <.tip-hotkey> "Shift + Backspace" - <.tip-content> "Delete Link" - - result.push <> - <.tip - @click=save - @hotkey('return').force=save - > - <.tip-hotkey> "Return" - <.tip-content> "Update Link" + let temp + + temp = { + click_handler: handle_delete.bind(this) + hotkey_handler: handle_delete.bind(this) + hotkey: 'shift+backspace' + hotkey_display_name: "Shift + Backspace" + content: "Delete Link" + } + result.push temp + + temp = { + click_handler: save.bind(this) + hotkey_handler: save.bind(this) + hotkey: 'return' + hotkey_display_name: "Return" + content: "Update Link" + } + result.push temp if link.is_bang - result.push <> - <.tip @click=handle_click_set_default_bang> - <.tip-hotkey> "Click" - <.tip-content> "Set Default Bang" - - result.push <> - <.tip - @click=close - @hotkey('esc').force=close - > - <.tip-hotkey> "Esc" - <.tip-content> "Cancel" + temp = { + click_handler: handle_click_set_default_bang.bind(this) + hotkey_display_name: "Click" + content: "Set Default Bang" + } + result.push temp + + temp = { + click_handler: close.bind(this) + hotkey_handler: close.bind(this) + hotkey: 'esc' + hotkey_display_name: "Esc" + content: "Cancel" + } + result.push temp result diff --git a/app/components/app-links.imba b/app/components/app-links.imba index d656f25..73a6897 100644 --- a/app/components/app-links.imba +++ b/app/components/app-links.imba @@ -95,9 +95,8 @@ tag app-links - unless $tips.show_more - <.links> - css ofy:scroll - for link, index in state.sorted_links - + <.links> + css ofy:scroll + for link, index in state.sorted_links + diff --git a/app/components/app-tips.imba b/app/components/app-tips.imba index d15a111..5a83d5a 100644 --- a/app/components/app-tips.imba +++ b/app/components/app-tips.imba @@ -1,5 +1,32 @@ import { chunk, fill } from 'lodash' +tag app-tip + + + css d:flex fld:column jc:start fl:1 + bdr:1px solid + bc:$tip-bc + min-width:0 ta:center p:10px + cursor:pointer transition:background 100ms + @first ta:left rdl:3px + @last ta:right bd:none rdr:3px + @hover bg:$tip-hover-c + if tip.placeholder or not tip.click_handler + css + @hover @important cursor:auto bg:none + + if tip.hotkey_handler and tip.hotkey + <@hotkey(tip.hotkey).force=tip.hotkey_handler> + css d:none + + <.tip-hotkey> tip.hotkey_display_name + css fs:12px c:$tip-hotkey-c + + <.tip-content> tip.content + css pt:2px fs:14px c:$tip-content-c + tag app-tips def unmount @@ -19,45 +46,20 @@ tag app-tips pad(chunks[-1]) chunks - css >>> .tip-row - d:flex fld:row w:100% fl:1 - fs:20px fs:14px - jc:end ta:center - - css >>> .tip - d:flex fld:column jc:start fl:1 - bdr:1px solid - bc:$tip-bc - min-width:0 ta:center p:10px - cursor:pointer transition:background 100ms - @first ta:left rdl:3px - @last ta:right bd:none rdr:3px - @hover bg:$tip-hover-c - - css >>> .tip.noclick, .tip.placeholder - @hover bg:none cursor:auto - - css >>> .tip-hotkey - fs:12px c:$tip-hotkey-c - - css >>> .tip-content - pt:2px fs:14px c:$tip-content-c - def render let chunks = get_chunks! css d:flex fld:column gap:15px + css .tip-row + d:flex fld:row w:100% fl:1 + fs:20px fs:14px + jc:end ta:center + <.tip-row> for tip in chunks[0] - <.tip - .noclick=(not tip.click_handler) - @click.if(tip.click_handler)=tip.click_handler - @hotkey(tip.hotkey).if(tip.hotkey_handler and tip.hotkey).force=tip.hotkey_handler - > - <.tip-hotkey> tip.hotkey_display_name - <.tip-content> tip.content + if chunks.length > 1 @@ -82,10 +84,4 @@ tag app-tips for row in chunks.slice(1) <.tip-row> for tip in row - <.tip - .noclick=(not tip.click_handler) - @click.if(tip.click_handler)=tip.click_handler - @hotkey(tip.hotkey).if(tip.hotkey_handler and tip.hotkey).force=tip.hotkey_handler - > - <.tip-hotkey> tip.hotkey_display_name - <.tip-content> tip.content +