Browse Source

refactor

main
familyfriendlymikey 2 years ago
parent
commit
79b1e493fc
  1. 1
      app/api.imba
  2. 13
      app/client.imba
  3. 29
      app/components/app-bang.imba
  4. 74
      app/components/app-edit.imba
  5. 191
      app/components/app-links.imba
  6. 39
      app/components/app-settings.imba
  7. 18
      app/components/app-tips.imba
  8. 4
      app/config.imba
  9. 1
      scripts/config_move.sh

1
app/api.imba

@ -5,7 +5,6 @@ import db from './db'
import state from './state' import state from './state'
import config from './config' import config from './config'
p config
import { omit, orderBy } from 'lodash' import { omit, orderBy } from 'lodash'
import { nanoid } from 'nanoid' import { nanoid } from 'nanoid'
import fzi from 'fzi' import fzi from 'fzi'

13
app/client.imba

@ -1,15 +1,14 @@
let p = console.log let p = console.log
import pkg from '../package.json'
let version = pkg.version
p "fuzzyhome version {version}"
# import sw from './sw.imba?serviceworker' # import sw from './sw.imba?serviceworker'
# navigator..serviceWorker..register(sw).then! do |reg| reg.update! # navigator..serviceWorker..register(sw).then! do |reg| reg.update!
import download from 'downloadjs'
import { nanoid } from 'nanoid' import { nanoid } from 'nanoid'
import { err } from './utils' import { err } from './utils'
import pkg from '../package.json'
let version = pkg.version
p "fuzzyhome version {version}"
import db from './db' import db from './db'
import state from './state' import state from './state'
let refs = {} let refs = {}
@ -33,12 +32,14 @@ extend tag element
api api
get config get config
config config
get p
console.log
get refs get refs
refs refs
get err get err
err err
get version
version
get p
console.log
tag app tag app

29
app/components/app-bang.imba

@ -1,20 +1,35 @@
tag app-bang tag app-bang
get encoded_bang_query get encoded_bang_query
"{active_bang.url}{window.encodeURIComponent(state.query)}" "{bang.url}{window.encodeURIComponent(state.query)}"
def handle_bang def handle_bang
await api.increment_link_frequency state.active_bang await api.increment_link_frequency bang
window.location.href = encoded_bang_query window.location.href = encoded_bang_query
def render def render
<self> <self
.selected
@click=handle_bang
>
css d:flex fld:row jc:space-between ai:center
px:16px py:11px rd:5px cursor:pointer c:#FAD4AB
css .bang-text <.link-left>
tt:none word-break:break-all css d:flex fl:1
<.bang @click=handle_bang> <img.link-icon src=bang.icon>
css w:20px h:20px mr:10px rd:3px
<.display-name> encoded_bang_query
css tt:capitalize fs:20px overflow-wrap:anywhere
css tt:none word-break:break-all
<.link-right>
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 css .buttons-disabled .link-button visibility:hidden
css .selected .link-button visibility:visible
<.frequency> bang.frequency
css fs:15px ml:7px

74
app/components/app-edit.imba

