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.

119 lines
2.3 KiB

2 years ago
let p = console.log
import all_links from '../assets/community_links'
2 years ago
import fzi from 'fzi'
import api from '../api'
2 years ago
tag app-community-links
active = no
2 years ago
selection_index = 0
query = ""
get render? do mounted?
2 years ago
2 years ago
def mount
$cli.focus!
links = await get_links!
render!
def get_links
let result = []
for link_text in all_links
let link = await api.create_link_from_text(link_text, no)
link.link_text = link_text
result.push link
result
get filtered_links
links.filter! do |link| !api.name_exists(link.name)
get sorted_links
fzi.sort query, filtered_links, do |x| x.name
get selected_link
sorted_links[selection_index]
2 years ago
2 years ago
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 add_community_link
return if state.loading
state.loading = yes
try
await api.add_link selected_link.link_text
catch e
err "adding link", e
state.loading = no
2 years ago
get tips
let result = []
result.push <>
<.tip
@click=close
@hotkey("esc").force=close
>
2 years ago
<.tip-hotkey> "Esc"
<.tip-content> "Exit Community Links"
result.push <>
<.tip
@click=add_community_link
@hotkey("shift+return").force=add_community_link
>
2 years ago
<.tip-hotkey> "Shift + Return Or Click"
<.tip-content> "Add To Your Links"
result.push <>
<.tip.noclick
@hotkey('down').capture.if(!state.loading)=increment_selection_index
@hotkey('up').capture.if(!state.loading)=decrement_selection_index
>
<.tip-hotkey> "Up/Down Arrow"
<.tip-content> "Move Selection"
result
2 years ago
def render
2 years ago
<self>
css d:flex fld:column jc:start gap:15px fl:1 w:100% ofy:hidden
<div>
<input$cli
autofocus
bind=query
>
2 years ago
<app-tips tips=tips>
<.links>
css ofy:auto
for link, index in sorted_links
2 years ago
<.link
.selected=(selection_index == index)
@pointerover=(selection_index = index)
@click=add_community_link
2 years ago
>
css d:flex fld:row jc:space-between ai:center px:16px
2 years ago
py:2px rd:5px cursor:pointer c:$text-c min-height:35px
2 years ago
if link.is_bang
css c:$bang-c
2 years ago
<.link-left> link.name
2 years ago
css fl:1
<link-right.ellipsis> link.url
css fl:1 c:inherit