Browse Source

implement pins

main
familyfriendlymikey 2 years ago
parent
commit
637283382d
  1. 20
      app/client.imba
  2. 3
      app/db.imba

20
app/client.imba

@ -121,7 +121,9 @@ tag app
if state.query.trim!.length > 0 if state.query.trim!.length > 0
state.scored_links = fzi state.links, state.query state.scored_links = fzi state.links, state.query
else else
state.scored_links = orderBy(state.links, 'frequency', 'desc') let pinned = do |link| link.is_pinned
let frequency = do |link| link.frequency
state.scored_links = orderBy(state.links, [pinned, frequency], ['desc', 'desc'])
def increment_link_frequency link def increment_link_frequency link
try try
@ -187,11 +189,12 @@ tag app
name = split_text.pop!.slice(1) name = split_text.pop!.slice(1)
let display_name = split_text.join(" ") let display_name = split_text.join(" ")
let is_bang = no let is_bang = no
let is_pinned = no
if display_name.startsWith "!" if display_name.startsWith "!"
is_bang = yes is_bang = yes
display_name = display_name.slice(1) display_name = display_name.slice(1)
name ||= display_name name ||= display_name
{ name, display_name, is_bang, url, frequency:0, icon } { name, display_name, is_bang, is_pinned, url, frequency:0, icon }
def handle_add def handle_add
loading = yes loading = yes
@ -301,6 +304,14 @@ tag app
handle_edit link handle_edit link
def handle_click_pin link def handle_click_pin link
link.is_pinned = !link.is_pinned
try
let result = await db.links.update link.id, link
throw "link id not found" if result is 0
catch e
return err "pinning link", e
await reload_db!
imba.commit!
p link p link
def handle_click_make_default_bang link def handle_click_make_default_bang link
@ -583,9 +594,12 @@ tag app
<.link-right> <.link-right>
<.link-buttons> <.link-buttons>
<.link-button@click.prevent.stop=handle_click_edit(link)> "E" <.link-button@click.prevent.stop=handle_click_edit(link)> "E"
<.link-button@click.prevent.stop=handle_click_pin(link)> "P"
<.link-button@click.prevent.stop=handle_click_make_default_bang(link)> "B" <.link-button@click.prevent.stop=handle_click_make_default_bang(link)> "B"
<.link-button@click.prevent.stop=handle_click_delete(link)> "D" <.link-button@click.prevent.stop=handle_click_delete(link)> "D"
<.link-button
@click.prevent.stop=handle_click_pin(link)
[visibility:visible c:purple3/50]=(link.is_pinned and index isnt selection_index)
> "P"
<.frequency> link.frequency <.frequency> link.frequency
# <[c:purple3 pt:10px fs:10px]> state.scored_links.length # <[c:purple3 pt:10px fs:10px]> state.scored_links.length
$main-input.focus! $main-input.focus!

3
app/db.imba

@ -31,13 +31,14 @@ db.version(3).stores({
link.url = parse_url(link.url).href link.url = parse_url(link.url).href
db.version(4).stores({ db.version(4).stores({
links: "++id,display_name,name,is_bang,url,frequency,icon" links: "++id,display_name,name,is_bang,is_pinned,url,frequency,icon"
}).upgrade! do |trans| }).upgrade! do |trans|
p "upgrading to fuzzyhome db version 4" p "upgrading to fuzzyhome db version 4"
trans.links.toCollection!.modify! do |link| trans.links.toCollection!.modify! do |link|
link.display_name = link.name link.display_name = link.name
link.is_bang = no link.is_bang = no
link.icon = link.img link.icon = link.img
link.is_pinned = no
delete link.img delete link.img
export default db export default db

Loading…
Cancel
Save