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.

154 lines
3.6 KiB

2 years ago
import download from 'downloadjs'
2 years ago
tag app-settings
active = no
2 years ago
def close
2 years ago
active = no
2 years ago
def open
active = yes
2 years ago
def handle_click_github
global.location.href = "https://github.com/familyfriendlymikey/fuzzyhome"
def handle_click_toggle_tips
2 years ago
config.data.enable_tips = not config.data.enable_tips
config.save!
active = no
2 years ago
def handle_click_toggle_buttons
2 years ago
config.data.enable_buttons = not config.data.enable_buttons
config.save!
active = no
2 years ago
def handle_click_toggle_search_on_paste
2 years ago
config.data.enable_search_on_paste = not config.data.enable_search_on_paste
config.save!
active = no
2 years ago
def handle_toggle_light_theme
2 years ago
config.data.enable_light_theme = not config.data.enable_light_theme
2 years ago
config.save!
active = no
2 years ago
def handle_import e
2 years ago
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
2 years ago
throw "Name already exists, add manually if you don't mind duplicates."
api.add_link link_text
2 years ago
catch e
errors.push "{link_text}\n{e}"
if errors.length > 0
err "importing some links", errors.join("\n\n")
state.loading = yes
2 years ago
await handle_import!
2 years ago
active = no
state.loading = no
close!
2 years ago
def handle_click_export
state.loading = yes
await api.reload_db!
2 years ago
let links = state.links.map do |link|
api.construct_link_text link
2 years ago
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")
2 years ago
active = no
state.loading = no
2 years ago
def render
2 years ago
<self>
css w:100%
2 years ago
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
2 years ago
bg:none bd:none cursor:pointer fs:14px
rd:5px
transition:background 100ms
2 years ago
h:100%
2 years ago
bg:$button-bg c:$button-c
@hover bg:$button-hover-bg
2 years ago
2 years ago
if refs.community-links.active
<app-community-links>
2 years ago
2 years ago
else
<.settings-container>
2 years ago
2 years ago
<.settings-button
2 years ago
@click=close
@hotkey("esc")=close
2 years ago
@hotkey("shift+tab")=close
2 years ago
> "BACK"
2 years ago
2 years ago
<.settings-container>
2 years ago
2 years ago
<.settings-button @click=(refs.community-links.open! and close!)>
2 years ago
"VIEW COMMUNITY LINKS"
2 years ago
2 years ago
<.settings-container>
2 years ago
2 years ago
<label.settings-button>
"IMPORT"
<input[d:none]
disabled=state.loading
@change=handle_import
2 years ago
@click=(this.value = '')
type="file"
>
2 years ago
2 years ago
<.settings-button @click=handle_click_export>
2 years ago
"EXPORT"
2 years ago
<.settings-container>
2 years ago
2 years ago
<.settings-button @click=handle_click_github>
2 years ago
"TUTORIAL"
2 years ago
<.settings-button @click=handle_click_github>
2 years ago
"GITHUB"
2 years ago
2 years ago
<.settings-container>
2 years ago
<.settings-button @click=handle_click_toggle_tips>
2 years ago
config.data.enable_tips ? "DISABLE TIPS" : "ENABLE TIPS"
2 years ago
<.settings-button @click=handle_click_toggle_buttons>
2 years ago
config.data.enable_buttons ? "DISABLE BUTTONS" : "ENABLE BUTTONS"
2 years ago
<.settings-container>
2 years ago
2 years ago
<.settings-button @click=handle_click_toggle_search_on_paste>
2 years ago
config.data.enable_search_on_paste ? "DISABLE SEARCH ON PASTE" : "ENABLE SEARCH ON PASTE"
2 years ago
2 years ago
<.settings-button @click=config.cycle_theme>
"THEME: {config.data.theme.toUpperCase!}"
<.settings-container>
<.settings-button @click=(api.delete_all_bang_history! and close!)>
"DELETE ALL BANG HISTORY"