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.

147 lines
3.7 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_dark_theme = not config.data.enable_dark_theme
config.save!
active = no
2 years ago
def handle_click_import e
def name_exists new_name
state.links.some! do |{name}| new_name is name
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
2 years ago
if name_exists link.name
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")
2 years ago
loading = yes
await handle_import!
2 years ago
active = no
2 years ago
loading = no
def handle_click_export
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
2 years ago
loading = no
def render
2 years ago
<self[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
bg:none c:purple4 bd:none cursor:pointer fs:14px
bg:purple4/10 rd:5px
transition:background 100ms
2 years ago
h:100%
@hover bg:purple4/20
2 years ago
2 years ago
if refs.community-links.active
<app-community-links>
2 years ago
else
<.settings-container>
<.settings-button
2 years ago
@click=close
@hotkey("esc")=close
2 years ago
@hotkey("shift+tab")=close
2 years ago
> "BACK"
<.settings-container>
<.settings-button
@click.if(!loading)=$community-links.open
>
"VIEW COMMUNITY LINKS"
<.settings-container>
<label.settings-button>
"IMPORT"
<input[d:none]
disabled=state.loading
2 years ago
@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
>
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>
<.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
<.settings-button
@click.if(!loading)=handle_toggle_light_theme
>
2 years ago
config.data.enable_dark_theme ? "DISABLE DARK THEME" : "ENABLE DARK THEME"