Browse Source

refactor: wip

main
familyfriendlymikey 2 years ago
parent
commit
6bf68d4e10
  1. 1
      .gitignore
  2. 14
      app/assets/community_links.imba
  3. 475
      app/client.imba
  4. 1
      app/community_links.imba
  5. 77
      app/components/app-community-links.imba
  6. 37
      app/components/app-edit.imba
  7. 21
      app/components/app-prompt.imba
  8. 142
      app/components/app-settings.imba
  9. 14
      app/process_community_links.imba
  10. 6
      app/state.imba
  11. 40
      app/styles.imba
  12. 3
      app/utils.imba

1
.gitignore

@ -2,3 +2,4 @@
node_modules node_modules
dist dist
*.swp *.swp
.fdignore

14
app/assets/community_links.imba

@ -0,0 +1,14 @@
export default """
!google search google.com/search?q=
!youtube search youtube.com/results?search_query=
!brave search search.brave.com/search?q=
!amazon search amazon.com/s?k=
!google site:reddit google.com/search?q=site%3Areddit.com%20
!google site:stackoverflow google.com/search?q=site%3Astackoverflow.com%20
twitch twitch.tv
instagram instagram.com
messenger messenger.com
photopea photopea.com
youtube youtube.com
localhost:3000 http://localhost:3000
""".split '\n'

475
app/client.imba

