You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
3.6 KiB
146 lines
3.6 KiB
import download from 'downloadjs'
|
|
|
|
tag app-settings
|
|
|
|
active = no
|
|
|
|
def close
|
|
active = no
|
|
|
|
def open
|
|
active = yes
|
|
|
|
def handle_click_github
|
|
global.location.href = "https://github.com/familyfriendlymikey/fuzzyhome"
|
|
|
|
def handle_click_toggle_tips
|
|
config.data.enable_tips = not config.data.enable_tips
|
|
config.save!
|
|
active = no
|
|
|
|
def handle_click_toggle_buttons
|
|
config.data.enable_buttons = not config.data.enable_buttons
|
|
config.save!
|
|
active = no
|
|
|
|
def handle_click_toggle_search_on_paste
|
|
config.data.enable_search_on_paste = not config.data.enable_search_on_paste
|
|
config.save!
|
|
active = no
|
|
|
|
def handle_toggle_light_theme
|
|
config.data.enable_dark_theme = not config.data.enable_dark_theme
|
|
config.save!
|
|
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 api.create_link_from_text link_text
|
|
if api.name_exists link.name
|
|
throw "Name already exists, add manually if you don't mind duplicates."
|
|
api.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!
|
|
active = no
|
|
loading = no
|
|
|
|
def handle_click_export
|
|
loading = yes
|
|
await api.reload_db!
|
|
let links = state.links.map do |link|
|
|
api.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")
|
|
active = no
|
|
loading = no
|
|
|
|
def render
|
|
|
|
<self>
|
|
css w:100%
|
|
|
|
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
|
|
transition:background 100ms
|
|
h:100%
|
|
@hover bg:purple4/20
|
|
|
|
if refs.community-links.active
|
|
<app-community-links>
|
|
|
|
else
|
|
<.settings-container>
|
|
|
|
<.settings-button
|
|
@click=close
|
|
@hotkey("esc")=close
|
|
@hotkey("shift+tab")=close
|
|
> "BACK"
|
|
|
|
<.settings-container>
|
|
|
|
<.settings-button @click.if(!loading)=(refs.community-links.open! and close!)>
|
|
"VIEW COMMUNITY LINKS"
|
|
|
|
<.settings-container>
|
|
|
|
<label.settings-button>
|
|
"IMPORT"
|
|
<input[d:none]
|
|
disabled=state.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.data.enable_tips ? "DISABLE TIPS" : "ENABLE TIPS"
|
|
|
|
<.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>
|
|
config.data.enable_dark_theme ? "DISABLE DARK THEME" : "ENABLE DARK THEME"
|
|
|