@ -18,7 +18,7 @@ tag app-edit
def handle_click_set_default_bang def handle_click_set_default_bang
if link.is_bang isnt true if link.is_bang isnt true
return err "setting default bang", "Link is not a bang." return err "setting default bang", "Link is not a bang."
config.default_bang = link config.data.default_bang = link
save_config! save_config!
state.query = prior_query state.query = prior_query
prior_query = '' prior_query = ''
@ -56,42 +56,44 @@ tag app-edit
<self> <self>
css d:flex fld:column gap:20px w:100% css d:flex fld:column gap:20px w:100%
<.tips> <app-tips>
<.tip <.tip-row>
@click=close
@hotkey('esc').capture.if(!state.loading)=close <.tip
> @click=close
<.tip-hotkey> "Esc" @hotkey('esc').capture.if(!state.loading)=close
<.tip-content> "Cancel" >
<.tip-hotkey> "Esc"
<.tip <.tip-content> "Cancel"
@click=handle_delete
@hotkey('shift+backspace').capture.if(!state.loading)=handle_delete <.tip
> @click=handle_delete
css fl:2 @hotkey('shift+backspace').capture.if(!state.loading)=handle_delete
<.tip-hotkey> "Shift + Backspace" >
<.tip-content> "Delete Link" css fl:2
<.tip-hotkey> "Shift + Backspace"
if link.is_bang <.tip-content> "Delete Link"
<.tip @click=handle_click_set_default_bang>
if link.is_bang
<.tip @click=handle_click_set_default_bang>
css fl:2
<.tip-hotkey> "Click"
<.tip-content> "Set Default Bang"
<.tip
@click=save
@hotkey('shift+return').capture.if(!state.loading)=save
>
css fl:2 css fl:2
<.tip-hotkey> "Click" <.tip-hotkey> "Return"
<.tip-content> "Set Default Bang" <.tip-content> "Update Link"
<.tip <.tip.noclick
@click=save @hotkey('tab').capture.if(!state.loading)=cycle_focus
@hotkey('shift+return').capture.if(!state.loading)=save >
> <.tip-hotkey> "Tab"
css fl:2 <.tip-content> "Next"
<.tip-hotkey> "Return"
<.tip-content> "Update Link"
<.tip.noclick
@hotkey('tab').capture.if(!state.loading)=cycle_focus
>
<.tip-hotkey> "Tab"
<.tip-content> "Next"
<.inputs> <.inputs>
css d:flex fld:column gap:20px css d:flex fld:column gap:20px

191
app/components/app-links.imba