@ -1,25 +1,28 @@
let p = console.log let p = console.log
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 { orderBy, omit } from 'lodash' import { orderBy, omit } from 'lodash'
import pkg from '../package.json'
let version = pkg.version
import db from './db'
import fzi from 'fzi' import fzi from 'fzi'
import download from 'downloadjs' import download from 'downloadjs'
import { nanoid } from 'nanoid' import { nanoid } from 'nanoid'
import { parse_url } from './utils'
import initial_config from './config'
import { evaluate as eval_math } from 'mathjs' import { evaluate as eval_math } from 'mathjs'
import community_links from './community_links'
let state = { import pkg from '../package.json'
query: '' let version = pkg.version
links: [] import { parse_url } from './utils'
sorted_links: [] import db from './db'
} import state from './state'
import default_config from './config'
import app-community-links from './components/app-community-links'
import app-settings from './components/app-settings'
import app-prompt from './components/app-prompt'
import app-edit from './components/app-edit'
import './styles'
p "fuzzyhome version {version}"
global._fuzzyhome_delete_everything = do |prompt=yes| global._fuzzyhome_delete_everything = do |prompt=yes|
return if prompt and window.confirm "This will delete everything. Are you sure?" return if prompt and window.confirm "This will delete everything. Are you sure?"
@ -28,19 +31,18 @@ global._fuzzyhome_delete_everything = do |prompt=yes|
delete localStorage.fuzzyhome_visited delete localStorage.fuzzyhome_visited
location.reload! location.reload!
p "fuzzyhome version {version}" extend tag element
get state
state
tag app tag app
selection_index = 0 selection_index = 0
settings_active = no
loading = no
fatal_error = no fatal_error = no
bang = no bang = no
holding_shift = no
editing_link = no editing_link = no
prior_query = '' prior_query = ''
viewing_community_links = no viewing_community_links = yes
get render? do mounted? get render? do mounted?
@ -52,7 +54,7 @@ tag app
await reload_db! await reload_db!
p "links:", state.links p "links:", state.links
catch e catch e
err "loading database", e err "state.loading database", e
fatal_error = yes fatal_error = yes
return return
await load_config! await load_config!
@ -92,7 +94,7 @@ tag app
def reset_config def reset_config
p "resetting config" p "resetting config"
config = initial_config config = default_config
save_config! save_config!
def save_config def save_config
@ -130,16 +132,7 @@ tag app
name name
def sort_links def sort_links
let links let links = state.links
if viewing_community_links
p community_links
links = community_links.filter do |link|
not state.links.some do |my_link|
link.id is my_link.id
p links
else
links = state.links
if state.query.trim!.length > 0 if state.query.trim!.length > 0
if config.enable_effective_names if config.enable_effective_names
state.sorted_links = fzi links, state.query state.sorted_links = fzi links, state.query
@ -190,7 +183,7 @@ tag app
reader.readAsDataURL(blob) reader.readAsDataURL(blob)
get can_add get can_add
return no if loading return no if state.loading
return no if settings_active return no if settings_active
let query = state.query.trim! let query = state.query.trim!
return no if query is '' return no if query is ''
@ -220,14 +213,14 @@ tag app
{ name, display_name, is_bang, is_pinned, url, frequency:0, icon } { name, display_name, is_bang, is_pinned, url, frequency:0, icon }
def handle_add def handle_add
loading = yes state.loading = yes
try try
await add_link state.query await add_link state.query
state.query = '' state.query = ''
sort_links! sort_links!
catch e catch e
err "adding link", e err "adding link", e
loading = no state.loading = no
def add_link text def add_link text
let link = await create_link_from_text text let link = await create_link_from_text text
@ -257,9 +250,9 @@ tag app
await update_link link, new_link_text await update_link link, new_link_text
catch e catch e
return err "editing link", e return err "editing link", e
loading = yes state.loading = yes
await edit_link! await edit_link!
loading = no state.loading = no
def update_link old_link, new_link_text def update_link old_link, new_link_text
let new_link = await create_link_from_text new_link_text let new_link = await create_link_from_text new_link_text
@ -324,14 +317,14 @@ tag app
catch e catch e
err "reloading db after successful delete", e err "reloading db after successful delete", e
loading = yes state.loading = yes
await delete_link! await delete_link!
state.query = prior_query state.query = prior_query
prior_query = '' prior_query = ''
editing_link = no editing_link = no
sort_links! sort_links!
selection_index = Math.min selection_index, state.sorted_links.length - 1 selection_index = Math.min selection_index, state.sorted_links.length - 1
loading = no state.loading = no
def handle_click_edit link def handle_click_edit link
handle_edit link handle_edit link
@ -346,16 +339,6 @@ tag app
await reload_db! await reload_db!
imba.commit! imba.commit!
def handle_click_set_default_bang
if editing_link.is_bang isnt true
return err "setting default bang", "Link is not a bang."
config.default_bang = editing_link
save_config!
editing_link = no
state.query = prior_query
prior_query = ''
sort_links!
def handle_shift_backspace def handle_shift_backspace
if editing_link if editing_link
await handle_delete editing_link await handle_delete editing_link
@ -382,12 +365,12 @@ tag app
err "updating link", e err "updating link", e
else else
handle_add! handle_add!
loading = yes state.loading = yes
await go! await go!
editing_link = no editing_link = no
state.query = '' state.query = ''
sort_links! sort_links!
loading = no state.loading = no
def handle_esc def handle_esc
if editing_link if editing_link
@ -408,42 +391,6 @@ tag app
def name_exists new_name def name_exists new_name
state.links.some! do |{name}| new_name is name state.links.some! do |{name}| new_name is name
def handle_click_import e
def handle_import
let errors = []
try
let text = await e.target.files[0].text!
var links = text.split "\n"
catch e
return err "importing db", e
for link_text in links
try
let link = await create_link_from_text link_text
if name_exists link.name
throw "Name already exists, add manually if you don't mind duplicates."
add_link link_text
catch e
errors.push "{link_text}\n{e}"
if errors.length > 0
err "importing some links", errors.join("\n\n")
loading = yes
await handle_import!
settings_active = no
loading = no
def handle_click_export
loading = yes
await reload_db!
let links = state.links.map do |link|
construct_link_text link
let datetime = new Date!.toString!.split(" ")
let date = datetime.slice(1, 4).join("-").toLowerCase!
let time = datetime[4].split(":").join("-")
let filename = "fuzzyhome_v{version}_{date}_{time}.txt"
download(links.join("\n"), filename, "text/plain")
settings_active = no
loading = no
get math_result get math_result
try try
let result = Number(eval_math state.query) let result = Number(eval_math state.query)
@ -452,9 +399,6 @@ tag app
catch catch
no no
def handle_click_github
global.location.href = "https://github.com/familyfriendlymikey/fuzzyhome"
def handle_paste e def handle_paste e
return unless config.enable_search_on_paste return unless config.enable_search_on_paste
return if state.query.length > 0 return if state.query.length > 0
@ -463,38 +407,10 @@ tag app
bang ||= config.default_bang bang ||= config.default_bang
handle_bang! handle_bang!
def handle_click_toggle_tips
config.enable_tips = not config.enable_tips
save_config!
settings_active = no
def handle_click_toggle_buttons
config.enable_buttons = not config.enable_buttons
save_config!
settings_active = no
def handle_click_toggle_search_on_paste
config.enable_search_on_paste = not config.enable_search_on_paste
save_config!
settings_active = no
def handle_toggle_light_theme
config.enable_dark_theme = not config.enable_dark_theme
save_config!
settings_active = no
def handle_click_toggle_effective_names
config.enable_effective_names = not config.enable_effective_names
save_config!
settings_active = no
def handle_click_toggle_simplify_ui def handle_click_toggle_simplify_ui
config.enable_simplify_ui = not config.enable_simplify_ui config.enable_simplify_ui = not config.enable_simplify_ui
save_config! save_config!
get pretty_date
Date!.toString!.split(" ").slice(0, 4).join(" ")
def handle_click_copy s def handle_click_copy s
try try
await window.navigator.clipboard.writeText(s) await window.navigator.clipboard.writeText(s)
@ -516,19 +432,7 @@ tag app
def render def render
css .disabled * <self .disabled=state.loading>
@important c:gray4 cursor:default user-select:none pointer-events:none
css .disabled $main-input
@important bg:gray4/10 bc:gray4
<self .disabled=loading>
css body
d:flex fld:column jc:flex-start ai:center
m:0 w:100% h:100% bg:#20222f
ff:sans-serif fw:1
user-select:none
css self css self
d:flex fld:column jc:flex-start ai:center d:flex fld:column jc:flex-start ai:center
@ -539,46 +443,11 @@ tag app
css .fatal css .fatal
c:blue2 c:blue2
css $main-input
w:100% h:50px px:20px
fs:20px ta:center
bd:1px solid purple4
bg:purple4/10 c:blue3 caret-color:blue3
outline:none rd:5px
@placeholder fs:10px c:blue3
css .loading-container css .loading-container
d:flex fld:row jc:space-around ai:center d:flex fld:row jc:space-around ai:center
w:100% h:50px w:100% h:50px
bg:purple4/10 rd:5px c:gray4 bg:purple4/10 rd:5px c:gray4
css .settings-container
d:flex fld:row jc:space-around ai:center
w:100% h:50px
mt:10px
gap:10px
css .settings-button, .settings-container button
d:flex fld:column jc:center ai:center fl:1
bg:none c:purple4 bd:none cursor:pointer fs:14px
bg:purple4/10 rd:5px
h:100%
css .middle-button
d:flex fld:row w:100%
c:purple4 fs:20px cursor:pointer
fs:14px pt:15px
css .tip
d:flex fld:column bdr:1px solid blue3/10 min-width:0 fl:1 p:5px
@last bd:none
css .tip-hotkey
fs:12px c:purple3/50
css .tip-content
pt:2px fs:14px c:purple3
css .links css .links
d:flex fld:column jc:flex-start fl:1 d:flex fld:column jc:flex-start fl:1
w:100% ofy:auto pt:15px w:100% ofy:auto pt:15px
@ -590,12 +459,6 @@ tag app
css .link-left css .link-left
d:flex fl:1 d:flex fl:1
css .selected
bg:blue3/5
css a
td:none
css .link-icon css .link-icon
w:20px h:20px mr:10px rd:3px w:20px h:20px mr:10px rd:3px
@ -639,74 +502,28 @@ tag app
if fatal_error if fatal_error
<.fatal> <.fatal>
""" """
There was an error loading the database. There was an error state.loading the database.
This could be due to a user setting This could be due to a user setting
disallowing local storage, or a random error. disallowing local storage, or a random error.
Consider refreshing. Consider refreshing.
Check developer console for more information. Check developer console for more information.
""" """
if settings_active
<.settings-container>
<.settings-button
@click=(settings_active = no)
> "BACK"
<.settings-container>
<.settings-button
@click.if(!loading)=handle_click_view_community_links
>
"VIEW COMMUNITY LINKS"
<.settings-container>
<label.settings-button>
"IMPORT"
<input[d:none]
disabled=loading
@change=handle_click_import
@click=(this.value = '')
type="file"
>
<.settings-button
@click.if(!loading)=handle_click_export
> "EXPORT"
<.settings-container>
<.settings-button
@click.if(!loading)=handle_click_github
> "TUTORIAL"
<.settings-button
@click.if(!loading)=handle_click_github
> "GITHUB"
<.settings-container>
<.settings-button
@click=handle_click_toggle_tips
>
config.enable_tips ? "DISABLE TIPS" : "ENABLE TIPS"
<.settings-button
@click=handle_click_toggle_buttons
>
config.enable_buttons ? "DISABLE BUTTONS" : "ENABLE BUTTONS"
<.settings-container>
<.settings-button
@click=handle_click_toggle_search_on_paste
>
config.enable_search_on_paste ? "DISABLE SEARCH ON PASTE" : "ENABLE SEARCH ON PASTE"
<.settings-button
@click=handle_click_toggle_effective_names
>
config.enable_effective_names ? "DISABLE EFFECTIVE NAMES" : "ENABLE EFFECTIVE NAMES"
<.settings-container>
<.settings-button
@click.if(!loading)=handle_toggle_light_theme
>
config.enable_dark_theme ? "DISABLE DARK THEME" : "ENABLE DARK THEME"
else if viewing_community_links
<app-community-links>
elif settings_active
<app-settings>
elif editing_link
<app-edit>
else
<links>
<.header> <.header>
css css
d:flex fld:row w:100% d:flex fld:row w:100%
css $main-input
fl:1
css .side css .side
c:purple3/90 fs:15px c:purple3/90 fs:15px
d:flex ja:center w:30px d:flex ja:center w:30px
@ -732,18 +549,18 @@ tag app
<input$main-input <input$main-input
bind=state.query bind=state.query
# placeholder=pretty_date # placeholder=pretty_date
@hotkey('return').capture.if(!loading)=handle_return @hotkey('return').capture.if(!state.loading)=handle_return
@hotkey('shift+return').capture.if(!loading)=handle_shift_return @hotkey('shift+return').capture.if(!state.loading)=handle_shift_return
@hotkey('esc').capture.if(!loading)=handle_esc @hotkey('esc').capture.if(!state.loading)=handle_esc
@hotkey('shift+backspace').capture.if(!loading)=handle_shift_backspace @hotkey('shift+backspace').capture.if(!state.loading)=handle_shift_backspace
@hotkey('down').capture.if(!loading)=increment_selection_index @hotkey('down').capture.if(!state.loading)=increment_selection_index
@hotkey('up').capture.if(!loading)=decrement_selection_index @hotkey('up').capture.if(!state.loading)=decrement_selection_index
@keydown.del.if(!loading)=handle_del @keydown.del.if(!state.loading)=handle_del
@input.if(!loading)=handle_input @input.if(!state.loading)=handle_input
@paste.if(!loading)=handle_paste @paste.if(!state.loading)=handle_paste
@blur=this.focus @blur=this.focus
@cut=handle_cut @cut=handle_cut
disabled=loading disabled=state.loading
> >
let m = math_result let m = math_result
@ -752,126 +569,80 @@ tag app
@click=handle_click_copy(m) @click=handle_click_copy(m)
> "= {Math.round(m * 100)/100}" > "= {Math.round(m * 100)/100}"
else else
<.side.right @click.if(!loading)=toggle_settings> <.side.right @click.if(!state.loading)=toggle_settings>
<svg src="./assets/settings.svg"> <svg src="./assets/settings.svg">
if viewing_community_links if config.enable_tips and not config.enable_simplify_ui
<.middle-button> <.middle-button>
<.tip[jc:start ta:left fl:1] @click=handle_return>
<.tip[jc:start ta:center fl:1] <.tip-hotkey> "Return"
@click=handle_esc <.tip-content> "Navigate To Link"
> <.tip[jc:center ta:center fl:2 px:15px]
<.tip-hotkey> "Esc" @click=handle_shift_return
<.tip-content> "Exit Community Links" >
<.tip-hotkey> "Shift + Return"
<.tip[jc:end ta:center fl:1] <.tip-content[of:hidden text-overflow:ellipsis white-space:nowrap]>
@click=handle_shift_return <span> "Add New Link"
> <span[ws:pre]> " "
<.tip-hotkey> "Shift + Return" let sq = state.query.trim!.split /\s+/
<.tip-content> "Add To Your Links" if sq.length >= 2
let url = sq.pop!
elif config.enable_tips and not config.enable_simplify_ui <span> '"'
if editing_link <span> sq.join ' '
<.middle-button> <span[ws:pre]> ' '
<span[c:blue3]> url
<.tip[jc:start ta:left fl:1] <span> '"'
@click=handle_esc else
> <span> '"'
<.tip-hotkey> "Esc" <span> sq.join ' '
<.tip-content> "Cancel Edits" <span> '"'
<.tip[jc:end ta:right fl:1]
if editing_link.is_bang @click=handle_shift_backspace
<.tip[jc:end ta:center fl:1] >
@click=handle_click_set_default_bang <.tip-hotkey> "Shift + Backspace"
> <.tip-content> "Edit Link"
<.tip-hotkey> "Click"
<.tip-content> "Set Default Bang" <.links>
if not viewing_community_links and (bang or state.sorted_links.length < 1)
<.tip[jc:center ta:center fl:1 px:15px] <a.link.selected
@click=handle_shift_return href=encoded_bang_query
> @click=handle_click_bang
<.tip-hotkey> "Shift + Return" >
<.tip-content[of:hidden text-overflow:ellipsis white-space:nowrap]> <.link-left>
"Update Link" <img.link-icon src=active_bang.icon>
<.display-name.bang-text> encoded_bang_query
<.tip[jc:end ta:right fl:1] <.link-right[jc:flex-end]>
@click=handle_shift_backspace <.frequency> active_bang.frequency
>
<.tip-hotkey> "Shift + Backspace"
<.tip-content> "Delete Link"
else else
<.middle-button> for link, index in state.sorted_links
<.tip[jc:start ta:left fl:1] @click=handle_return> <a.link
<.tip-hotkey> "Return" href=link.url
<.tip-content> "Navigate To Link" @pointerover=(selection_index = index)
<.tip[jc:center ta:center fl:2 px:15px] @click.prevent=handle_click_link(link)
@click=handle_shift_return .selected=(index is selection_index)
>
<.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> "Shift + Backspace"
<.tip-content> "Edit Link"
unless editing_link
<.links>
if not viewing_community_links and (bang or state.sorted_links.length < 1)
<a.link.selected
href=encoded_bang_query
@click=handle_click_bang
> >
<.link-left> <.link-left>
<img.link-icon src=active_bang.icon> <img.link-icon src=link.icon>
<.display-name.bang-text> encoded_bang_query <.display-name
<.link-right[jc:flex-end]> [c:#FAD4AB]=link.is_bang
<.frequency> active_bang.frequency > link.display_name
else if link.display_name isnt link.name and config.enable_effective_names
for link, index in state.sorted_links <.name>
<a.link <span.parens> "("
href=link.url <span> link.name
@pointerover=(selection_index = index) <span.parens> ")"
@click.prevent=handle_click_link(link) <.link-right>
.selected=(index is selection_index) <.link-buttons .buttons-disabled=(not config.enable_buttons or config.enable_simplify_ui)>
> <.link-button@click.prevent.stop=handle_click_edit(link)>
<.link-left> <svg src='./assets/edit-2.svg'>
<img.link-icon src=link.icon> <.link-button@click.prevent.stop=handle_click_delete(link)>
<.display-name <svg src='./assets/trash.svg'>
[c:#FAD4AB]=link.is_bang <.link-button
> link.display_name @click.prevent.stop=handle_click_pin(link)
if link.display_name isnt link.name and config.enable_effective_names [visibility:visible c:purple3/50]=(link.is_pinned and (index isnt selection_index or not config.enable_buttons or config.enable_simplify_ui))
<.name> >
<span.parens> "(" <svg src='./assets/star.svg'>
<span> link.name <.frequency> link.frequency
<span.parens> ")"
<.link-right>
<.link-buttons .buttons-disabled=(not config.enable_buttons or config.enable_simplify_ui)>
<.link-button@click.prevent.stop=handle_click_edit(link)>
<svg src='./assets/edit-2.svg'>
<.link-button@click.prevent.stop=handle_click_delete(link)>
<svg src='./assets/trash.svg'>
<.link-button
@click.prevent.stop=handle_click_pin(link)
[visibility:visible c:purple3/50]=(link.is_pinned and (index isnt selection_index or not config.enable_buttons or config.enable_simplify_ui))
>
<svg src='./assets/star.svg'>
<.frequency> link.frequency
$main-input.focus! $main-input.focus!
imba.mount <app> imba.mount <app>

1
app/community_links.imba

@ -1 +0,0 @@
export default []

77
app/components/app-community-links.imba

@ -0,0 +1,77 @@
let p = console.log
import links from '../assets/community_links'
tag app-community-links
active = no
selection_index = 0
def open
active = yes
def close
active = no
def increment_selection_index
selection_index = Math.min(links.length - 1, selection_index + 1)
def decrement_selection_index
selection_index = Math.max(0, selection_index - 1)
def get_link_obj link_text
let split_text = link_text.trim!.split /\s+/
let url = split_text.pop!
let rest = split_text.join " "
{ url, rest }
def render
<self
@hotkey('esc').capture.if(!loading)=close
@hotkey('down').capture.if(!loading)=increment_selection_index
@hotkey('up').capture.if(!loading)=decrement_selection_index
>
css self
d:flex fld:column jc:flex-start fl:1
w:100% ofy:auto pt:15px
css .link
d:flex fld:row jc:space-between ai:center
px:16px py:11px rd:5px cursor:pointer c:blue3
min-height:35px
css .link-left
fl:1
css .link-right
fl:1
overflow-wrap:anywhere
word-break:break-all
css .bang
c:#FAD4AB
css .selected
bg:blue3/5
<.middle-button>
<.tip[jc:start ta:center fl:1]
@click=handle_esc
>
<.tip-hotkey> "Esc"
<.tip-content> "Exit Community Links"
<.tip[jc:end ta:center fl:1]
@click=handle_shift_return
>
<.tip-hotkey> "Shift + Return"
<.tip-content> "Add To Your Links"
for link_text, index in links
<.link
.selected=(selection_index == index)
@pointerover=(selection_index = index)
>
let { url, rest } = get_link_obj link_text
<.link-left .bang=rest.startsWith("!")> rest
<.link-right> url

37
app/components/app-edit.imba

@ -0,0 +1,37 @@
tag app-edit < app-prompt
def handle_click_set_default_bang
if editing_link.is_bang isnt true
return err "setting default bang", "Link is not a bang."
config.default_bang = editing_link
save_config!
editing_link = no
state.query = prior_query
prior_query = ''
sort_links!
def render
<self>
<.middle-button>
<.tip[jc:start ta:left fl:1]
@click=handle_esc
>
<.tip-hotkey> "Esc"
<.tip-content> "Cancel Edits"
if editing_link.is_bang
<.tip[jc:end ta:center fl:1]
@click=handle_click_set_default_bang
>
<.tip-hotkey> "Click"
<.tip-content> "Set Default Bang"
<.tip[jc:center ta:center fl:1 px:15px]
@click=handle_shift_return
>
<.tip-hotkey> "Shift + Return"
<.tip-content[of:hidden text-overflow:ellipsis white-space:nowrap]>
"Update Link"
<.tip[jc:end ta:right fl:1]
@click=handle_shift_backspace
>
<.tip-hotkey> "Shift + Backspace"
<.tip-content> "Delete Link"

21
app/components/app-prompt.imba

@ -0,0 +1,21 @@
tag app-prompt
active = no
def get_input s
input_text = s
active = yes
let result = await new Promise! do |resolve|
self.addEventListener('end') do |e|
self.removeEventListener('end', this)
resolve(e.detail)
active = no
result
def end
emit('end', input_text)
def render
<self>
<input bind=input_text>
<button@click=end> 'Done.'

142
app/components/app-settings.imba

@ -0,0 +1,142 @@
tag app-settings
active = no
def end
active = no
def handle_click_github
global.location.href = "https://github.com/familyfriendlymikey/fuzzyhome"
def handle_click_toggle_tips
config.enable_tips = not config.enable_tips
save_config!
settings_active = no
def handle_click_toggle_buttons
config.enable_buttons = not config.enable_buttons
save_config!
settings_active = no
def handle_click_toggle_search_on_paste
config.enable_search_on_paste = not config.enable_search_on_paste
save_config!
settings_active = no
def handle_toggle_light_theme
config.enable_dark_theme = not config.enable_dark_theme
save_config!
settings_active = no
def handle_click_toggle_effective_names
config.enable_effective_names = not config.enable_effective_names
save_config!
settings_active = no
def handle_click_import e
def handle_import
let errors = []
try
let text = await e.target.files[0].text!
var links = text.split "\n"
catch e
return err "importing db", e
for link_text in links
try
let link = await create_link_from_text link_text
if name_exists link.name
throw "Name already exists, add manually if you don't mind duplicates."
add_link link_text
catch e
errors.push "{link_text}\n{e}"
if errors.length > 0
err "importing some links", errors.join("\n\n")
loading = yes
await handle_import!
settings_active = no
loading = no
def handle_click_export
loading = yes
await reload_db!
let links = state.links.map do |link|
construct_link_text link
let datetime = new Date!.toString!.split(" ")
let date = datetime.slice(1, 4).join("-").toLowerCase!
let time = datetime[4].split(":").join("-")
let filename = "fuzzyhome_v{version}_{date}_{time}.txt"
download(links.join("\n"), filename, "text/plain")
settings_active = no
loading = no
def render
<self>
css .settings-container
d:flex fld:row jc:space-around ai:center
w:100% h:50px
mt:10px
gap:10px
css .settings-button, .settings-container button
d:flex fld:column jc:center ai:center fl:1
bg:none c:purple4 bd:none cursor:pointer fs:14px
bg:purple4/10 rd:5px
h:100%
if $community-links.active
<community-links>
else
<.settings-container>
<.settings-button
@click=end
@hotkey("esc")=end
> "BACK"
<.settings-container>
<.settings-button
@click.if(!loading)=$community-links.open
>
"VIEW COMMUNITY LINKS"
<.settings-container>
<label.settings-button>
"IMPORT"
<input[d:none]
disabled=loading
@change=handle_click_import
@click=(this.value = '')
type="file"
>
<.settings-button
@click.if(!loading)=handle_click_export
> "EXPORT"
<.settings-container>
<.settings-button
@click.if(!loading)=handle_click_github
> "TUTORIAL"
<.settings-button
@click.if(!loading)=handle_click_github
> "GITHUB"
<.settings-container>
<.settings-button
@click=handle_click_toggle_tips
>
config.enable_tips ? "DISABLE TIPS" : "ENABLE TIPS"
<.settings-button
@click=handle_click_toggle_buttons
>
config.enable_buttons ? "DISABLE BUTTONS" : "ENABLE BUTTONS"
<.settings-container>
<.settings-button
@click=handle_click_toggle_search_on_paste
>
config.enable_search_on_paste ? "DISABLE SEARCH ON PASTE" : "ENABLE SEARCH ON PASTE"
<.settings-button
@click=handle_click_toggle_effective_names
>
config.enable_effective_names ? "DISABLE EFFECTIVE NAMES" : "ENABLE EFFECTIVE NAMES"
<.settings-container>
<.settings-button
@click.if(!loading)=handle_toggle_light_theme
>
config.enable_dark_theme ? "DISABLE DARK THEME" : "ENABLE DARK THEME"

14
app/process_community_links.imba

@ -1,14 +0,0 @@
let p = console.log
const sharp = require 'sharp'
import links from '../app/community_links'
def main
for link in links
data = link.icon.replace(/data:.*base64,/, '')
p data.slice(0, 10)
let buf = Buffer.from(data, 'base64')
buf = await sharp(buf).resize(20, 20).toBuffer!
p buf
# p x.toString("base64")
main!

6
app/state.imba

@ -0,0 +1,6 @@
export default {
query: ''
links: []
sorted_links: []
loading: no
}

40
app/styles.imba

@ -0,0 +1,40 @@
global css body
d:flex fld:column jc:flex-start ai:center
m:0 w:100% h:100% bg:#20222f
ff:sans-serif fw:1
user-select:none
global css input
w:100% h:50px px:20px fl:1
fs:20px ta:center
bd:1px solid purple4
bg:purple4/10 c:blue3 caret-color:blue3
outline:none rd:5px
global css a
td:none
global css .disabled *
@important c:gray4 cursor:default user-select:none pointer-events:none
global css .disabled $main-input
@important bg:gray4/10 bc:gray4
global css .middle-button
d:flex fld:row w:100%
c:purple4 fs:20px cursor:pointer
fs:14px pt:15px
global css .tip
d:flex fld:column bdr:1px solid blue3/10 min-width:0 fl:1 p:5px
@last bd:none
global css .tip-hotkey
fs:12px c:purple3/50
global css .tip-content
pt:2px fs:14px c:purple3
global css .selected
bg:blue3/5

3
app/utils.imba

@ -9,3 +9,6 @@ export def parse_url url
try try
return get_url "https://{url}" return get_url "https://{url}"
throw "invalid url" throw "invalid url"
def get_pretty_date
Date!.toString!.split(" ").slice(0, 4).join(" ")

Loading…
Cancel
Save