Browse Source

refactor

main
familyfriendlymikey 2 years ago
parent
commit
3e735b3db5
  1. 3
      app/api.imba
  2. 2
      app/components/app-link.imba
  3. 68
      app/components/app-links.imba
  4. 1
      app/state.imba

3
app/api.imba

@ -175,3 +175,6 @@ export default new class api
def decrement_link_selection_index def decrement_link_selection_index
set_link_selection_index Math.max(0, state.link_selection_index - 1) set_link_selection_index Math.max(0, state.link_selection_index - 1)
def navigate link
await increment_link_frequency link
window.location.href = link.url

2
app/components/app-link.imba

@ -3,7 +3,7 @@ tag app-link
def render def render
<self <self
@pointerover=api.set_link_selection_index(index) @pointerover=api.set_link_selection_index(index)
@click.prevent=handle_click_link(link) @click=handle_click
.selected=(index is state.link_selection_index) .selected=(index is state.link_selection_index)
> >
css d:flex fld:row jc:space-between ai:center css d:flex fld:row jc:space-between ai:center

68
app/components/app-links.imba

@ -2,8 +2,6 @@ import { evaluate as eval_math } from 'mathjs'
tag app-links tag app-links
active_bang = no
def mount def mount
p document p document
$links-input.focus! $links-input.focus!
@ -53,26 +51,19 @@ tag app-links
api.set_link_selection_index 0 api.set_link_selection_index 0
api.sort_links! api.sort_links!
def handle_click_link link def handle_click_link
navigate link if state.active_bang or state.sorted_links.length < 1
def navigate link
await increment_link_frequency link
window.location.href = link.url
def handle_return
if active_bang or state.sorted_links.length < 1
return handle_bang! return handle_bang!
let link = api.selected_link let link = api.selected_link
if link.is_bang if link.is_bang
state.query = '' state.query = ''
active_bang = link state.active_bang = link
else else
navigate link api.navigate link
def handle_del def handle_del
if state.query.length < 1 if state.query.length < 1
active_bang = no state.active_bang = no
api.sort_links! api.sort_links!
def handle_click_delete link def handle_click_delete link
@ -142,7 +133,6 @@ tag app-links
@keydown.del.if(!state.loading)=handle_del @keydown.del.if(!state.loading)=handle_del
@input.if(!state.loading)=handle_input @input.if(!state.loading)=handle_input
@paste.if(!state.loading)=handle_paste @paste.if(!state.loading)=handle_paste
@blur=this.focus
@cut=handle_cut @cut=handle_cut
disabled=state.loading disabled=state.loading
> >
@ -157,49 +147,25 @@ tag app-links
<svg src="../assets/settings.svg"> <svg src="../assets/settings.svg">
if config.data.enable_tips if config.data.enable_tips
if active_bang if state.active_bang
<.tips> <.tips>
<.tip@click=handle_search> <.tip
<.tip-hotkey> "Return" @click=(state.active_bang = no)
<.tip-content> "Search With Query" @hotkey('esc').capture.if(!state.loading)=(state.active_bang = no)
<.tip@click=exit_bang>
<.tip-hotkey> "Esc"
<.tip-content> "Exit Bang"
<.tip[jc:center ta:center fl:2 px:15px]
@click=handle_shift_return
>
<.tip-hotkey> "Shift + Return"
<.tip-content[of:hidden text-overflow:ellipsis white-space:nowrap]>
<span> "Add New Link"
<span[ws:pre]> " "
let sq = state.query.trim!.split /\s+/
if sq.length >= 2
let url = sq.pop!
<span> '"'
<span> sq.join ' '
<span[ws:pre]> ' '
<span[c:blue3]> url
<span> '"'
else
<span> '"'
<span> sq.join ' '
<span> '"'
<.tip[jc:end ta:right fl:1]
@click=handle_shift_backspace
> >
<.tip-hotkey> "Tab" <.tip-hotkey> "Esc"
<.tip-content> "Select Next History Item" <.tip-content> "Back"
else else
<.tips> <.tips>
<.tip @click=handle_return> <.tip
@click=handle_click_link
@hotkey('return').force.if(!loading)=handle_click_link
>
<.tip-hotkey> "Return" <.tip-hotkey> "Return"
<.tip-content> "Navigate To Link" <.tip-content> "Navigate To Link"
@ -225,8 +191,8 @@ tag app-links
css d:flex fld:column jc:flex-start css d:flex fld:column jc:flex-start
fl:1 w:100% ofy:auto pt:15px fl:1 w:100% ofy:auto pt:15px
if not viewing_community_links and (active_bang or state.sorted_links.length < 1) if not viewing_community_links and (state.active_bang or state.sorted_links.length < 1)
<app-bang data=active_bang> <app-bang data=state.active_bang>
else else
for link, index in state.sorted_links for link, index in state.sorted_links
<app-link link=link index=index> <app-link link=link index=index>

1
app/state.imba

@ -4,4 +4,5 @@ export default {
sorted_links: [] sorted_links: []
loading: no loading: no
link_selection_index: 0 link_selection_index: 0
active_bang: no
} }

Loading…
Cancel
Save