diff --git a/app/api.imba b/app/api.imba
index edd8957..6df2695 100644
--- a/app/api.imba
+++ b/app/api.imba
@@ -80,10 +80,14 @@ export default new class api
def sort_links
if state.query.trim!.length <= 0
- return state.sorted_links = orderBy(state.links, ['is_pinned', 'frequency'], ['desc', 'desc'])
- if config.data.enable_effective_names
- return state.sorted_links = fzi state.links, state.query
- state.sorted_links = fzi state.links, state.query, "display_name"
+ state.sorted_links = orderBy(state.links, ['is_pinned', 'frequency'], ['desc', 'desc'])
+ elif config.data.enable_effective_names
+ state.sorted_links = fzi.sort state.query, state.links, do |x| x.name
+ else
+ state.sorted_links = fzi.sort state.query, state.links, do |x| x.display_name
+
+ def name_exists new_name
+ state.links.some! do |{name}| new_name is name
def add_initial_links
let initial_links = [
@@ -102,7 +106,7 @@ export default new class api
catch e
err "adding link", e
- def create_link_from_text text
+ def create_link_from_text text, get_icon=yes
text = text.trim!
throw "Text is empty." if text is ''
let split_text = text.split(/\s+/)
@@ -110,7 +114,6 @@ export default new class api
let url = split_text.pop!
let host
{ href:url, host } = parse_url url
- let icon = await fetch_image_as_base_64 host
let name
if split_text[-1].startsWith "`"
name = split_text.pop!.slice(1)
@@ -121,7 +124,10 @@ export default new class api
is_bang = yes
display_name = display_name.slice(1)
name ||= display_name
- { name, display_name, is_bang, is_pinned, url, frequency:0, icon }
+ let link = { name, display_name, is_bang, is_pinned, url, frequency:0 }
+ if get_icon
+ link.icon = await fetch_image_as_base_64 host
+ return link
def fetch_image_as_base_64 host
let fallback = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAH0lEQVR42mO8seXffwYqAsZRA0cNHDVw1MBRA0eqgQCDRkbJSQHxEQAAAABJRU5ErkJggg=='
diff --git a/app/components/app-community-links.imba b/app/components/app-community-links.imba
index 0f1b07d..a73a934 100644
--- a/app/components/app-community-links.imba
+++ b/app/components/app-community-links.imba
@@ -1,14 +1,37 @@
let p = console.log
-import links from '../assets/community_links'
+import all_links from '../assets/community_links'
import fzi from 'fzi'
+import api from '../api'
tag app-community-links
- active = yes
+ active = no
selection_index = 0
+ query = ""
+
+ get render? do mounted?
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]
def open
active = yes
@@ -22,27 +45,31 @@ tag app-community-links
def decrement_selection_index
selection_index = Math.max(0, selection_index - 1)
- def get_link_obj link_text
- let split_text = link_text.trim!.split /\s+/
- let url = split_text.pop!
- let rest = split_text.join " "
- { url, rest }
-
- def add_community_link link
- await db.links.add link
- await api.reload_db!
- imba.commit!
+ 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
get tips
let result = []
result.push <>
- <.tip @click=close>
+ <.tip
+ @click=close
+ @hotkey("esc").force=close
+ >
<.tip-hotkey> "Esc"
<.tip-content> "Exit Community Links"
result.push <>
- <.tip @click=handle_shift_return>
+ <.tip
+ @click=add_community_link
+ @hotkey("shift+return").force=add_community_link
+ >
<.tip-hotkey> "Shift + Return Or Click"
<.tip-content> "Add To Your Links"
@@ -62,28 +89,30 @@ tag app-community-links
css d:flex fld:column jc:start gap:15px fl:1 w:100% ofy:hidden
-
+
<.links>
css ofy:auto
- for link_text, index in links
+ for link, index in sorted_links
<.link
.selected=(selection_index == index)
@pointerover=(selection_index = index)
- @click=(add_community_link(link_text))
+ @click=add_community_link
>
css d:flex fld:row jc:space-between ai:center px:16px
- py:11px rd:5px cursor:pointer c:blue3 min-height:35px
+ py:2px rd:5px cursor:pointer c:blue3 min-height:35px
- let { url, rest } = get_link_obj link_text
+ if link.is_bang
+ css c:#FAD4AB
- <.link-left> rest
+ <.link-left> link.name
css fl:1
- if rest.startsWith("!")
- css c:#FAD4AB
- <.link-right> url
- css fl:1 overflow-wrap:anywhere word-break:break-all
+ link.url
+ css fl:1 c:inherit
diff --git a/app/components/app-settings.imba b/app/components/app-settings.imba
index d7a2741..cd4fbc7 100644
--- a/app/components/app-settings.imba
+++ b/app/components/app-settings.imba
@@ -35,9 +35,6 @@ tag app-settings
def handle_click_import e
- def name_exists new_name
- state.links.some! do |{name}| new_name is name
-
def handle_import
let errors = []
try
@@ -48,7 +45,7 @@ tag app-settings
for link_text in links
try
let link = await api.create_link_from_text link_text
- if name_exists link.name
+ if api.name_exists link.name
throw "Name already exists, add manually if you don't mind duplicates."
api.add_link link_text
catch e
diff --git a/package-lock.json b/package-lock.json
index 3fe66fa..3fcc6b7 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -11,8 +11,8 @@
"dexie": "^3.2.2",
"dexie-export-import": "^1.0.3",
"downloadjs": "^1.4.7",
- "fzi": "^1.0.0",
- "imba": "^2.0.0-alpha.219",
+ "fzi": "^1.1.0",
+ "imba": "^2.0.0-alpha.220",
"lodash": "^4.17.21",
"mathjs": "^11.1.0",
"nanoid": "^4.0.0"
@@ -516,9 +516,9 @@
}
},
"node_modules/fzi": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/fzi/-/fzi-1.0.0.tgz",
- "integrity": "sha512-ZsF/SPkQVWrVPvhkKRivf7pM8LC1kMQmWPXPlbHIdQPL10a6Q9eiVbCJfmEVRFbZafd66DQMC8brfpORxSaKKA=="
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/fzi/-/fzi-1.1.0.tgz",
+ "integrity": "sha512-5bqCChh+i3RQ2Acl+FGg7JnxONXLaWDl4g/JLbRJE+zV5zX0GI0ScpKr/MzgDqzRnhkqy58J6kVy+GfDv2QSFw=="
},
"node_modules/glob-parent": {
"version": "5.1.2",
@@ -532,9 +532,9 @@
}
},
"node_modules/imba": {
- "version": "2.0.0-alpha.219",
- "resolved": "https://registry.npmjs.org/imba/-/imba-2.0.0-alpha.219.tgz",
- "integrity": "sha512-5BIUK9DBNDvprJ/hPezfg4dk6w96j/yOCWU35O/CKpLx8ce+k/u534HYrdQNGZqfTY7ImSA5uRduVbp1zKi9Wg==",
+ "version": "2.0.0-alpha.220",
+ "resolved": "https://registry.npmjs.org/imba/-/imba-2.0.0-alpha.220.tgz",
+ "integrity": "sha512-Q2Kiqb7kLKfVZ19kje0PWgWR4K+0Nt3RmY2RD13AkhEz2Wksdr3Sj1PGJazy2gW/xC18ILB2MgPplXxzGr3dWQ==",
"dependencies": {
"chokidar": "^3.4.3",
"esbuild": "^0.15.2"
@@ -945,9 +945,9 @@
"optional": true
},
"fzi": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/fzi/-/fzi-1.0.0.tgz",
- "integrity": "sha512-ZsF/SPkQVWrVPvhkKRivf7pM8LC1kMQmWPXPlbHIdQPL10a6Q9eiVbCJfmEVRFbZafd66DQMC8brfpORxSaKKA=="
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/fzi/-/fzi-1.1.0.tgz",
+ "integrity": "sha512-5bqCChh+i3RQ2Acl+FGg7JnxONXLaWDl4g/JLbRJE+zV5zX0GI0ScpKr/MzgDqzRnhkqy58J6kVy+GfDv2QSFw=="
},
"glob-parent": {
"version": "5.1.2",
@@ -958,9 +958,9 @@
}
},
"imba": {
- "version": "2.0.0-alpha.219",
- "resolved": "https://registry.npmjs.org/imba/-/imba-2.0.0-alpha.219.tgz",
- "integrity": "sha512-5BIUK9DBNDvprJ/hPezfg4dk6w96j/yOCWU35O/CKpLx8ce+k/u534HYrdQNGZqfTY7ImSA5uRduVbp1zKi9Wg==",
+ "version": "2.0.0-alpha.220",
+ "resolved": "https://registry.npmjs.org/imba/-/imba-2.0.0-alpha.220.tgz",
+ "integrity": "sha512-Q2Kiqb7kLKfVZ19kje0PWgWR4K+0Nt3RmY2RD13AkhEz2Wksdr3Sj1PGJazy2gW/xC18ILB2MgPplXxzGr3dWQ==",
"requires": {
"chokidar": "^3.4.3",
"esbuild": "^0.15.2"
diff --git a/package.json b/package.json
index a55888d..5a1ecba 100644
--- a/package.json
+++ b/package.json
@@ -14,8 +14,8 @@
"dexie": "^3.2.2",
"dexie-export-import": "^1.0.3",
"downloadjs": "^1.4.7",
- "fzi": "^1.0.0",
- "imba": "^2.0.0-alpha.219",
+ "fzi": "^1.1.0",
+ "imba": "^2.0.0-alpha.220",
"lodash": "^4.17.21",
"mathjs": "^11.1.0",
"nanoid": "^4.0.0"