From ce1cbfa9d92fdb201cc8d56ec0b9205180f29ca7 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 17 Mar 2020 10:33:07 +0100 Subject: [PATCH] :fire: Remove unused and deprecated namespace. --- frontend/src/uxbox/main/data/history.cljs | 4 +- frontend/src/uxbox/main/data/projects.cljs | 270 ------------------ frontend/src/uxbox/main/data/undo.cljs | 107 ------- frontend/src/uxbox/main/data/workspace.cljs | 4 +- frontend/src/uxbox/main/ui.cljs | 1 - .../src/uxbox/main/ui/dashboard/grid.cljs | 1 - .../src/uxbox/main/ui/dashboard/profile.cljs | 1 - .../uxbox/main/ui/dashboard/recent_files.cljs | 1 - .../src/uxbox/main/ui/dashboard/sidebar.cljs | 3 +- .../src/uxbox/main/ui/settings/header.cljs | 1 - .../src/uxbox/main/ui/workspace/header.cljs | 5 +- 11 files changed, 7 insertions(+), 391 deletions(-) delete mode 100644 frontend/src/uxbox/main/data/projects.cljs diff --git a/frontend/src/uxbox/main/data/history.cljs b/frontend/src/uxbox/main/data/history.cljs index e3cda935c..6112736fd 100644 --- a/frontend/src/uxbox/main/data/history.cljs +++ b/frontend/src/uxbox/main/data/history.cljs @@ -10,7 +10,7 @@ [cljs.spec.alpha :as s] [potok.core :as ptk] [uxbox.common.spec :as us] - [uxbox.main.data.projects :as dp] + [uxbox.common.pages :as cp] [uxbox.main.repo :as rp] [uxbox.util.data :refer [replace-by-id index-by]])) @@ -26,7 +26,7 @@ (s/def ::user uuid?) (s/def ::shapes - (s/every ::dp/minimal-shape :kind vector?)) + (s/every ::cp/minimal-shape :kind vector?)) (s/def ::data (s/keys :req-un [::shapes])) diff --git a/frontend/src/uxbox/main/data/projects.cljs b/frontend/src/uxbox/main/data/projects.cljs deleted file mode 100644 index 569f55ccc..000000000 --- a/frontend/src/uxbox/main/data/projects.cljs +++ /dev/null @@ -1,270 +0,0 @@ -;; 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/. -;; -;; Copyright (c) 2015-2017 Andrey Antukh - -;; NOTE: this namespace is deprecated and will be removed when new -;; dashboard is implemented. Is just maintained as a temporal solution -;; for have the old dashboard code "working". - - -(ns uxbox.main.data.projects - (:require - [beicon.core :as rx] - [cljs.spec.alpha :as s] - [cuerdas.core :as str] - [potok.core :as ptk] - [uxbox.common.pages :as cp] - [uxbox.common.spec :as us] - [uxbox.main.repo :as rp] - [uxbox.util.router :as rt] - [uxbox.util.time :as dt] - [uxbox.util.timers :as ts] - [uxbox.util.uuid :as uuid])) - -;; WARN: this file is deprecated. - -;; --- Specs - -(s/def ::id ::us/uuid) -(s/def ::name string?) -(s/def ::profile-id ::us/uuid) -(s/def ::project-id (s/nilable ::us/uuid)) -(s/def ::created-at ::us/inst) -(s/def ::modified-at ::us/inst) - -(s/def ::project - (s/keys ::req-un [::id - ::name - ::version - ::profile-id - ::created-at - ::modified-at])) - -(s/def ::file - (s/keys :req-un [::id - ::name - ::created-at - ::modified-at - ::project-id])) - - -;; --- Initialize Dashboard - -(declare fetch-projects) -(declare fetch-files) -(declare fetch-draft-files) -(declare initialized) - -;; NOTE/WARN: this need to be refactored completly when new UI is -;; prototyped. - -(defn initialize - [id] - (ptk/reify ::initialize - ptk/UpdateEvent - (update [_ state] - (update state :dashboard-projects assoc :id id)) - - ptk/WatchEvent - (watch [_ state stream] - (rx/merge - (if (nil? id) - (rx/of fetch-draft-files) - (rx/of (fetch-files id))) - (->> stream - (rx/filter (ptk/type? ::files-fetched)) - (rx/take 1) - (rx/map #(initialized id (deref %)))))))) - -(defn initialized - [id files] - (ptk/reify ::initialized - ptk/UpdateEvent - (update [_ state] - (let [files (into #{} (map :id) files)] - (update-in state [:dashboard-projects :files] assoc id files))))) - -;; --- Update Opts (Filtering & Ordering) - -(defn update-opts - [& {:keys [order filter] :as opts}] - (ptk/reify ::update-opts - ptk/UpdateEvent - (update [_ state] - (update state :dashboard-projects merge - (when order {:order order}) - (when filter {:filter filter}))))) - -;; --- Fetch Projects - -(declare projects-fetched) - -(def fetch-projects - (ptk/reify ::fetch-projects - ptk/WatchEvent - (watch [_ state stream] - (->> (rp/query :projects) - (rx/map projects-fetched))))) - -;; --- Projects Fetched - -(defn projects-fetched - [projects] - (us/verify (s/every ::project) projects) - (ptk/reify ::projects-fetched - ptk/UpdateEvent - (update [_ state] - (let [assoc-project #(update-in %1 [:projects (:id %2)] merge %2)] - (reduce assoc-project state projects))))) - -;; --- Fetch Files - -(declare files-fetched) - -(defn fetch-files - [project-id] - (ptk/reify ::fetch-files - ptk/WatchEvent - (watch [_ state stream] - (let [params (if (nil? project-id) {} {:project-id project-id})] - (->> (rp/query :files params) - (rx/map files-fetched)))))) - -(def fetch-draft-files - (ptk/reify ::fetch-draft-files - ptk/WatchEvent - (watch [_ state stream] - (->> (rp/query :draft-files {}) - (rx/map files-fetched))))) - -;; --- Fetch File (by ID) - -(defn fetch-file - [id] - (us/verify ::us/uuid id) - (ptk/reify ::fetch-file - ptk/WatchEvent - (watch [_ state stream] - (->> (rp/query :file {:id id}) - (rx/map #(files-fetched [%])))))) - -;; --- Create File - -(defn create-file - [{:keys [project-id] :as params}] - (ptk/reify ::create-file - ptk/WatchEvent - (watch [this state stream] - (let [name (str "New File " (gensym "p")) - params {:name name :project-id project-id}] - (->> (rp/mutation! :create-file params) - (rx/mapcat - (fn [data] - (rx/of (files-fetched [data]) - #(update-in % [:dashboard-projects :files project-id] conj (:id data)))))))))) - -(declare file-created) - -(def create-draft-file - (ptk/reify ::create-draft-file - ptk/WatchEvent - (watch [this state stream] - (let [name (str "New File " (gensym "p")) - params {:name name}] - (->> (rp/mutation! :create-draft-file params) - (rx/map file-created)))))) - -(defn file-created - [data] - (us/verify ::file data) - (ptk/reify ::create-draft-file - ptk/UpdateEvent - (update [this state] - (update state :files assoc (:id data) data)))) - -;; --- Rename Project - -(defn rename-project - [id name] - {:pre [(uuid? id) (string? name)]} - (ptk/reify ::rename-project - ptk/UpdateEvent - (update [_ state] - (assoc-in state [:projects id :name] name)) - - ptk/WatchEvent - (watch [_ state stream] - (let [params {:id id :name name}] - (->> (rp/mutation :rename-project params) - (rx/ignore)))))) - -;; --- Delete Project (by id) - -(defn delete-project - [id] - (us/verify ::us/uuid id) - (ptk/reify ::delete-project - ptk/UpdateEvent - (update [_ state] - (update state :projects dissoc id)) - - ptk/WatchEvent - (watch [_ state s] - (->> (rp/mutation :delete-project {:id id}) - (rx/ignore))))) - -;; --- Delete File (by id) - -(defn delete-file - [id] - (us/verify ::us/uuid id) - (ptk/reify ::delete-file - ptk/UpdateEvent - (update [_ state] - (update state :files dissoc id)) - - ptk/WatchEvent - (watch [_ state s] - (->> (rp/mutation :delete-file {:id id}) - (rx/ignore))))) - -;; --- Rename Project - -(defn rename-file - [id name] - {:pre [(uuid? id) (string? name)]} - (ptk/reify ::rename-file - ptk/UpdateEvent - (update [_ state] - (assoc-in state [:files id :name] name)) - - ptk/WatchEvent - (watch [_ state stream] - (let [params {:id id :name name}] - (->> (rp/mutation :rename-file params) - (rx/ignore)))))) - -;; --- Go To Project - -(defn go-to - [file-id] - (us/verify ::us/uuid file-id) - (ptk/reify ::go-to - ptk/WatchEvent - (watch [_ state stream] - (let [page-ids (get-in state [:files file-id :pages])] - (let [path-params {:file-id file-id} - query-params {:page-id (first page-ids)}] - (rx/of (rt/nav :workspace path-params query-params))))))) - -(defn go-to-project - [id] - (us/verify (s/nilable ::us/uuid) id) - (ptk/reify ::go-to-project - ptk/WatchEvent - (watch [_ state stream] - (if (nil? id) - (rx/of (rt/nav :dashboard-projects {} {})) - (rx/of (rt/nav :dashboard-projects {} {:project-id (str id)})))))) diff --git a/frontend/src/uxbox/main/data/undo.cljs b/frontend/src/uxbox/main/data/undo.cljs index d4d2064d2..e8dd9a884 100644 --- a/frontend/src/uxbox/main/data/undo.cljs +++ b/frontend/src/uxbox/main/data/undo.cljs @@ -10,112 +10,5 @@ [cljs.spec.alpha :as s] [potok.core :as ptk] [uxbox.common.spec :as us] - [uxbox.main.data.projects :as dp] [uxbox.main.store :as st])) -(def MAX-STACK-SIZE 50) - -;; --- Watch Page Changes - -(declare save-undo-entry) -(declare save-undo-entry?) -(declare undo?) -(declare redo?) - -(defn watch-page-changes - [id] - (us/verify ::us/uuid id) - (ptk/reify ::watch-page-changes - ptk/WatchEvent - (watch [_ state stream] - #_(let [stopper (rx/filter #(= % ::dp/stop-page-watcher) stream)] - (->> stream - (rx/filter dp/page-update?) - (rx/filter #(not (undo? %))) - (rx/filter #(not (redo? %))) - (rx/map #(save-undo-entry id)) - (rx/take-until stopper)))))) - -;; -- Save Undo Entry - -(defn save-undo-entry - [id] - (us/verify ::us/uuid id) - (letfn [(cons-entry [stack entry] - (let [stack (cons entry stack)] - (if (> (count stack) MAX-STACK-SIZE) - (take MAX-STACK-SIZE stack) - stack)))] - (ptk/reify ::save-undo-entry - ptk/UpdateEvent - (update [_ state] - #_(let [page (dp/pack-page state id) - undo {:data (:data page) - :metadata (:metadata page)}] - (-> state - (update-in [:undo id :stack] cons-entry undo) - (assoc-in [:undo id :selected] 0))))))) - -(defn save-undo-entry? - [v] - (= (ptk/type v) ::save-undo-entry)) - -;; --- Select Previous Entry - -(def undo - (ptk/reify ::undo - ptk/UpdateEvent - (update [_ state] - #_(let [pid (get-in state [:workspace :current]) - {:keys [stack selected] :as ustate} (get-in state [:undo pid])] - (if (>= selected (dec (count stack))) - state - (let [pointer (inc selected) - page (get-in state [:pages pid]) - undo (nth stack pointer) - data (:data undo) - metadata (:metadata undo) - packed (assoc page :data data :metadata metadata)] - - ;; (println "Undo: pointer=" pointer) - ;; (println "Undo: packed=") - ;; (pp/pprint packed) - - (-> state - (dp/unpack-page packed) - (assoc-in [:undo pid :selected] pointer)))))))) - -(defn undo? - [v] - (= (ptk/type v) ::undo)) - -;; --- Select Next Entry - -(def redo - (ptk/reify ::redo - ptk/UpdateEvent - (update [_ state] - #_(let [pid (get-in state [:workspace :current]) - undo-state (get-in state [:undo pid]) - stack (:stack undo-state) - selected (:selected undo-state)] - (if (or (nil? selected) (zero? selected)) - state - (let [pointer (dec selected) - undo (nth stack pointer) - data (:data undo) - metadata (:metadata undo) - page (get-in state [:pages pid]) - packed (assoc page :data data :metadata metadata)] - - ;; (println "Redo: pointer=" pointer) - ;; (println "Redo: packed=") - ;; (pp/pprint packed) - - (-> state - (dp/unpack-page packed) - (assoc-in [:undo pid :selected] pointer)))))))) - -(defn redo? - [v] - (= (ptk/type v) ::redo)) diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index bfa5ed36c..52d82368c 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -20,7 +20,7 @@ [uxbox.config :as cfg] [uxbox.main.constants :as c] [uxbox.main.data.icons :as udi] - [uxbox.main.data.projects :as dp] + [uxbox.main.data.dashboard :as dd] [uxbox.main.geom :as geom] [uxbox.main.refs :as refs] [uxbox.main.repo :as rp] @@ -444,7 +444,7 @@ (s/def ::metadata (s/nilable ::cp/metadata)) (s/def ::data ::cp/data) -(s/def ::file ::dp/file) +(s/def ::file ::dd/file) (s/def ::page (s/keys :req-un [::id ::name diff --git a/frontend/src/uxbox/main/ui.cljs b/frontend/src/uxbox/main/ui.cljs index 1ba0bd6b6..58d55926c 100644 --- a/frontend/src/uxbox/main/ui.cljs +++ b/frontend/src/uxbox/main/ui.cljs @@ -19,7 +19,6 @@ [uxbox.builtins.icons :as i] [uxbox.common.exceptions :as ex] [uxbox.main.data.auth :refer [logout]] - [uxbox.main.data.projects :as dp] [uxbox.main.refs :as refs] [uxbox.main.store :as st] [uxbox.main.ui.dashboard :refer [dashboard]] diff --git a/frontend/src/uxbox/main/ui/dashboard/grid.cljs b/frontend/src/uxbox/main/ui/dashboard/grid.cljs index ad158643b..55f2762a0 100644 --- a/frontend/src/uxbox/main/ui/dashboard/grid.cljs +++ b/frontend/src/uxbox/main/ui/dashboard/grid.cljs @@ -4,7 +4,6 @@ [cuerdas.core :as str] [rumext.alpha :as mf] [uxbox.builtins.icons :as i] - [uxbox.main.data.projects :as udp] [uxbox.main.data.dashboard :as dsh] [uxbox.main.store :as st] [uxbox.main.exports :as exports] diff --git a/frontend/src/uxbox/main/ui/dashboard/profile.cljs b/frontend/src/uxbox/main/ui/dashboard/profile.cljs index b06e817df..688e31678 100644 --- a/frontend/src/uxbox/main/ui/dashboard/profile.cljs +++ b/frontend/src/uxbox/main/ui/dashboard/profile.cljs @@ -15,7 +15,6 @@ [rumext.alpha :as mf] [uxbox.builtins.icons :as i] [uxbox.main.data.auth :as da] - [uxbox.main.data.projects :as dp] [uxbox.main.store :as st] [uxbox.main.refs :as refs] [uxbox.main.ui.navigation :as nav] diff --git a/frontend/src/uxbox/main/ui/dashboard/recent_files.cljs b/frontend/src/uxbox/main/ui/dashboard/recent_files.cljs index cbfbda1cc..2936a778e 100644 --- a/frontend/src/uxbox/main/ui/dashboard/recent_files.cljs +++ b/frontend/src/uxbox/main/ui/dashboard/recent_files.cljs @@ -15,7 +15,6 @@ [uxbox.builtins.icons :as i] [uxbox.common.exceptions :as ex] [uxbox.main.constants :as c] - [uxbox.main.data.projects :as udp] [uxbox.main.data.dashboard :as dsh] [uxbox.main.store :as st] [uxbox.main.exports :as exports] diff --git a/frontend/src/uxbox/main/ui/dashboard/sidebar.cljs b/frontend/src/uxbox/main/ui/dashboard/sidebar.cljs index f52941336..7e6da96cd 100644 --- a/frontend/src/uxbox/main/ui/dashboard/sidebar.cljs +++ b/frontend/src/uxbox/main/ui/dashboard/sidebar.cljs @@ -15,7 +15,6 @@ [rumext.alpha :as mf] [uxbox.builtins.icons :as i] [uxbox.main.constants :as c] - [uxbox.main.data.projects :as udp] [uxbox.main.data.dashboard :as dsh] [uxbox.main.store :as st] [uxbox.main.refs :as refs] @@ -50,7 +49,7 @@ (kbd/enter? %) (let [name (-> % dom/get-target dom/get-value)] - (st/emit! (udp/rename-project id name)) + (st/emit! (dsh/rename-project id name)) (swap! local assoc :edit false)))] [:li {:on-click on-click diff --git a/frontend/src/uxbox/main/ui/settings/header.cljs b/frontend/src/uxbox/main/ui/settings/header.cljs index 84056236d..fbee35ef7 100644 --- a/frontend/src/uxbox/main/ui/settings/header.cljs +++ b/frontend/src/uxbox/main/ui/settings/header.cljs @@ -11,7 +11,6 @@ [rumext.alpha :as mf] [uxbox.builtins.icons :as i] [uxbox.main.data.auth :as da] - [uxbox.main.data.projects :as dp] [uxbox.main.store :as st] [uxbox.util.i18n :as i18n :refer [tr t]] [uxbox.util.router :as rt])) diff --git a/frontend/src/uxbox/main/ui/workspace/header.cljs b/frontend/src/uxbox/main/ui/workspace/header.cljs index 5ce1a2083..2abe8e4c3 100644 --- a/frontend/src/uxbox/main/ui/workspace/header.cljs +++ b/frontend/src/uxbox/main/ui/workspace/header.cljs @@ -15,7 +15,6 @@ [uxbox.builtins.icons :as i :include-macros true] [uxbox.config :as cfg] [uxbox.main.data.history :as udh] - [uxbox.main.data.undo :as udu] [uxbox.main.data.workspace :as dw] [uxbox.main.refs :as refs] [uxbox.main.store :as st] @@ -67,8 +66,8 @@ [{:keys [page] :as props}] (let [toggle #(st/emit! (dw/toggle-flag %)) toggle-layout #(st/emit! (dw/toggle-layout-flag %)) - on-undo #(st/emit! (udu/undo)) - on-redo #(st/emit! (udu/redo)) + on-undo (constantly nil) + on-redo (constantly nil) on-image #(modal/show! import-image-modal {}) ;;on-download #(udl/open! :download) layout (mf/deref refs/workspace-layout)