mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 19:46:37 +02:00
Implement search feaature in dashboard
This commit is contained in:
parent
d5f2a1a634
commit
b2843ef1ce
9 changed files with 244 additions and 33 deletions
|
@ -28,6 +28,46 @@
|
||||||
(s/def ::project-id ::us/uuid)
|
(s/def ::project-id ::us/uuid)
|
||||||
(s/def ::file-id ::us/uuid)
|
(s/def ::file-id ::us/uuid)
|
||||||
(s/def ::profile-id ::us/uuid)
|
(s/def ::profile-id ::us/uuid)
|
||||||
|
(s/def ::team-id ::us/uuid)
|
||||||
|
(s/def ::search-term ::us/string)
|
||||||
|
|
||||||
|
;; --- Query: Files search
|
||||||
|
|
||||||
|
(def ^:private sql:search-files
|
||||||
|
"with projects as (
|
||||||
|
select p.*
|
||||||
|
from project as p
|
||||||
|
inner join team_profile_rel as tpr on (tpr.team_id = p.team_id)
|
||||||
|
where tpr.profile_id = $1
|
||||||
|
and p.team_id = $2
|
||||||
|
and p.deleted_at is null
|
||||||
|
and (tpr.is_admin = true or
|
||||||
|
tpr.is_owner = true or
|
||||||
|
tpr.can_edit = true)
|
||||||
|
union
|
||||||
|
select p.*
|
||||||
|
from project as p
|
||||||
|
inner join project_profile_rel as ppr on (ppr.project_id = p.id)
|
||||||
|
where ppr.profile_id = $1
|
||||||
|
and p.team_id = $2
|
||||||
|
and p.deleted_at is null
|
||||||
|
and (ppr.is_admin = true or
|
||||||
|
ppr.is_owner = true or
|
||||||
|
ppr.can_edit = true)
|
||||||
|
)
|
||||||
|
select file.*
|
||||||
|
from file
|
||||||
|
inner join projects as pr on (file.project_id = pr.id)
|
||||||
|
where file.name ilike ('%' || $3 || '%')
|
||||||
|
order by file.created_at asc")
|
||||||
|
|
||||||
|
(s/def ::search-files
|
||||||
|
(s/keys :req-un [::profile-id ::team-id ::search-term]))
|
||||||
|
|
||||||
|
(sq/defquery ::search-files
|
||||||
|
[{:keys [profile-id team-id search-term] :as params}]
|
||||||
|
(-> (db/query db/pool [sql:search-files profile-id team-id search-term])
|
||||||
|
(p/then (partial mapv decode-row))))
|
||||||
|
|
||||||
;; --- Query: Draft Files
|
;; --- Query: Draft Files
|
||||||
|
|
||||||
|
|
|
@ -54,14 +54,38 @@
|
||||||
},
|
},
|
||||||
"unused" : true
|
"unused" : true
|
||||||
},
|
},
|
||||||
|
"dashboard.search.no-matches-for" : {
|
||||||
|
"used-in" : [ "src/uxbox/main/ui/dashboard/search.cljs:47" ],
|
||||||
|
"translations" : {
|
||||||
|
"en" : "No matches found for \"%s\""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dashboard.search.results-for" : {
|
||||||
|
"translations" : {
|
||||||
|
"en" : "Search results for \"%s\""
|
||||||
|
},
|
||||||
|
"unused" : true
|
||||||
|
},
|
||||||
|
"dashboard.search.searching-for" : {
|
||||||
|
"used-in" : [ "src/uxbox/main/ui/dashboard/search.cljs:43" ],
|
||||||
|
"translations" : {
|
||||||
|
"en" : "Searching for %s..."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dashboard.search.type-something" : {
|
||||||
|
"used-in" : [ "src/uxbox/main/ui/dashboard/search.cljs:39" ],
|
||||||
|
"translations" : {
|
||||||
|
"en" : "Type to search results"
|
||||||
|
}
|
||||||
|
},
|
||||||
"dashboard.sidebar.drafts" : {
|
"dashboard.sidebar.drafts" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui/dashboard/sidebar.cljs:112" ],
|
"used-in" : [ "src/uxbox/main/ui/dashboard/sidebar.cljs:113" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Drafts"
|
"en" : "Drafts"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dashboard.sidebar.libraries" : {
|
"dashboard.sidebar.libraries" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui/dashboard/sidebar.cljs:117" ],
|
"used-in" : [ "src/uxbox/main/ui/dashboard/sidebar.cljs:118" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Libraries"
|
"en" : "Libraries"
|
||||||
}
|
}
|
||||||
|
@ -73,7 +97,7 @@
|
||||||
"unused" : true
|
"unused" : true
|
||||||
},
|
},
|
||||||
"dashboard.sidebar.recent" : {
|
"dashboard.sidebar.recent" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui/dashboard/sidebar.cljs:105" ],
|
"used-in" : [ "src/uxbox/main/ui/dashboard/sidebar.cljs:106" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Recent"
|
"en" : "Recent"
|
||||||
}
|
}
|
||||||
|
@ -142,7 +166,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ds.default-library-title" : {
|
"ds.default-library-title" : {
|
||||||
"used-in" : [ "src/uxbox/main/data/colors.cljs:68", "src/uxbox/main/data/icons.cljs:90", "src/uxbox/main/data/images.cljs:110" ],
|
"used-in" : [ "src/uxbox/main/data/icons.cljs:90", "src/uxbox/main/data/colors.cljs:68", "src/uxbox/main/data/images.cljs:110" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Unnamed Collection (%s)",
|
"en" : "Unnamed Collection (%s)",
|
||||||
"fr" : "Collection sans nom (%s)"
|
"fr" : "Collection sans nom (%s)"
|
||||||
|
@ -220,7 +244,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ds.multiselect-bar.delete" : {
|
"ds.multiselect-bar.delete" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui/dashboard/colors.cljs:214", "src/uxbox/main/ui/dashboard/images.cljs:187", "src/uxbox/main/ui/dashboard/icons.cljs:221" ],
|
"used-in" : [ "src/uxbox/main/ui/dashboard/icons.cljs:221", "src/uxbox/main/ui/dashboard/colors.cljs:214", "src/uxbox/main/ui/dashboard/images.cljs:187" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Delete",
|
"en" : "Delete",
|
||||||
"fr" : "Supprimer"
|
"fr" : "Supprimer"
|
||||||
|
@ -276,7 +300,7 @@
|
||||||
"unused" : true
|
"unused" : true
|
||||||
},
|
},
|
||||||
"ds.search.placeholder" : {
|
"ds.search.placeholder" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui/dashboard/sidebar.cljs:140" ],
|
"used-in" : [ "src/uxbox/main/ui/dashboard/sidebar.cljs:168" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Search...",
|
"en" : "Search...",
|
||||||
"fr" : "Rechercher..."
|
"fr" : "Rechercher..."
|
||||||
|
@ -332,7 +356,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ds.uploaded-at" : {
|
"ds.uploaded-at" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui/dashboard/images.cljs:271", "src/uxbox/main/ui/dashboard/icons.cljs:309" ],
|
"used-in" : [ "src/uxbox/main/ui/dashboard/icons.cljs:309", "src/uxbox/main/ui/dashboard/images.cljs:271" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Uploaded at %s",
|
"en" : "Uploaded at %s",
|
||||||
"fr" : "Mise en ligne : %s"
|
"fr" : "Mise en ligne : %s"
|
||||||
|
@ -402,14 +426,14 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"errors.generic" : {
|
"errors.generic" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui.cljs:131" ],
|
"used-in" : [ "src/uxbox/main/ui.cljs:135" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Something wrong has happened.",
|
"en" : "Something wrong has happened.",
|
||||||
"fr" : "Quelque chose c'est mal passé."
|
"fr" : "Quelque chose c'est mal passé."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"errors.network" : {
|
"errors.network" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui.cljs:125" ],
|
"used-in" : [ "src/uxbox/main/ui.cljs:129" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Unable to connect to backend server.",
|
"en" : "Unable to connect to backend server.",
|
||||||
"fr" : "Impossible de se connecter au serveur principal."
|
"fr" : "Impossible de se connecter au serveur principal."
|
||||||
|
@ -514,7 +538,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"profile.recovery.go-to-login" : {
|
"profile.recovery.go-to-login" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui/profile/recovery.cljs:81", "src/uxbox/main/ui/profile/recovery_request.cljs:65" ],
|
"used-in" : [ "src/uxbox/main/ui/profile/recovery_request.cljs:65", "src/uxbox/main/ui/profile/recovery.cljs:81" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Go back!",
|
"en" : "Go back!",
|
||||||
"fr" : "Retour!"
|
"fr" : "Retour!"
|
||||||
|
@ -871,7 +895,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"workspace.options.color" : {
|
"workspace.options.color" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui/workspace/sidebar/options/fill.cljs:47", "src/uxbox/main/ui/workspace/sidebar/options/page.cljs:124", "src/uxbox/main/ui/workspace/sidebar/options/stroke.cljs:81" ],
|
"used-in" : [ "src/uxbox/main/ui/workspace/sidebar/options/page.cljs:124", "src/uxbox/main/ui/workspace/sidebar/options/fill.cljs:47", "src/uxbox/main/ui/workspace/sidebar/options/stroke.cljs:81" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Color",
|
"en" : "Color",
|
||||||
"fr" : "Couleur"
|
"fr" : "Couleur"
|
||||||
|
@ -913,7 +937,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"workspace.options.measures" : {
|
"workspace.options.measures" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui/workspace/sidebar/options/circle.cljs:64", "src/uxbox/main/ui/workspace/sidebar/options/frame.cljs:55", "src/uxbox/main/ui/workspace/sidebar/options/icon.cljs:66", "src/uxbox/main/ui/workspace/sidebar/options/image.cljs:62", "src/uxbox/main/ui/workspace/sidebar/options/rect.cljs:66", "src/uxbox/main/ui/workspace/sidebar/options/text.cljs:69" ],
|
"used-in" : [ "src/uxbox/main/ui/workspace/sidebar/options/text.cljs:69", "src/uxbox/main/ui/workspace/sidebar/options/icon.cljs:66", "src/uxbox/main/ui/workspace/sidebar/options/image.cljs:62", "src/uxbox/main/ui/workspace/sidebar/options/circle.cljs:64", "src/uxbox/main/ui/workspace/sidebar/options/frame.cljs:55", "src/uxbox/main/ui/workspace/sidebar/options/rect.cljs:66" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Size, position & rotation",
|
"en" : "Size, position & rotation",
|
||||||
"fr" : "Taille, position et rotation"
|
"fr" : "Taille, position et rotation"
|
||||||
|
@ -927,21 +951,21 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"workspace.options.position" : {
|
"workspace.options.position" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui/workspace/sidebar/options/circle.cljs:92", "src/uxbox/main/ui/workspace/sidebar/options/frame.cljs:84", "src/uxbox/main/ui/workspace/sidebar/options/icon.cljs:95", "src/uxbox/main/ui/workspace/sidebar/options/image.cljs:91", "src/uxbox/main/ui/workspace/sidebar/options/rect.cljs:95", "src/uxbox/main/ui/workspace/sidebar/options/text.cljs:98" ],
|
"used-in" : [ "src/uxbox/main/ui/workspace/sidebar/options/text.cljs:98", "src/uxbox/main/ui/workspace/sidebar/options/icon.cljs:95", "src/uxbox/main/ui/workspace/sidebar/options/image.cljs:91", "src/uxbox/main/ui/workspace/sidebar/options/circle.cljs:92", "src/uxbox/main/ui/workspace/sidebar/options/frame.cljs:84", "src/uxbox/main/ui/workspace/sidebar/options/rect.cljs:95" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Position",
|
"en" : "Position",
|
||||||
"fr" : "Position"
|
"fr" : "Position"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"workspace.options.rotation-radius" : {
|
"workspace.options.rotation-radius" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui/workspace/sidebar/options/circle.cljs:107", "src/uxbox/main/ui/workspace/sidebar/options/icon.cljs:112", "src/uxbox/main/ui/workspace/sidebar/options/image.cljs:108", "src/uxbox/main/ui/workspace/sidebar/options/rect.cljs:112", "src/uxbox/main/ui/workspace/sidebar/options/text.cljs:115" ],
|
"used-in" : [ "src/uxbox/main/ui/workspace/sidebar/options/text.cljs:115", "src/uxbox/main/ui/workspace/sidebar/options/icon.cljs:112", "src/uxbox/main/ui/workspace/sidebar/options/image.cljs:108", "src/uxbox/main/ui/workspace/sidebar/options/circle.cljs:107", "src/uxbox/main/ui/workspace/sidebar/options/rect.cljs:112" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Rotation & Radius",
|
"en" : "Rotation & Radius",
|
||||||
"fr" : "TODO"
|
"fr" : "TODO"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"workspace.options.size" : {
|
"workspace.options.size" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui/workspace/sidebar/options/circle.cljs:68", "src/uxbox/main/ui/workspace/sidebar/options/frame.cljs:57", "src/uxbox/main/ui/workspace/sidebar/options/icon.cljs:68", "src/uxbox/main/ui/workspace/sidebar/options/image.cljs:64", "src/uxbox/main/ui/workspace/sidebar/options/page.cljs:114", "src/uxbox/main/ui/workspace/sidebar/options/rect.cljs:68", "src/uxbox/main/ui/workspace/sidebar/options/text.cljs:71" ],
|
"used-in" : [ "src/uxbox/main/ui/workspace/sidebar/options/page.cljs:114", "src/uxbox/main/ui/workspace/sidebar/options/text.cljs:71", "src/uxbox/main/ui/workspace/sidebar/options/icon.cljs:68", "src/uxbox/main/ui/workspace/sidebar/options/image.cljs:64", "src/uxbox/main/ui/workspace/sidebar/options/circle.cljs:68", "src/uxbox/main/ui/workspace/sidebar/options/frame.cljs:57", "src/uxbox/main/ui/workspace/sidebar/options/rect.cljs:68" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
"en" : "Size",
|
"en" : "Size",
|
||||||
"fr" : "Taille"
|
"fr" : "Taille"
|
||||||
|
|
3
frontend/resources/styles/main/layouts/search-page.scss
Normal file
3
frontend/resources/styles/main/layouts/search-page.scss
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.search-page {
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
|
@ -55,6 +55,23 @@
|
||||||
;; Initialization
|
;; Initialization
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(declare search-files)
|
||||||
|
|
||||||
|
(defn initialize-search
|
||||||
|
[team-id search-term]
|
||||||
|
(ptk/reify ::initialize-search
|
||||||
|
ptk/UpdateEvent
|
||||||
|
(update [_ state]
|
||||||
|
(update state :dashboard-local assoc
|
||||||
|
:search-result nil))
|
||||||
|
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
(let [local (:dashboard-local state)]
|
||||||
|
(when-not (empty? search-term)
|
||||||
|
(rx/of (search-files team-id search-term)))))))
|
||||||
|
|
||||||
|
|
||||||
(declare fetch-files)
|
(declare fetch-files)
|
||||||
(declare fetch-projects)
|
(declare fetch-projects)
|
||||||
(declare fetch-recent-files)
|
(declare fetch-recent-files)
|
||||||
|
@ -135,6 +152,29 @@
|
||||||
(let [assoc-project #(assoc-in %1 [:projects (:id %2)] %2)]
|
(let [assoc-project #(assoc-in %1 [:projects (:id %2)] %2)]
|
||||||
(reduce assoc-project state projects)))))
|
(reduce assoc-project state projects)))))
|
||||||
|
|
||||||
|
;; --- Search Files
|
||||||
|
|
||||||
|
(declare files-searched)
|
||||||
|
|
||||||
|
(defn search-files
|
||||||
|
[team-id search-term]
|
||||||
|
(us/assert ::us/uuid team-id)
|
||||||
|
(us/assert ::us/string search-term)
|
||||||
|
(ptk/reify ::search-files
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
(->> (rp/query :search-files {:team-id team-id :search-term search-term})
|
||||||
|
(rx/map files-searched)))))
|
||||||
|
|
||||||
|
(defn files-searched
|
||||||
|
[files]
|
||||||
|
(us/verify (s/every ::file) files)
|
||||||
|
(ptk/reify ::files-searched
|
||||||
|
ptk/UpdateEvent
|
||||||
|
(update [_ state]
|
||||||
|
(update state :dashboard-local assoc
|
||||||
|
:search-result files))))
|
||||||
|
|
||||||
;; --- Fetch Files
|
;; --- Fetch Files
|
||||||
|
|
||||||
(declare files-fetched)
|
(declare files-fetched)
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
request {:method method
|
request {:method method
|
||||||
:url url
|
:url url
|
||||||
:headers headers
|
:headers headers
|
||||||
:query-string (when query (encode-query query))
|
:query query
|
||||||
:body (if (map? body) (t/encode body) body)}
|
:body (if (map? body) (t/encode body) body)}
|
||||||
options {:response-type response-type
|
options {:response-type response-type
|
||||||
:credentials? true}]
|
:credentials? true}]
|
||||||
|
|
|
@ -58,8 +58,11 @@
|
||||||
["/password" :settings-password]]
|
["/password" :settings-password]]
|
||||||
|
|
||||||
["/dashboard"
|
["/dashboard"
|
||||||
["/:team-id" :dashboard-team]
|
["/team/:team-id"
|
||||||
["/:team-id/:project-id" :dashboard-project]]
|
["/" :dashboard-team]
|
||||||
|
["/search" :dashboard-search]
|
||||||
|
["/project/:project-id" :dashboard-project]
|
||||||
|
["/library" :dashboard-library]]]
|
||||||
|
|
||||||
["/workspace/:file-id" :workspace]])
|
["/workspace/:file-id" :workspace]])
|
||||||
|
|
||||||
|
@ -84,7 +87,8 @@
|
||||||
:settings-password)
|
:settings-password)
|
||||||
(mf/element settings/settings #js {:route route})
|
(mf/element settings/settings #js {:route route})
|
||||||
|
|
||||||
(:dashboard-team
|
(:dashboard-search
|
||||||
|
:dashboard-team
|
||||||
:dashboard-project)
|
:dashboard-project)
|
||||||
(mf/element dashboard #js {:route route})
|
(mf/element dashboard #js {:route route})
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
[uxbox.main.refs :as refs]
|
[uxbox.main.refs :as refs]
|
||||||
[uxbox.main.ui.dashboard.header :refer [header]]
|
[uxbox.main.ui.dashboard.header :refer [header]]
|
||||||
[uxbox.main.ui.dashboard.sidebar :refer [sidebar]]
|
[uxbox.main.ui.dashboard.sidebar :refer [sidebar]]
|
||||||
|
[uxbox.main.ui.dashboard.search :refer [search-page]]
|
||||||
[uxbox.main.ui.dashboard.project :refer [project-page]]
|
[uxbox.main.ui.dashboard.project :refer [project-page]]
|
||||||
[uxbox.main.ui.dashboard.recent-files :refer [recent-files-page]]
|
[uxbox.main.ui.dashboard.recent-files :refer [recent-files-page]]
|
||||||
[uxbox.main.ui.dashboard.profile :refer [profile-section]]
|
[uxbox.main.ui.dashboard.profile :refer [profile-section]]
|
||||||
|
@ -30,9 +31,12 @@
|
||||||
|
|
||||||
(defn- parse-params
|
(defn- parse-params
|
||||||
[route profile]
|
[route profile]
|
||||||
(let [team-id (get-in route [:params :path :team-id])
|
(let [search-term (get-in route [:params :query :search-term])
|
||||||
|
team-id (get-in route [:params :path :team-id])
|
||||||
project-id (get-in route [:params :path :project-id])]
|
project-id (get-in route [:params :path :project-id])]
|
||||||
(cond-> {}
|
(cond->
|
||||||
|
{:search-term search-term}
|
||||||
|
|
||||||
(uuid-str? team-id)
|
(uuid-str? team-id)
|
||||||
(assoc :team-id (uuid team-id))
|
(assoc :team-id (uuid team-id))
|
||||||
|
|
||||||
|
@ -51,7 +55,7 @@
|
||||||
[{:keys [route] :as props}]
|
[{:keys [route] :as props}]
|
||||||
(let [profile (mf/deref refs/profile)
|
(let [profile (mf/deref refs/profile)
|
||||||
section (get-in route [:data :name])
|
section (get-in route [:data :name])
|
||||||
{:keys [team-id project-id]} (parse-params route profile)]
|
{:keys [search-term team-id project-id]} (parse-params route profile)]
|
||||||
[:main.dashboard-main
|
[:main.dashboard-main
|
||||||
[:& messages-widget]
|
[:& messages-widget]
|
||||||
[:section.dashboard-layout
|
[:section.dashboard-layout
|
||||||
|
@ -59,10 +63,14 @@
|
||||||
[:& profile-section {:profile profile}]
|
[:& profile-section {:profile profile}]
|
||||||
[:& sidebar {:team-id team-id
|
[:& sidebar {:team-id team-id
|
||||||
:project-id project-id
|
:project-id project-id
|
||||||
|
:search-term search-term
|
||||||
:section section}]
|
:section section}]
|
||||||
[:div.dashboard-content
|
[:div.dashboard-content
|
||||||
[:& header]
|
[:& header]
|
||||||
(case section
|
(case section
|
||||||
|
:dashboard-search
|
||||||
|
(mf/element search-page #js {:team-id team-id :search-term search-term})
|
||||||
|
|
||||||
:dashboard-team
|
:dashboard-team
|
||||||
(mf/element recent-files-page #js {:team-id team-id})
|
(mf/element recent-files-page #js {:team-id team-id})
|
||||||
|
|
||||||
|
|
51
frontend/src/uxbox/main/ui/dashboard/search.cljs
Normal file
51
frontend/src/uxbox/main/ui/dashboard/search.cljs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||||
|
;; Copyright (c) 2015-2020 Andrey Antukh <niwi@niwi.nz>
|
||||||
|
|
||||||
|
(ns uxbox.main.ui.dashboard.search
|
||||||
|
(:require
|
||||||
|
[lentes.core :as l]
|
||||||
|
[rumext.alpha :as mf]
|
||||||
|
[uxbox.main.store :as st]
|
||||||
|
[uxbox.main.data.dashboard :as dsh]
|
||||||
|
[uxbox.util.i18n :as i18n :refer [t]]
|
||||||
|
[uxbox.main.ui.dashboard.grid :refer [grid]]))
|
||||||
|
|
||||||
|
;; --- Component: Search
|
||||||
|
|
||||||
|
(def search-result-ref
|
||||||
|
(-> (l/in [:dashboard-local :search-result])
|
||||||
|
(l/derive st/state)))
|
||||||
|
|
||||||
|
(mf/defc search-page
|
||||||
|
[{:keys [team-id search-term] :as props}]
|
||||||
|
(let [search-result (mf/deref search-result-ref)
|
||||||
|
locale (i18n/use-locale)]
|
||||||
|
(mf/use-effect
|
||||||
|
{:fn #(st/emit! (dsh/initialize-search team-id search-term))
|
||||||
|
:deps (mf/deps search-term)})
|
||||||
|
[:section.search-page
|
||||||
|
[:section.dashboard-grid
|
||||||
|
[:div.dashboard-grid-content
|
||||||
|
(cond
|
||||||
|
(empty? search-term)
|
||||||
|
[:div.grid-files-empty
|
||||||
|
[:div.grid-files-desc (t locale "dashboard.search.type-something")]]
|
||||||
|
|
||||||
|
(nil? search-result)
|
||||||
|
[:div.grid-files-empty
|
||||||
|
[:div.grid-files-desc (t locale "dashboard.search.searching-for" search-term)]]
|
||||||
|
|
||||||
|
(empty? search-result)
|
||||||
|
[:div.grid-files-empty
|
||||||
|
[:div.grid-files-desc (t locale "dashboard.search.no-matches-for" search-term)]]
|
||||||
|
|
||||||
|
:else
|
||||||
|
[:& grid { :files search-result :hide-new? true}])]]]))
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[lentes.core :as l]
|
[lentes.core :as l]
|
||||||
[rumext.alpha :as mf]
|
[rumext.alpha :as mf]
|
||||||
|
[goog.functions :as f]
|
||||||
[uxbox.builtins.icons :as i]
|
[uxbox.builtins.icons :as i]
|
||||||
[uxbox.main.constants :as c]
|
[uxbox.main.constants :as c]
|
||||||
[uxbox.main.data.dashboard :as dsh]
|
[uxbox.main.data.dashboard :as dsh]
|
||||||
|
@ -84,7 +85,7 @@
|
||||||
:team-id team-id
|
:team-id team-id
|
||||||
}])))
|
}])))
|
||||||
|
|
||||||
(mf/defc sidear-team
|
(mf/defc sidebar-team
|
||||||
[{:keys [profile
|
[{:keys [profile
|
||||||
team-id
|
team-id
|
||||||
selected-section
|
selected-section
|
||||||
|
@ -125,20 +126,60 @@
|
||||||
:selected-project-id selected-project-id
|
:selected-project-id selected-project-id
|
||||||
:team-id team-id}]]))
|
:team-id team-id}]]))
|
||||||
|
|
||||||
|
|
||||||
|
(def debounced-emit! (f/debounce st/emit! 500))
|
||||||
|
|
||||||
(mf/defc sidebar
|
(mf/defc sidebar
|
||||||
[{:keys [section team-id project-id] :as props}]
|
[{:keys [section team-id project-id search-term] :as props}]
|
||||||
(let [locale (i18n/use-locale)
|
(let [locale (i18n/use-locale)
|
||||||
profile (mf/deref refs/profile)]
|
profile (mf/deref refs/profile)
|
||||||
|
search-term-not-nil (or search-term "")
|
||||||
|
|
||||||
|
on-search-focus
|
||||||
|
(fn [event]
|
||||||
|
(let [target (dom/get-target event)
|
||||||
|
value (dom/get-value target)]
|
||||||
|
(.select target)
|
||||||
|
(if (empty? value)
|
||||||
|
(debounced-emit! (rt/nav :dashboard-search {:team-id team-id} {}))
|
||||||
|
(debounced-emit! (rt/nav :dashboard-search {:team-id team-id} {:search-term value})))))
|
||||||
|
|
||||||
|
on-search-blur
|
||||||
|
(fn [event]
|
||||||
|
(let [target (dom/get-target event)]
|
||||||
|
(dom/clean-value! target)
|
||||||
|
(debounced-emit! (rt/nav :dashboard-team {:team-id team-id}))))
|
||||||
|
|
||||||
|
on-search-change
|
||||||
|
(fn [event]
|
||||||
|
(let [value (-> (dom/get-target event)
|
||||||
|
(dom/get-value))]
|
||||||
|
(debounced-emit! (rt/nav :dashboard-search {:team-id team-id} {:search-term value}))))
|
||||||
|
|
||||||
|
on-clear-click
|
||||||
|
(fn [event]
|
||||||
|
(let [search-input (dom/get-element "search-input")]
|
||||||
|
(dom/clean-value! search-input)
|
||||||
|
(.focus search-input)
|
||||||
|
(debounced-emit! (rt/nav :dashboard-search {:team-id team-id} {}))))]
|
||||||
|
|
||||||
[:div.library-bar
|
[:div.library-bar
|
||||||
[:div.library-bar-inside
|
[:div.library-bar-inside
|
||||||
[:form.dashboard-search
|
[:form.dashboard-search
|
||||||
[:input.input-text
|
[:input.input-text
|
||||||
{:key :images-search-box
|
{:key :images-search-box
|
||||||
|
:id "search-input"
|
||||||
:type "text"
|
:type "text"
|
||||||
:auto-focus true
|
:placeholder (t locale "ds.search.placeholder")
|
||||||
:placeholder (t locale "ds.search.placeholder")}]
|
:default-value search-term-not-nil
|
||||||
[:div.clear-search i/close]]
|
:autoComplete "off"
|
||||||
[:& sidear-team {:selected-team-id team-id
|
:on-focus on-search-focus
|
||||||
|
:on-blur on-search-blur
|
||||||
|
:on-change on-search-change}]
|
||||||
|
[:div.clear-search
|
||||||
|
{:on-click on-clear-click}
|
||||||
|
i/close]]
|
||||||
|
[:& sidebar-team {:selected-team-id team-id
|
||||||
:selected-project-id project-id
|
:selected-project-id project-id
|
||||||
:selected-section section
|
:selected-section section
|
||||||
:profile profile
|
:profile profile
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue