Browse Source

refactor

main
familyfriendlymikey 2 years ago
parent
commit
710a643076
  1. 13
      app/api.imba
  2. 3
      app/client.imba
  3. 15
      app/components/app-bang.imba
  4. 8
      app/components/app-edit.imba
  5. 2
      app/components/app-home.imba
  6. 20
      app/components/app-links.imba
  7. 14
      app/components/app-settings.imba
  8. 24
      app/components/app-tips.imba
  9. 4
      app/config.imba

13
app/api.imba

@ -9,6 +9,7 @@ import { omit, orderBy } from 'lodash'
import { nanoid } from 'nanoid' import { nanoid } from 'nanoid'
import fzi from 'fzi' import fzi from 'fzi'
import { evaluate as eval_math } from 'mathjs' import { evaluate as eval_math } from 'mathjs'
import { cloneDeep } from 'lodash'
export default new class api export default new class api
@ -32,6 +33,15 @@ export default new class api
p omit(new_link, "icon") p omit(new_link, "icon")
return new_link return new_link
def put_link link
try
await db.links.update link.id, link
if config.data.default_bang.id is link.id
config.set_default_bang link
await reload_db!
catch e
err "putting link", e
def delete_link link def delete_link link
def go def go
try try
@ -62,8 +72,9 @@ export default new class api
sort_links! sort_links!
def increment_link_frequency link def increment_link_frequency link
link.frequency += 1
try try
await db.links.update link.id, { frequency: link.frequency + 1 } await put_link link
catch e catch e
err "putting link", e err "putting link", e

3
app/client.imba

@ -57,6 +57,9 @@ tag app
unless global.localStorage.fuzzyhome_visited unless global.localStorage.fuzzyhome_visited
await api.add_initial_links! await api.add_initial_links!
try
let default_bang = await api.add_link '!google search https://www.google.com/search?q='
config.data.default_bang = default_bang
global.localStorage.fuzzyhome_visited = yes global.localStorage.fuzzyhome_visited = yes
try try

15
app/components/app-bang.imba

@ -1,5 +1,9 @@
tag app-bang tag app-bang
def unset_active_bang
state.active_bang = no
api.sort_links!
get bang get bang
state.active_bang or config.data.default_bang state.active_bang or config.data.default_bang
@ -13,8 +17,7 @@ tag app-bang
def render def render
<self> <self>
css w:100% d:flex fld:column gap:10px css w:100% d:flex fld:column gap:15px
<app-tips> <app-tips>
@ -46,8 +49,8 @@ tag app-bang
if state.active_bang if state.active_bang
<.tip <.tip
@click=(state.active_bang = no) @click=unset_active_bang
@hotkey('esc').capture.if(!state.loading)=(state.active_bang = no) @hotkey('esc').capture.if(!state.loading)=unset_active_bang
> >
<.tip-hotkey> "Esc" <.tip-hotkey> "Esc"
<.tip-content> "Back" <.tip-content> "Back"
@ -87,7 +90,7 @@ tag app-bang
unless $tips-more.active unless $tips-more.active
<.bang.selected@click=handle_bang> <.bang.selected@click=handle_bang>
css d:flex fld:row jc:space-between ai:center css d:flex fld:row jc:space-between ai:center
px:16px py:11px rd:5px cursor:pointer c:blue3 px:16px py:11px rd:5px cursor:pointer c:#FAD4AB
<.link-left> <.link-left>
css d:flex fl:1 css d:flex fl:1
@ -96,7 +99,7 @@ tag app-bang
css w:20px h:20px mr:10px rd:3px css w:20px h:20px mr:10px rd:3px
<.display-name> encoded_bang_query <.display-name> encoded_bang_query
css c:#FAD4AB fs:20px word-break:break-all css fs:20px word-break:break-all
<.link-right> <.link-right>
css d:flex fld:row jc:space-between ai:center css d:flex fld:row jc:space-between ai:center

8
app/components/app-edit.imba

@ -16,13 +16,12 @@ tag app-edit
imba.commit! imba.commit!
def handle_click_set_default_bang def handle_click_set_default_bang
if link.is_bang isnt true unless link.is_bang
return err "setting default bang", "Link is not a bang." return err "setting default bang", "Link is not a bang."
config.data.default_bang = link config.data.default_bang = link
save_config! config.save!
state.query = prior_query
prior_query = ''
api.sort_links! api.sort_links!
close!
def handle_delete def handle_delete
try try
@ -78,7 +77,6 @@ tag app-edit
if link.is_bang if link.is_bang
<.tip @click=handle_click_set_default_bang> <.tip @click=handle_click_set_default_bang>
css fl:2 css fl:2
<.tip-hotkey> "Click"
<.tip-content> "Set Default Bang" <.tip-content> "Set Default Bang"
<.tip <.tip

2
app/components/app-home.imba

@ -24,7 +24,7 @@ tag app-home
def render def render
<self> <self>
css w:100% d:flex fld:column gap:10px ofy:hidden css w:100% d:flex fld:column ofy:hidden gap:20px
<.header> <.header>
css d:flex fld:row w:100% css d:flex fld:row w:100%

20
app/components/app-links.imba

@ -14,7 +14,7 @@ tag app-links
def render def render
<self> <self>
css w:100% d:flex fld:column gap:10px ofy:hidden css w:100% d:flex fld:column gap:15px ofy:hidden
<app-tips> <app-tips>
@ -69,15 +69,6 @@ tag app-links
<.tip-hotkey> "Shift + Tab" <.tip-hotkey> "Shift + Tab"
<.tip-content> "Toggle Settings" <.tip-content> "Toggle Settings"
<.tip.noclick
@hotkey('down').capture.if(!state.loading)=api.increment_link_selection_index
@hotkey('up').capture.if(!state.loading)=api.decrement_link_selection_index
>
<.tip-hotkey> "Up/Down Arrow"
<.tip-content> "Move Selection"
<.tip-row>
<.tip <.tip
@click.if(!loading)=api.handle_cut @click.if(!loading)=api.handle_cut
> >
@ -88,6 +79,15 @@ tag app-links
<.tip-hotkey> "Cut (If No Selection)" <.tip-hotkey> "Cut (If No Selection)"
<.tip-content> "Cut All Text" <.tip-content> "Cut All Text"
<.tip-row>
<.tip.noclick
@hotkey('down').capture.if(!state.loading)=api.increment_link_selection_index
@hotkey('up').capture.if(!state.loading)=api.decrement_link_selection_index
>
<.tip-hotkey> "Up/Down Arrow"
<.tip-content> "Move Selection"
<.tip.noclick> <.tip.noclick>
<.tip-hotkey> "Paste (If Input Empty)" <.tip-hotkey> "Paste (If Input Empty)"
<.tip-content> "Instant Search" <.tip-content> "Instant Search"

14
app/components/app-settings.imba

@ -125,21 +125,23 @@ tag app-settings
<.settings-button <.settings-button
@click.if(!loading)=handle_click_github @click.if(!loading)=handle_click_github
> "GITHUB" > "GITHUB"
<.settings-container> <.settings-container>
<.settings-button
@click=handle_click_toggle_tips <.settings-button @click=handle_click_toggle_tips>
> let t= p config.data
config.data.enable_tips ? "DISABLE TIPS" : "ENABLE TIPS" config.data.enable_tips ? "DISABLE TIPS" : "ENABLE TIPS"
<.settings-button
@click=handle_click_toggle_buttons <.settings-button @click=handle_click_toggle_buttons>
>
config.data.enable_buttons ? "DISABLE BUTTONS" : "ENABLE BUTTONS" config.data.enable_buttons ? "DISABLE BUTTONS" : "ENABLE BUTTONS"
<.settings-container> <.settings-container>
<.settings-button <.settings-button
@click=handle_click_toggle_search_on_paste @click=handle_click_toggle_search_on_paste
> >
config.data.enable_search_on_paste ? "DISABLE SEARCH ON PASTE" : "ENABLE SEARCH ON PASTE" config.data.enable_search_on_paste ? "DISABLE SEARCH ON PASTE" : "ENABLE SEARCH ON PASTE"
<.settings-button <.settings-button
@click.if(!loading)=handle_toggle_light_theme @click.if(!loading)=handle_toggle_light_theme
> >

24
app/components/app-tips.imba

@ -28,18 +28,24 @@ tag app-tips
css >>> .tip-content css >>> .tip-content
pt:2px fs:14px c:purple3 pt:2px fs:14px c:purple3
<self[d:none]=config.data.enable_tips> <self[d:none]=!config.data.enable_tips>
<slot> <slot>
tag app-tips-more < app-tips tag app-tips-more < app-tips
active = no get render? do mounted?
get hide do !active
def toggle
active = !active
<self[d:none]=config.data.enable_tips> def mount
css d:flex fld:column gap:10px active = no
imba.commit!
get hidden do !active
toggle = do active = !active
open = do active = yes
close = do active = no
<self[d:none]=!config.data.enable_tips>
css d:flex fld:column gap:15px
<@click=toggle> <@click=toggle>
css w:100% d:flex ja:center c:purple3 rdb:4px cursor:pointer css w:100% d:flex ja:center c:purple3 rdb:4px cursor:pointer
@ -55,7 +61,7 @@ tag app-tips-more < app-tips
<svg src="../assets/chevron-up.svg"> <svg src="../assets/chevron-up.svg">
<.more> <.more>
css d:flex fld:column gap:10px css d:flex fld:column gap:15px
if hide if hidden
css d:none css d:none
<slot> <slot>

4
app/config.imba

@ -23,5 +23,9 @@ export default new class config
p "config:", this.data p "config:", this.data
def set_default_bang bang
data.default_bang = bang
save!
def save def save
global.localStorage.fuzzyhome_config = JSON.stringify(this.data) global.localStorage.fuzzyhome_config = JSON.stringify(this.data)

Loading…
Cancel
Save