Browse Source

implement link editing

main
familyfriendlymikey 2 years ago
parent
commit
2ec24983f2
  1. 56
      app/client.imba

56
app/client.imba

@ -32,6 +32,7 @@ tag app
fatal_error = no
bang = no
holding_shift = no
editing_link = no
get render? do mounted?
@ -225,11 +226,13 @@ tag app
link_text
def handle_edit link
editing_link = link
state.query = construct_link_text(link)
def make_edit link, new_link_text
def edit_link
let input = window.prompt "Enter the new link name and url:", construct_link_text(link)
return if input is null
try
await update_link link, input
await update_link link, new_link_text
catch e
return err "editing link", e
loading = yes
@ -281,12 +284,12 @@ tag app
sort_links!
def handle_click_delete link
return unless window.confirm "Do you really want to delete {link..display_name}?"
handle_delete link
def handle_delete link
def delete_link
return unless window.confirm "Do you really want to delete {link..display_name}?"
try
await db.links.delete(link.id)
catch e
@ -322,12 +325,32 @@ tag app
window.alert "{link.display_name} is now the default bang"
def handle_shift_backspace
if editing_link
await handle_delete editing_link
editing_link = no
state.query = ''
sort_links!
else
return unless state.scored_links.length > 0
handle_edit state.scored_links[selection_index]
def handle_shift_return
if editing_link
try
await update_link editing_link, state.query
editing_link = no
state.query = ''
sort_links!
catch e
err "updating link", e
else
handle_add!
def handle_esc
editing_link = no
state.query = ''
sort_links!
def handle_click_add
handle_add!
@ -617,6 +640,7 @@ tag app
# placeholder=pretty_date
@hotkey('return').capture=handle_return
@hotkey('shift+return').capture.if(can_add)=handle_shift_return
@hotkey('esc').capture=handle_esc
@hotkey('shift+backspace').capture=handle_shift_backspace
@hotkey('down').capture=increment_selection_index
@hotkey('up').capture=decrement_selection_index
@ -632,6 +656,29 @@ tag app
<svg src="./assets/settings.svg">
if config.enable_tips and not config.enable_simplify_ui
if editing_link
<.middle-button>
<.tip[jc:start ta:left fl:1]
@click=handle_esc
>
<.tip-hotkey> "Esc"
<.tip-content> "Cancel Edits"
<.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"
else
<.middle-button>
<.tip[jc:start ta:left fl:1] @click=handle_return>
<.tip-hotkey> "Return"
@ -661,6 +708,7 @@ tag app
<.tip-hotkey> "Shift + Backspace"
<.tip-content> "Edit Link"
unless editing_link
<.links>
if bang or state.scored_links.length < 1
<a.link.selected

Loading…
Cancel
Save