@ -3,7 +3,6 @@ import { evaluate as eval_math } from 'mathjs'
tag app-links tag app-links
def mount def mount
p document
$links-input.focus! $links-input.focus!
def handle_paste e def handle_paste e
@ -93,7 +92,8 @@ tag app-links
def render def render
<self[w:100%]> <self>
css w:100% d:flex fld:column gap:10px
if $as.active if $as.active
<app-settings$as> <app-settings$as>
@ -132,10 +132,11 @@ tag app-links
<.side.right @click.if(!state.loading)=toggle_settings> <.side.right @click.if(!state.loading)=toggle_settings>
<svg src="../assets/settings.svg"> <svg src="../assets/settings.svg">
if config.data.enable_tips if state.active_bang or state.sorted_links.length < 1
if state.active_bang
<app-tips> <app-tips>
<.tip-row>
<.tip <.tip
@click=(state.active_bang = no) @click=(state.active_bang = no)
@ -144,93 +145,119 @@ tag app-links
<.tip-hotkey> "Esc" <.tip-hotkey> "Esc"
<.tip-content> "Back" <.tip-content> "Back"
else <.tip
@click=handle_shift_return
@hotkey('shift+return').capture.if(!state.loading)=handle_shift_return
>
<.tip-hotkey> "Shift + Return"
<.tip-content.ellipsis>
<span[ws:pre]> "Create Link "
let sq = state.query.trim!.split /\s+/
if sq.length >= 2
let url = sq.pop!
<span> '"'
<span> sq.join " "
<span[c:blue3 ws:pre]> " {url}"
<span> '"'
else
<span> "\"{sq.join " "}\""
<.tip
@click=(state.active_bang = no)
@hotkey('esc').capture.if(!state.loading)=(state.active_bang = no)
>
<.tip-hotkey> "Return"
<.tip-content> "Search"
else
<app-tips>
<app-tips> <.tip-row>
<.tip-row> <.tip
@click=handle_click_link
<.tip @hotkey('return').force.if(!loading)=handle_click_link
@click=handle_click_link >
@hotkey('return').force.if(!loading)=handle_click_link <.tip-hotkey> "Return"
> <.tip-content> "Navigate To Link"
<.tip-hotkey> "Return"
<.tip-content> "Navigate To Link" <.tip
@click=handle_shift_return
<.tip @hotkey('shift+return').capture.if(!state.loading)=handle_shift_return
@click=handle_shift_return >
@hotkey('shift+return').capture.if(!state.loading)=handle_shift_return <.tip-hotkey> "Shift + Return"
> <.tip-content.ellipsis>
<.tip-hotkey> "Shift + Return" <span[ws:pre]> "Create Link "
<.tip-content.ellipsis> let sq = state.query.trim!.split /\s+/
<span[ws:pre]> "Create Link " if sq.length >= 2
let sq = state.query.trim!.split /\s+/ let url = sq.pop!
if sq.length >= 2 <span> '"'
let url = sq.pop! <span> sq.join " "
<span> '"' <span[c:blue3 ws:pre]> " {url}"
<span> sq.join " " <span> '"'
<span[c:blue3 ws:pre]> " {url}"
<span> '"'
else
<span> "\"{sq.join " "}\""
<.tip
@click=handle_shift_backspace
@hotkey('shift+backspace').capture.if(!state.loading)=handle_shift_backspace
>
<.tip-hotkey> "Shift + Backspace"
<.tip-content> "Edit Link"
<app-tips-more$tips-more>
<.tip-row>
<.tip
@click.if(!state.loading)=api.toggle_effective_names
@hotkey('tab').capture.if(!state.loading)=api.toggle_effective_names
>
<.tip-hotkey> "Tab"
<.tip-content> "Toggle Effective Names"
<.tip
@click.if(!state.loading)=api.toggle_settings
@hotkey('esc').capture.if(!state.loading)=toggle_settings
>
<.tip-hotkey> "Esc"
<.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)=handle_cut
>
if math_result
<.tip-hotkey> "Cut (Math, If No Selection)"
<.tip-content> "Cut Math Result"
else else
<.tip-hotkey> "Cut (If No Selection)" <span> "\"{sq.join " "}\""
<.tip-content> "Cut All Text"
<.tip
@click=handle_shift_backspace
@hotkey('shift+backspace').capture.if(!state.loading)=handle_shift_backspace
>
<.tip-hotkey> "Shift + Backspace"
<.tip-content> "Edit Link"
<app-tips-more$tips-more>
<.tip-row>
<.tip
@click.if(!state.loading)=api.toggle_effective_names
@hotkey('tab').capture.if(!state.loading)=api.toggle_effective_names
>
<.tip-hotkey> "Tab"
<.tip-content> "Toggle Effective Names"
<.tip
@click.if(!state.loading)=api.toggle_settings
@hotkey('esc').capture.if(!state.loading)=toggle_settings
>
<.tip-hotkey> "Esc"
<.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)=handle_cut
>
if math_result
<.tip-hotkey> "Cut (Math, If No Selection)"
<.tip-content> "Cut Math Result"
else
<.tip-hotkey> "Cut (If No Selection)"
<.tip-content> "Cut All Text"
<.tip.noclick> <.tip.noclick>
<.tip-hotkey> "Paste (If Input Empty)" <.tip-hotkey> "Paste (If Input Empty)"
<.tip-content> "Instant Search" <.tip-content> "Instant Search"
<.tip.placeholder> <.tip.placeholder>
unless $tips-more.active unless $tips-more.active
<.links> <.links>
css d:flex fld:column jc:flex-start css d:flex fld:column jc:flex-start
fl:1 w:100% ofy:auto fl:1 w:100% ofy:auto
if not viewing_community_links and (state.active_bang or state.sorted_links.length < 1) if state.active_bang
<app-bang data=state.active_bang> <app-bang bang=state.active_bang>
elif state.sorted_links.length < 1
<app-bang bang=config.data.default_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>

39
app/components/app-settings.imba

@ -1,3 +1,5 @@
import download from 'downloadjs'
tag app-settings tag app-settings
active = no active = no
@ -12,24 +14,24 @@ tag app-settings
global.location.href = "https://github.com/familyfriendlymikey/fuzzyhome" global.location.href = "https://github.com/familyfriendlymikey/fuzzyhome"
def handle_click_toggle_tips def handle_click_toggle_tips
config.enable_tips = not config.enable_tips config.data.enable_tips = not config.data.enable_tips
save_config! config.save!
settings_active = no active = no
def handle_click_toggle_buttons def handle_click_toggle_buttons
config.enable_buttons = not config.enable_buttons config.data.enable_buttons = not config.data.enable_buttons
save_config! config.save!
settings_active = no active = no
def handle_click_toggle_search_on_paste def handle_click_toggle_search_on_paste
config.enable_search_on_paste = not config.enable_search_on_paste config.data.enable_search_on_paste = not config.data.enable_search_on_paste
save_config! config.save!
settings_active = no active = no
def handle_toggle_light_theme def handle_toggle_light_theme
config.enable_dark_theme = not config.enable_dark_theme config.data.enable_dark_theme = not config.data.enable_dark_theme
save_config! config.save!
settings_active = no active = no
def handle_click_import e def handle_click_import e
@ -56,7 +58,7 @@ tag app-settings
loading = yes loading = yes
await handle_import! await handle_import!
settings_active = no active = no
loading = no loading = no
def handle_click_export def handle_click_export
@ -69,7 +71,7 @@ tag app-settings
let time = datetime[4].split(":").join("-") let time = datetime[4].split(":").join("-")
let filename = "fuzzyhome_v{version}_{date}_{time}.txt" let filename = "fuzzyhome_v{version}_{date}_{time}.txt"
download(links.join("\n"), filename, "text/plain") download(links.join("\n"), filename, "text/plain")
settings_active = no active = no
loading = no loading = no
def render def render
@ -87,6 +89,7 @@ tag app-settings
bg:none c:purple4 bd:none cursor:pointer fs:14px bg:none c:purple4 bd:none cursor:pointer fs:14px
bg:purple4/10 rd:5px bg:purple4/10 rd:5px
h:100% h:100%
@hover bg:blue
if refs.community-links.active if refs.community-links.active
<app-community-links> <app-community-links>
@ -124,18 +127,18 @@ tag app-settings
<.settings-button <.settings-button
@click=handle_click_toggle_tips @click=handle_click_toggle_tips
> >
config.enable_tips ? "DISABLE TIPS" : "ENABLE TIPS" config.data.enable_tips ? "DISABLE TIPS" : "ENABLE TIPS"
<.settings-button <.settings-button
@click=handle_click_toggle_buttons @click=handle_click_toggle_buttons
> >
config.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.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
> >
config.enable_dark_theme ? "DISABLE DARK THEME" : "ENABLE DARK THEME" config.data.enable_dark_theme ? "DISABLE DARK THEME" : "ENABLE DARK THEME"

18
app/components/app-tips.imba

@ -3,7 +3,7 @@ tag app-tips
css >>> .tip-row css >>> .tip-row
d:flex fld:row w:100% fl:1 d:flex fld:row w:100% fl:1
fs:20px fs:20px
fs:14px pt:15px fs:14px
jc:end ta:center jc:end ta:center
bg:#20222f c:purple4 bg:#20222f c:purple4
@ -28,8 +28,8 @@ tag app-tips
css >>> .tip-content css >>> .tip-content
pt:2px fs:14px c:purple3 pt:2px fs:14px c:purple3
<self> <self[d:none]=config.data.enable_tips>
<slot> <slot>
tag app-tips-more < app-tips tag app-tips-more < app-tips
@ -38,11 +38,12 @@ tag app-tips-more < app-tips
def toggle def toggle
active = !active active = !active
<self> <self[d:none]=config.data.enable_tips>
css d:flex fld:column gap:10px
<@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
my:7px py:2px transition:background 100ms transition:background 100ms
@hover bg:purple3/3 @hover bg:purple3/3
if active if active
css rd:0 css rd:0
@ -53,7 +54,8 @@ tag app-tips-more < app-tips
else else
<svg src="../assets/chevron-up.svg"> <svg src="../assets/chevron-up.svg">
css >>> .hide .tip-row d:none <.more>
css >>> .more .tip-row @first pt:0 css d:flex fld:column gap:10px
<.more .hide=hide> if hide
css d:none
<slot> <slot>

4
app/config.imba

File diff suppressed because one or more lines are too long

1
scripts/config_move.sh

@ -0,0 +1 @@
printf "\033c" && rg --pcre2 -g '!config.imba' 'config\.(?!data.)'"$1"
Loading…
Cancel
Save