Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split out emoji-autocomplete as a seperate module
- Loading branch information
Showing
9 changed files
with
181 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(ns braid.core.api | ||
(:require | ||
[re-frame.core :as re-frame])) | ||
|
||
(def dispatch re-frame/dispatch) | ||
(def reg-event-fx re-frame/reg-event-fx) | ||
(def reg-sub re-frame/reg-sub) | ||
|
||
(reg-event-fx :braid.core/init-state | ||
(fn [{db :db} [_ state]] | ||
{:db (merge db state)})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(ns braid.core.modules | ||
(:require | ||
[braid.client.ui.views.autocomplete] | ||
[braid.emoji.core])) | ||
|
||
(defn init [] | ||
(braid.emoji.core/init)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(ns braid.emoji.core | ||
(:require | ||
[clojure.string :as string] | ||
[braid.core.api :as api] | ||
[braid.emoji.helpers :as helpers])) | ||
|
||
(defn simple-matches? | ||
[m s] | ||
(not= -1 (.indexOf m s))) | ||
|
||
(defn emoji-view | ||
[emoji] | ||
[:div.emoji.match | ||
(helpers/shortcode->html (string/replace emoji #"[\(\)]" ":")) | ||
[:div.name emoji] | ||
[:div.extra "..."]]) | ||
|
||
(defn autocomplete-handler [text] | ||
(let [pattern #"\B[:(](\S{2,})$"] | ||
(when-let [query (second (re-find pattern text))] | ||
(->> helpers/unicode | ||
(filter (fn [[k v]] | ||
(simple-matches? k query))) | ||
(map (fn [[k v]] | ||
{:key | ||
(fn [] k) | ||
:action | ||
(fn []) | ||
:message-transform | ||
(fn [text] | ||
(string/replace text pattern (str k " "))) | ||
:html | ||
(fn [] | ||
[emoji-view (let [show-brackets? (= "(" (first text)) | ||
emoji-name (apply str (-> k rest butlast))] | ||
(if show-brackets? | ||
(str "(" emoji-name ")") k)) | ||
{:react-key k}])})))))) | ||
|
||
(defn init [] | ||
(api/dispatch [:braid.core/register-autocomplete-engine autocomplete-handler])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
(ns braid.client.emoji) | ||
(ns braid.emoji.helpers) | ||
|
||
(declare unicode ascii) | ||
|
||
|