|
@ -10,11 +10,12 @@ import { nanoid } from 'nanoid' |
|
|
import { parse_url } from './utils' |
|
|
import { parse_url } from './utils' |
|
|
import initial_config from './config' |
|
|
import initial_config from './config' |
|
|
import { evaluate as eval_math } from 'mathjs' |
|
|
import { evaluate as eval_math } from 'mathjs' |
|
|
|
|
|
import community_links from './community_links' |
|
|
|
|
|
|
|
|
let state = { |
|
|
let state = { |
|
|
query: '' |
|
|
query: '' |
|
|
links: [] |
|
|
links: [] |
|
|
scored_links: [] |
|
|
sorted_links: [] |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
global._fuzzyhome_delete_everything = do |prompt=yes| |
|
|
global._fuzzyhome_delete_everything = do |prompt=yes| |
|
@ -22,6 +23,7 @@ global._fuzzyhome_delete_everything = do |prompt=yes| |
|
|
indexedDB.deleteDatabase("fuzzyhome") |
|
|
indexedDB.deleteDatabase("fuzzyhome") |
|
|
delete localStorage.fuzzyhome_config |
|
|
delete localStorage.fuzzyhome_config |
|
|
delete localStorage.fuzzyhome_visited |
|
|
delete localStorage.fuzzyhome_visited |
|
|
|
|
|
location.reload! |
|
|
|
|
|
|
|
|
p "fuzzyhome version {version}" |
|
|
p "fuzzyhome version {version}" |
|
|
|
|
|
|
|
@ -34,20 +36,22 @@ tag app |
|
|
bang = no |
|
|
bang = no |
|
|
holding_shift = no |
|
|
holding_shift = no |
|
|
editing_link = no |
|
|
editing_link = no |
|
|
|
|
|
prior_query = '' |
|
|
|
|
|
viewing_community_links = no |
|
|
|
|
|
|
|
|
get render? do mounted? |
|
|
get render? do mounted? |
|
|
|
|
|
|
|
|
def mount |
|
|
def mount |
|
|
|
|
|
unless global.localStorage.fuzzyhome_visited |
|
|
|
|
|
await add_initial_links! |
|
|
|
|
|
global.localStorage.fuzzyhome_visited = yes |
|
|
try |
|
|
try |
|
|
await reload_db! |
|
|
await reload_db! |
|
|
p state.links |
|
|
p "links:", state.links |
|
|
catch e |
|
|
catch e |
|
|
err "loading database", e |
|
|
err "loading database", e |
|
|
fatal_error = yes |
|
|
fatal_error = yes |
|
|
return |
|
|
return |
|
|
unless global.localStorage.fuzzyhome_visited |
|
|
|
|
|
await add_initial_links! |
|
|
|
|
|
global.localStorage.fuzzyhome_visited = yes |
|
|
|
|
|
await load_config! |
|
|
await load_config! |
|
|
|
|
|
|
|
|
def add_initial_links |
|
|
def add_initial_links |
|
@ -72,11 +76,10 @@ tag app |
|
|
config = JSON.parse(global.localStorage.fuzzyhome_config) |
|
|
config = JSON.parse(global.localStorage.fuzzyhome_config) |
|
|
validate_config! |
|
|
validate_config! |
|
|
catch |
|
|
catch |
|
|
p "resetting config" |
|
|
|
|
|
reset_config! |
|
|
reset_config! |
|
|
|
|
|
|
|
|
def validate_config |
|
|
def validate_config |
|
|
p config |
|
|
p "config:", config |
|
|
throw _ if config.default_bang.id == null |
|
|
throw _ if config.default_bang.id == null |
|
|
throw _ if config.default_bang.url == null |
|
|
throw _ if config.default_bang.url == null |
|
|
throw _ if config.default_bang.icon == null |
|
|
throw _ if config.default_bang.icon == null |
|
@ -100,6 +103,9 @@ tag app |
|
|
state.links = await db.links.toArray() |
|
|
state.links = await db.links.toArray() |
|
|
sort_links! |
|
|
sort_links! |
|
|
|
|
|
|
|
|
|
|
|
get selected_link |
|
|
|
|
|
state.sorted_links[selection_index] |
|
|
|
|
|
|
|
|
get tip_url |
|
|
get tip_url |
|
|
let split_query = state.query.trim!.split /\s+/ |
|
|
let split_query = state.query.trim!.split /\s+/ |
|
|
if split_query.length >= 2 |
|
|
if split_query.length >= 2 |
|
@ -120,13 +126,23 @@ tag app |
|
|
name |
|
|
name |
|
|
|
|
|
|
|
|
def sort_links |
|
|
def sort_links |
|
|
|
|
|
let links |
|
|
|
|
|
if viewing_community_links |
|
|
|
|
|
p community_links |
|
|
|
|
|
links = community_links.filter do |link| |
|
|
|
|
|
not state.links.some do |my_link| |
|
|
|
|
|
link.id is my_link.id |
|
|
|
|
|
p links |
|
|
|
|
|
else |
|
|
|
|
|
links = state.links |
|
|
|
|
|
|
|
|
if state.query.trim!.length > 0 |
|
|
if state.query.trim!.length > 0 |
|
|
if config.enable_effective_names |
|
|
if config.enable_effective_names |
|
|
state.scored_links = fzi state.links, state.query |
|
|
state.sorted_links = fzi links, state.query |
|
|
else |
|
|
else |
|
|
state.scored_links = fzi state.links, state.query, "display_name" |
|
|
state.sorted_links = fzi links, state.query, "display_name" |
|
|
else |
|
|
else |
|
|
state.scored_links = orderBy(state.links, ['is_pinned', 'frequency'], ['desc', 'desc']) |
|
|
state.sorted_links = orderBy(links, ['is_pinned', 'frequency'], ['desc', 'desc']) |
|
|
|
|
|
|
|
|
def increment_link_frequency link |
|
|
def increment_link_frequency link |
|
|
try |
|
|
try |
|
@ -138,7 +154,7 @@ tag app |
|
|
settings_active = !settings_active |
|
|
settings_active = !settings_active |
|
|
|
|
|
|
|
|
def increment_selection_index |
|
|
def increment_selection_index |
|
|
selection_index = Math.min(state.scored_links.length - 1, selection_index + 1) |
|
|
selection_index = Math.min(state.sorted_links.length - 1, selection_index + 1) |
|
|
|
|
|
|
|
|
def decrement_selection_index |
|
|
def decrement_selection_index |
|
|
selection_index = Math.max(0, selection_index - 1) |
|
|
selection_index = Math.max(0, selection_index - 1) |
|
@ -227,6 +243,7 @@ tag app |
|
|
link_text |
|
|
link_text |
|
|
|
|
|
|
|
|
def handle_edit link |
|
|
def handle_edit link |
|
|
|
|
|
prior_query = state.query |
|
|
editing_link = link |
|
|
editing_link = link |
|
|
state.query = construct_link_text(link) |
|
|
state.query = construct_link_text(link) |
|
|
|
|
|
|
|
@ -252,7 +269,9 @@ tag app |
|
|
return new_link |
|
|
return new_link |
|
|
|
|
|
|
|
|
def handle_click_link link |
|
|
def handle_click_link link |
|
|
if link.is_bang |
|
|
if viewing_community_links |
|
|
|
|
|
add_community_link link |
|
|
|
|
|
elif link.is_bang |
|
|
state.query = '' |
|
|
state.query = '' |
|
|
bang = link |
|
|
bang = link |
|
|
else |
|
|
else |
|
@ -271,9 +290,9 @@ tag app |
|
|
|
|
|
|
|
|
def handle_return |
|
|
def handle_return |
|
|
return if editing_link |
|
|
return if editing_link |
|
|
if bang or state.scored_links.length < 1 |
|
|
if bang or state.sorted_links.length < 1 |
|
|
return handle_bang! |
|
|
return handle_bang! |
|
|
let link = state.scored_links[selection_index] |
|
|
let link = selected_link |
|
|
if link.is_bang |
|
|
if link.is_bang |
|
|
state.query = '' |
|
|
state.query = '' |
|
|
bang = link |
|
|
bang = link |
|
@ -300,10 +319,14 @@ tag app |
|
|
await reload_db! |
|
|
await reload_db! |
|
|
catch e |
|
|
catch e |
|
|
err "reloading db after successful delete", e |
|
|
err "reloading db after successful delete", e |
|
|
selection_index = Math.min selection_index, state.scored_links.length - 1 |
|
|
|
|
|
|
|
|
|
|
|
loading = yes |
|
|
loading = yes |
|
|
await delete_link! |
|
|
await delete_link! |
|
|
|
|
|
state.query = prior_query |
|
|
|
|
|
prior_query = '' |
|
|
|
|
|
editing_link = no |
|
|
|
|
|
sort_links! |
|
|
|
|
|
selection_index = Math.min selection_index, state.sorted_links.length - 1 |
|
|
loading = no |
|
|
loading = no |
|
|
|
|
|
|
|
|
def handle_click_edit link |
|
|
def handle_click_edit link |
|
@ -325,38 +348,50 @@ tag app |
|
|
config.default_bang = editing_link |
|
|
config.default_bang = editing_link |
|
|
save_config! |
|
|
save_config! |
|
|
editing_link = no |
|
|
editing_link = no |
|
|
state.query = '' |
|
|
state.query = prior_query |
|
|
|
|
|
prior_query = '' |
|
|
sort_links! |
|
|
sort_links! |
|
|
|
|
|
|
|
|
def handle_shift_backspace |
|
|
def handle_shift_backspace |
|
|
if editing_link |
|
|
if editing_link |
|
|
await handle_delete editing_link |
|
|
await handle_delete editing_link |
|
|
editing_link = no |
|
|
|
|
|
state.query = '' |
|
|
|
|
|
sort_links! |
|
|
|
|
|
else |
|
|
else |
|
|
return unless state.scored_links.length > 0 |
|
|
return unless state.sorted_links.length > 0 |
|
|
handle_edit state.scored_links[selection_index] |
|
|
handle_edit selected_link |
|
|
|
|
|
|
|
|
|
|
|
def add_community_link link |
|
|
|
|
|
await db.links.add link |
|
|
|
|
|
await reload_db! |
|
|
|
|
|
imba.commit! |
|
|
|
|
|
|
|
|
def handle_shift_return |
|
|
def handle_shift_return |
|
|
def go |
|
|
def go |
|
|
if editing_link |
|
|
if viewing_community_links |
|
|
|
|
|
try |
|
|
|
|
|
await add_community_link selected_link |
|
|
|
|
|
catch e |
|
|
|
|
|
err "adding community link", e |
|
|
|
|
|
elif editing_link |
|
|
try |
|
|
try |
|
|
await update_link editing_link, state.query |
|
|
await update_link editing_link, state.query |
|
|
editing_link = no |
|
|
|
|
|
state.query = '' |
|
|
|
|
|
sort_links! |
|
|
|
|
|
catch e |
|
|
catch e |
|
|
err "updating link", e |
|
|
err "updating link", e |
|
|
else |
|
|
else |
|
|
handle_add! |
|
|
handle_add! |
|
|
loading = yes |
|
|
loading = yes |
|
|
await go! |
|
|
await go! |
|
|
|
|
|
editing_link = no |
|
|
|
|
|
state.query = '' |
|
|
|
|
|
sort_links! |
|
|
loading = no |
|
|
loading = no |
|
|
|
|
|
|
|
|
def handle_esc |
|
|
def handle_esc |
|
|
|
|
|
if editing_link |
|
|
editing_link = no |
|
|
editing_link = no |
|
|
state.query = '' |
|
|
state.query = prior_query |
|
|
|
|
|
prior_query = '' |
|
|
|
|
|
elif viewing_community_links |
|
|
|
|
|
viewing_community_links = no |
|
|
sort_links! |
|
|
sort_links! |
|
|
|
|
|
|
|
|
def handle_click_add |
|
|
def handle_click_add |
|
@ -457,6 +492,11 @@ tag app |
|
|
state.query = '' |
|
|
state.query = '' |
|
|
sort_links! |
|
|
sort_links! |
|
|
|
|
|
|
|
|
|
|
|
def handle_click_view_community_links |
|
|
|
|
|
viewing_community_links = yes |
|
|
|
|
|
settings_active = no |
|
|
|
|
|
sort_links! |
|
|
|
|
|
|
|
|
def render |
|
|
def render |
|
|
|
|
|
|
|
|
css .disabled * |
|
|
css .disabled * |
|
@ -593,6 +633,11 @@ tag app |
|
|
<.settings-button |
|
|
<.settings-button |
|
|
@click=(settings_active = no) |
|
|
@click=(settings_active = no) |
|
|
> "BACK" |
|
|
> "BACK" |
|
|
|
|
|
<.settings-container> |
|
|
|
|
|
<.settings-button |
|
|
|
|
|
@click.if(!loading)=handle_click_view_community_links |
|
|
|
|
|
> |
|
|
|
|
|
"VIEW COMMUNITY LINKS" |
|
|
<.settings-container> |
|
|
<.settings-container> |
|
|
<label.settings-button> |
|
|
<label.settings-button> |
|
|
"IMPORT" |
|
|
"IMPORT" |
|
@ -693,7 +738,22 @@ tag app |
|
|
<.side.right @click.if(!loading)=toggle_settings> |
|
|
<.side.right @click.if(!loading)=toggle_settings> |
|
|
<svg src="./assets/settings.svg"> |
|
|
<svg src="./assets/settings.svg"> |
|
|
|
|
|
|
|
|
if config.enable_tips and not config.enable_simplify_ui |
|
|
if viewing_community_links |
|
|
|
|
|
<.middle-button> |
|
|
|
|
|
|
|
|
|
|
|
<.tip[jc:start ta:center fl:1] |
|
|
|
|
|
@click=handle_esc |
|
|
|
|
|
> |
|
|
|
|
|
<.tip-hotkey> "Esc" |
|
|
|
|
|
<.tip-content> "Exit Community Links" |
|
|
|
|
|
|
|
|
|
|
|
<.tip[jc:end ta:center fl:1] |
|
|
|
|
|
@click=handle_shift_return |
|
|
|
|
|
> |
|
|
|
|
|
<.tip-hotkey> "Shift + Return" |
|
|
|
|
|
<.tip-content> "Add To Your Links" |
|
|
|
|
|
|
|
|
|
|
|
elif config.enable_tips and not config.enable_simplify_ui |
|
|
if editing_link |
|
|
if editing_link |
|
|
<.middle-button> |
|
|
<.middle-button> |
|
|
|
|
|
|
|
@ -755,7 +815,7 @@ tag app |
|
|
|
|
|
|
|
|
unless editing_link |
|
|
unless editing_link |
|
|
<.links> |
|
|
<.links> |
|
|
if bang or state.scored_links.length < 1 |
|
|
if not viewing_community_links and (bang or state.sorted_links.length < 1) |
|
|
<a.link.selected |
|
|
<a.link.selected |
|
|
href=encoded_bang_query |
|
|
href=encoded_bang_query |
|
|
@click=handle_click_bang |
|
|
@click=handle_click_bang |
|
@ -766,7 +826,7 @@ tag app |
|
|
<.link-right[jc:flex-end]> |
|
|
<.link-right[jc:flex-end]> |
|
|
<.frequency> active_bang.frequency |
|
|
<.frequency> active_bang.frequency |
|
|
else |
|
|
else |
|
|
for link, index in state.scored_links |
|
|
for link, index in state.sorted_links |
|
|
<a.link |
|
|
<a.link |
|
|
href=link.url |
|
|
href=link.url |
|
|
@pointerover=(selection_index = index) |
|
|
@pointerover=(selection_index = index) |
|
|