mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 00:40:30 -05:00
Basic backend integration for page history fetching.
This commit is contained in:
parent
6b495c1656
commit
e97e4cbb5a
5 changed files with 100 additions and 65 deletions
|
@ -164,3 +164,49 @@
|
|||
(defn delete-page
|
||||
[id]
|
||||
(DeletePage. id))
|
||||
|
||||
;; --- Page History Fetched
|
||||
|
||||
(defrecord PageHistoryFetched [history]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(-> state
|
||||
(assoc-in [:workspace :history :items] history)
|
||||
(assoc-in [:workspace :history :selected] nil))))
|
||||
|
||||
;; --- Fetch Page History
|
||||
|
||||
(defrecord FetchPageHistory [id]
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(println "FetchPageHistory" id)
|
||||
(letfn [(on-success [{history :payload}]
|
||||
(->PageHistoryFetched history))
|
||||
(on-failure [e]
|
||||
(uum/error (tr "errors.fetch-page-history"))
|
||||
(rx/empty))]
|
||||
(->> (rp/do :fetch/page-history {:page id})
|
||||
(rx/map on-success)
|
||||
(rx/catch on-failure))))
|
||||
|
||||
rs/EffectEvent
|
||||
(-apply-effect [_ state]
|
||||
))
|
||||
|
||||
(defn fetch-page-history
|
||||
[id]
|
||||
(FetchPageHistory. id))
|
||||
|
||||
;; --- Clean Page History
|
||||
|
||||
(defrecord CleanPageHistory []
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(println "CleanPageHistory")
|
||||
(-> state
|
||||
(assoc-in [:workspace :history :items] nil)
|
||||
(assoc-in [:workspace :history :selected] nil))))
|
||||
|
||||
(defn clean-page-history
|
||||
[]
|
||||
(CleanPageHistory.))
|
||||
|
|
|
@ -23,6 +23,11 @@
|
|||
(let [url (str url "/projects/" project "/pages")]
|
||||
(send! {:method :get :url url})))
|
||||
|
||||
(defmethod -do :fetch/page-history
|
||||
[type {:keys [page] :as params}]
|
||||
(let [url (str url "/pages/" page "/history")]
|
||||
(send! {:method :get :url url})))
|
||||
|
||||
(defmethod -do :delete/page
|
||||
[_ id]
|
||||
(let [url (str url "/pages/" id)]
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
[uxbox.ui.workspace.sidebar.options :refer (options-toolbox)]
|
||||
[uxbox.ui.workspace.sidebar.layers :refer (layers-toolbox)]
|
||||
[uxbox.ui.workspace.sidebar.sitemap :refer (sitemap-toolbox)]
|
||||
[uxbox.ui.workspace.sidebar.document-history :refer (document-history-toolbox)]
|
||||
[uxbox.ui.workspace.sidebar.history :refer (history-toolbox)]
|
||||
[uxbox.ui.workspace.sidebar.icons :refer (icons-toolbox)]
|
||||
[uxbox.ui.workspace.sidebar.drawtools :refer (draw-toolbox)]))
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
|||
(when (contains? flags :sitemap)
|
||||
(sitemap-toolbox))
|
||||
(when (contains? flags :document-history)
|
||||
(document-history-toolbox))
|
||||
(history-toolbox))
|
||||
(when (contains? flags :layers)
|
||||
(layers-toolbox))]])))
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
|
||||
(ns uxbox.ui.workspace.sidebar.document-history
|
||||
(ns uxbox.ui.workspace.sidebar.history
|
||||
(:require [sablono.core :as html :refer-macros [html]]
|
||||
[rum.core :as rum]
|
||||
[lentes.core :as l]
|
||||
|
@ -15,21 +15,51 @@
|
|||
[uxbox.state :as st]
|
||||
[uxbox.shapes :as shapes]
|
||||
[uxbox.library :as library]
|
||||
[uxbox.util.datetime :as dt]
|
||||
[uxbox.util.data :refer (read-string)]
|
||||
[uxbox.data.workspace :as dw]
|
||||
[uxbox.data.pages :as dpg]
|
||||
[uxbox.ui.workspace.base :as wb]
|
||||
[uxbox.ui.icons :as i]
|
||||
[uxbox.ui.mixins :as mx]
|
||||
[uxbox.util.dom :as dom]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Lenses
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(def ^:const history-l
|
||||
(as-> (l/in [:workspace :history]) $
|
||||
(l/focus-atom $ st/state)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Component
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn document-history-toolbox-render
|
||||
(defn- history-toolbox-will-mount
|
||||
[own]
|
||||
(let [workspace (rum/react wb/workspace-l)
|
||||
local (:rum/local own)
|
||||
(let [page @wb/page-l]
|
||||
(rs/emit! (dpg/fetch-page-history (:id page)))
|
||||
(add-watch wb/page-l ::key (fn [_ _ ov nv]
|
||||
(when (> (:version nv) (:version ov))
|
||||
(rs/emit! (dpg/fetch-page-history (:id nv))))))
|
||||
own))
|
||||
|
||||
(defn- history-toolbox-will-unmount
|
||||
[own]
|
||||
(rs/emit! (dpg/clean-page-history))
|
||||
(remove-watch wb/page-l ::key)
|
||||
own)
|
||||
|
||||
(defn- history-toolbox-transfer-state
|
||||
[oldown own]
|
||||
own)
|
||||
|
||||
(defn history-toolbox-render
|
||||
[own]
|
||||
(let [local (:rum/local own)
|
||||
page (rum/react wb/page-l)
|
||||
history (rum/react history-l)
|
||||
section (:section @local :main)
|
||||
close #(rs/emit! (dw/toggle-flag :document-history))
|
||||
main? (= section :main)
|
||||
|
@ -63,65 +93,19 @@
|
|||
[:ul.history-content
|
||||
[:li.current
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Current version"]]
|
||||
[:li
|
||||
[:span (str "Version " (:version page) " (current)")]]
|
||||
(for [item (:items history)]
|
||||
[:li {:key (str (:id item))}
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]
|
||||
[:li
|
||||
[:div.pin-icon i/pin]
|
||||
[:span "Version 02/02/2016 12:33h"]]])]])))
|
||||
[:span (str "Version " (:version item)
|
||||
" (" (dt/timeago (:created-at item)) ")")]])
|
||||
])]])))
|
||||
|
||||
|
||||
(def ^:static document-history-toolbox
|
||||
(def ^:static history-toolbox
|
||||
(mx/component
|
||||
{:render document-history-toolbox-render
|
||||
{:render history-toolbox-render
|
||||
:name "document-history-toolbox"
|
||||
:will-mount history-toolbox-will-mount
|
||||
:will-unmount history-toolbox-will-unmount
|
||||
:transfer-state history-toolbox-transfer-state
|
||||
:mixins [mx/static rum/reactive (mx/local)]}))
|
|
@ -33,7 +33,7 @@
|
|||
;; Lenses
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(def ^:static pages-l
|
||||
(def ^:const pages-l
|
||||
(letfn [(getter [state]
|
||||
(let [project (get-in state [:workspace :project])]
|
||||
(stpr/project-pages state project)))]
|
||||
|
|
Loading…
Reference in a new issue