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. 22
      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 fzi from 'fzi'
import { evaluate as eval_math } from 'mathjs'
import { cloneDeep } from 'lodash'
export default new class api
@ -32,6 +33,15 @@ export default new class api
p omit(new_link, "icon")
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 go
try
@ -62,8 +72,9 @@ export default new class api
sort_links!
def increment_link_frequency link
link.frequency += 1
try
await db.links.update link.id, { frequency: link.frequency + 1 }
await put_link link
catch e
err "putting link", e

3
app/client.imba

@ -57,6 +57,9 @@ tag app
unless global.localStorage.fuzzyhome_visited
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
try

15
app/components/app-bang.imba

@ -1,5 +1,9 @@
tag app-bang
def unset_active_bang
state.active_bang = no
api.sort_links!
get bang
state.active_bang or config.data.default_bang
@ -13,8 +17,7 @@ tag app-bang
def render
<self>
css w:100% d:flex fld:column gap:10px
css w:100% d:flex fld:column gap:15px
<app-tips>
@ -46,8 +49,8 @@ tag app-bang
if state.active_bang
<.tip
@click=(state.active_bang = no)
@hotkey('esc').capture.if(!state.loading)=(state.active_bang = no)
@click=unset_active_bang
@hotkey('esc').capture.if(!state.loading)=unset_active_bang
>
<.tip-hotkey> "Esc"
<.tip-content> "Back"
@ -87,7 +90,7 @@ tag app-bang
unless $tips-more.active
<.bang.selected@click=handle_bang>
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>
css d:flex fl:1
@ -96,7 +99,7 @@ tag app-bang
css w:20px h:20px mr:10px rd:3px
<.display-name> encoded_bang_query
css c:#FAD4AB fs:20px word-break:break-all
css fs:20px word-break:break-all
<.link-right>
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!
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."
config.data.default_bang = link
save_config!
state.query = prior_query
prior_query = ''
config.save!
api.sort_links!
close!
def handle_delete
try
@ -78,7 +77,6 @@ tag app-edit
if link.is_bang
<.tip @click=handle_click_set_default_bang>
css fl:2
<.tip-hotkey> "Click"
<.tip-content> "Set Default Bang"
<.tip

2
app/components/app-home.imba

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

20
app/components/app-links.imba

@ -14,7 +14,7 @@ tag app-links
def render
<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>
@ -69,15 +69,6 @@ tag app-links
<.tip-hotkey> "Shift + Tab"
<.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
@click.if(!loading)=api.handle_cut
>
@ -88,6 +79,15 @@ tag app-links
<.tip-hotkey> "Cut (If No Selection)"
<.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-hotkey> "Paste (If Input Empty)"
<.tip-content> "Instant Search"

14
app/components/app-settings.imba

@ -125,21 +125,23 @@ tag app-settings
<.settings-button
@click.if(!loading)=handle_click_github
> "GITHUB"
<.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"
<.settings-button
@click=handle_click_toggle_buttons
>
<.settings-button @click=handle_click_toggle_buttons>
config.data.enable_buttons ? "DISABLE BUTTONS" : "ENABLE BUTTONS"
<.settings-container>
<.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
>

22
app/components/app-tips.imba

@ -28,18 +28,24 @@ tag app-tips
css >>> .tip-content
pt:2px fs:14px c:purple3
<self[d:none]=config.data.enable_tips>
<self[d:none]=!config.data.enable_tips>
<slot>
tag app-tips-more < app-tips
get render? do mounted?
def mount
active = no
get hide do !active
def toggle
active = !active
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:10px
<self[d:none]=!config.data.enable_tips>
css d:flex fld:column gap:15px
<@click=toggle>
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">
<.more>
css d:flex fld:column gap:10px
if hide
css d:flex fld:column gap:15px
if hidden
css d:none
<slot>

4
app/config.imba

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

Loading…
Cancel
Save