A project you may only look at takes no edit, and greys what would make one
It used to take the edit and never save it, so a drawing stayed until the next reload and was gone after. `edit/edit-entry`, the one way a person changes the document, now refuses every edit when you cannot edit, rather than each command checking for itself; renaming the project and regenerating settings, which go around it, check too. The stage only selects, and the drawing tools, swatches, inspector fields, the timeline's edit buttons and the pool's add and upload are greyed out. Selecting, inspecting, playing and the view's own settings stay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
00e94c025a
commit
ef06f51d91
7 changed files with 68 additions and 10 deletions
|
|
@ -46,12 +46,22 @@
|
|||
(update :project merge {:status "edited · unsaved"}))
|
||||
db)))
|
||||
|
||||
(defn read-only?
|
||||
"Somebody else's project that we may look at and not write."
|
||||
[db]
|
||||
(false? (get-in db [:project :can-edit?])))
|
||||
|
||||
(defn edit-entry
|
||||
"Apply `f` to the loaded ENTRY — the document and the blocks, footage and
|
||||
source tracks beside it — and return the new db. For an edit that brings tier-2
|
||||
data in with it, which a document edit alone cannot."
|
||||
data in with it, which a document edit alone cannot.
|
||||
|
||||
NOTHING, IN A PROJECT YOU MAY ONLY LOOK AT. It used to take the edit and then
|
||||
never save it, so a drawing stayed until the next reload and was gone after.
|
||||
Here, as the one way a person changes the document, it is one rule rather
|
||||
than one per command."
|
||||
[db f]
|
||||
(replace-entry db (recorded f)))
|
||||
(if (read-only? db) db (replace-entry db (recorded f))))
|
||||
|
||||
(defn transport
|
||||
"App-db's copy of what the transport reads off the clip, after the clip was
|
||||
|
|
|
|||
|
|
@ -532,7 +532,8 @@
|
|||
(fn [{:keys [db]} [_ edit]]
|
||||
(let [id (:clip/current db)
|
||||
entry (store/entry id)]
|
||||
(if (or (get-in db [:project :busy?]) (empty? (:analyses (:clip entry))))
|
||||
(if (or (get-in db [:project :busy?]) (empty? (:analyses (:clip entry)))
|
||||
(edit/read-only? db))
|
||||
{}
|
||||
(let [plan (regenerate/plan (:clip entry) edit)
|
||||
report (select-keys plan [:features :roles])
|
||||
|
|
@ -656,8 +657,10 @@
|
|||
(rf/reg-event-fx
|
||||
::rename
|
||||
(fn [{:keys [db]} [_ value]]
|
||||
(if (edit/read-only? db)
|
||||
{}
|
||||
{:db (assoc-in db [:project :name] (not-empty (str/trim value)))
|
||||
:dispatch [::save {:auto? true :force? true}]}))
|
||||
:dispatch [::save {:auto? true :force? true}]})))
|
||||
|
||||
(rf/reg-event-fx
|
||||
::project-setting
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
[arthur.domain.node :as node]
|
||||
[arthur.domain.pick :as pick]
|
||||
[arthur.domain.symbol :as symbol]
|
||||
[arthur.events.edit :as edit]
|
||||
[arthur.footage.store :as store]
|
||||
[arthur.subs.playback :as playback]
|
||||
[arthur.subs.render :as render]
|
||||
|
|
@ -31,7 +32,9 @@
|
|||
(rf/reg-sub ::clipboard (fn [db _] (get-in db [:ui :clipboard])))
|
||||
(rf/reg-sub ::retry (fn [db _] (get-in db [:ui :retry])))
|
||||
(rf/reg-sub ::tone (fn [db _] (get-in db [:ui :tone])))
|
||||
(rf/reg-sub ::tool (fn [db _] (or (get-in db [:ui :tool]) :select)))
|
||||
(rf/reg-sub ::read-only? (fn [db _] (edit/read-only? db)))
|
||||
;; Looking is all a read-only project allows, so it is all the stage does.
|
||||
(rf/reg-sub ::tool (fn [db _] (if (edit/read-only? db) :select (or (get-in db [:ui :tool]) :select))))
|
||||
(rf/reg-sub ::auto-key? (fn [db _] (boolean (get-in db [:ui :auto-key?]))))
|
||||
(rf/reg-sub ::draft (fn [db _] (get-in db [:ui :draft])))
|
||||
(rf/reg-sub ::vertex (fn [db _] (get-in db [:ui :vertex])))
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
[arthur.events.playback :as pb]
|
||||
[arthur.subs.playback :as playback]
|
||||
[arthur.subs.render :as render]
|
||||
[arthur.subs.ui :as sub]
|
||||
[arthur.ui.layout :as layout]
|
||||
[arthur.ui.location :as location]
|
||||
[arthur.ui.params :as params]
|
||||
|
|
@ -69,7 +70,10 @@
|
|||
;; pane's contents.
|
||||
(let [{:keys [pool params shut] :as state} @(rf/subscribe [::layout/state])
|
||||
gone? #(contains? shut %)]
|
||||
[:div.app {:style (layout/vars state)}
|
||||
;; `read-only`: somebody else's project. The edits themselves are refused
|
||||
;; in `events/edit`; this greys out the controls that would make them.
|
||||
[:div.app {:style (layout/vars state)
|
||||
:class (when @(rf/subscribe [::sub/read-only?]) "read-only")}
|
||||
[topbar/view]
|
||||
[shortcuts/sheet]
|
||||
(when-not (gone? :pool) [pool/view])
|
||||
|
|
|
|||
|
|
@ -37,10 +37,10 @@
|
|||
[:aside.toolbox
|
||||
[:div.tools
|
||||
(doall
|
||||
(for [{t :tool :keys [key name tip icon]} kit]
|
||||
(for [{t :tool label :name :keys [key tip icon]} kit]
|
||||
^{:key t}
|
||||
[:button {:class (str "tool" (when (= t tool) " on"))
|
||||
:title (str name " (" (.toUpperCase key) ") — " tip)
|
||||
[:button {:class (str "tool tool-" (name t) (when (= t tool) " on"))
|
||||
:title (str label " (" (.toUpperCase key) ") — " tip)
|
||||
:on-click #(rf/dispatch [::ui/set-tool t])}
|
||||
[:svg {:view-box "0 0 18 18" :width 18 :height 18} icon]]))]
|
||||
[palette/grid]
|
||||
|
|
|
|||
27
frontend/test/arthur/events/read_only_test.cljs
Normal file
27
frontend/test/arthur/events/read_only_test.cljs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
(ns arthur.events.read-only-test
|
||||
(:require [cljs.test :refer [deftest is]]
|
||||
[arthur.domain.clip :as clip]
|
||||
[arthur.domain.paint :as paint]
|
||||
[arthur.events.ui :as ui]
|
||||
[arthur.footage.store :as store]
|
||||
[arthur.subs.ui :as sub]
|
||||
[re-frame.core :as rf]
|
||||
[re-frame.db :as rf-db]))
|
||||
|
||||
(deftest a-project-you-may-only-look-at-takes-no-edit
|
||||
(let [doc (paint/new-shape (clip/blank) :main :s 0 [0 0 10 0 20 10 10 20 0 20] 1)
|
||||
id (store/install! {:clip doc :store {}} "read-only")
|
||||
shape #(get-in (:clip (store/entry (:clip/current @rf-db/app-db))) [:symbols :main :nodes :s])]
|
||||
(reset! rf-db/app-db {:clip/current id :paint/revision 0
|
||||
:project {:can-edit? false}
|
||||
:ui {:open :main :tool :brush :selection [:node :main :s [:s]]
|
||||
:selections [[:node :main :s [:s]]]}
|
||||
:playback {:frame 0}})
|
||||
(is (= :select @(rf/subscribe [::sub/tool])) "the stage only selects")
|
||||
(rf/dispatch-sync [::ui/delete-selected])
|
||||
(is (some? (shape)) "Delete deletes nothing")
|
||||
(is (= 0 (:paint/revision @rf-db/app-db)) "and nothing became unsaved")
|
||||
(swap! rf-db/app-db #(-> % (assoc-in [:project :can-edit?] true) (update :ui assoc :tool :select :selection [:node :main :s [:s]]
|
||||
:selections [[:node :main :s [:s]]])))
|
||||
(rf/dispatch-sync [::ui/delete-selected])
|
||||
(is (nil? (shape)) "an editor's Delete does")))
|
||||
|
|
@ -2062,3 +2062,14 @@ button.tl-key.selected { background: var(--pick); box-shadow: 0 0 0 2px var(--pi
|
|||
cursor: ew-resize; touch-action: none;
|
||||
background: linear-gradient(var(--sel), var(--sel)) center / 2px 100% no-repeat;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
read-only — somebody else's project. `events/edit` refuses the edits; this
|
||||
greys out what would make them, so nothing offers what it cannot do.
|
||||
Selecting, inspecting, playing and the view's own settings stay. */
|
||||
.app.read-only :is(
|
||||
.toolbox .tool:not(.tool-select), .toolbox > :not(.tools),
|
||||
.context-controls, .creation-controls, button.auto-key,
|
||||
.params .inspect :is(input, select, textarea, button),
|
||||
.pool-foot
|
||||
) { opacity: .4; pointer-events: none; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue