Skip to content

Commit 2232020

Browse files
committed
enhance dialogs
1 parent 90d23ac commit 2232020

File tree

5 files changed

+52
-40
lines changed

5 files changed

+52
-40
lines changed

src/renderer/dialog/events.cljs

+16-11
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,34 @@
44
[renderer.dialog.views :as v]
55
[renderer.dialog.cmdk :as cmdk]))
66

7+
(defn create
8+
[db dialog]
9+
(update db :dialogs conj dialog))
10+
711
(rf/reg-event-db
812
::cmdk
913
(fn [db [_]]
10-
(update db :dialogs conj {:content [cmdk/root]
11-
:attrs {:class "dialog-content dialog-cmdk-content"}})))
14+
(create db {:content [cmdk/root]
15+
:attrs {:class "dialog-content dialog-cmdk-content"}})))
1216

1317
(rf/reg-event-db
1418
::about
1519
(fn [db [_]]
16-
(update db :dialogs conj {:title "Repath Studio"
17-
:content [v/about]})))
20+
(create db {:title "Repath Studio"
21+
:content [v/about]})))
1822

1923
(rf/reg-event-fx
2024
::save
2125
(fn [{:keys [db]} [_ k]]
22-
{:db (update db :dialogs conj {:title "Do you want to save your changes?"
23-
:content [v/save k]
24-
:attrs {:onOpenAutoFocus #(.preventDefault %)}})}))
26+
{:db (create db {:title "Do you want to save your changes?"
27+
:content [v/save k]
28+
:attrs {:onOpenAutoFocus #(.preventDefault %)}})}))
2529

26-
#_(rf/reg-event-db
27-
::confirmation
28-
(fn [db [_ data]]
29-
(update db :dialogs conj {:content [v/confirmation data]})))
30+
(rf/reg-event-db
31+
::confirmation
32+
(fn [db [_ data]]
33+
(create db {:title (:title data)
34+
:content [v/confirmation data]})))
3035

3136
(rf/reg-event-db
3237
::close

src/renderer/dialog/styles.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.dialog-content {
22
@apply fixed bg-secondary rounded-lg overflow-hidden shadow-xl border border-default;
3-
;
3+
44
width: 500px;
5+
max-width: 90%;
56
left: 50%;
67
top: 50%;
78
transform: translate(-50%, -50%);

src/renderer/dialog/views.cljs

+17-18
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,28 @@
2222
[:div.p-5
2323
[:div.flex.gap-3.items-start.pb-2
2424
[:div
25-
[:div [:strong "Version: "] config/version]
26-
[:div [:strong "Browser: "] platform/user-agent]]]
25+
[:div [:strong "Version: "] config/version]
26+
[:div [:strong "Browser: "] platform/user-agent]]]
2727
[:button.button.px-2.bg-primary.rounded.w-full
2828
{:auto-focus true
2929
:on-click #(rf/dispatch [::dialog.e/close])}
3030
"OK"]
3131
[close-button]])
3232

33-
#_(defn confirmation
34-
[{:keys [title description action]}]
35-
[:div.p-4
36-
[:h1.text-3xl.mb-2.font-light title]
37-
[:div description]
38-
[:div.flex.justify-end
39-
[:button.button.px-2.bg-primary.rounded
40-
{:on-click #(rf/dispatch [::dialog.e/close])}
41-
"No"]
42-
[:button.button.px-2.bg-primary.rounded
43-
{:auto-focus true
44-
:on-click #(do (rf/dispatch [::dialog.e/close])
45-
(rf/dispatch action))}
46-
"Yes"]]
47-
[close-button]])
33+
(defn confirmation
34+
[{:keys [description action confirm-label cancel-label]}]
35+
[:div.p-5
36+
[:p description]
37+
[:div.flex.gap-2.flex-wrap
38+
[:button.button.px-2.bg-primary.rounded.flex-1
39+
{:on-click #(rf/dispatch [::dialog.e/close])}
40+
(or cancel-label "Cancel")]
41+
[:button.button.px-2.bg-primary.rounded.flex-1
42+
{:auto-focus true
43+
:on-click #(do (rf/dispatch [::dialog.e/close])
44+
(rf/dispatch action))}
45+
(or confirm-label "OK")]]
46+
[close-button]])
4847

4948
(defn save
5049
[k]
@@ -53,7 +52,7 @@
5352
[:p
5453
"Your changes to " [:strong (:title document)]
5554
" will be lost if you close the document without saving."]
56-
[:div.flex.gap-2
55+
[:div.flex.gap-2.flex-wrap
5756
[:button.button.px-2.bg-primary.rounded.flex-1
5857
{:on-click #(do (rf/dispatch [::dialog.e/close])
5958
(rf/dispatch [::document.e/close k false]))}

src/renderer/history/views.cljs

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[re-frame.core :as rf]
88
[reagent.core :as ra]
99
[renderer.components :as comp]
10+
[renderer.dialog.events :as-alias dialog.e]
1011
[renderer.history.events :as-alias history.e]
1112
[renderer.history.subs :as-alias history.s]))
1213

@@ -111,7 +112,11 @@
111112
{:on-click #(rf/dispatch [::history.e/tree-view-updated 0.5 (center ref)])}
112113
"Center view"]
113114
[:button.button.flex-1
114-
{:on-click #(rf/dispatch [::history.e/clear])}
115+
{:on-click #(rf/dispatch [::dialog.e/confirmation
116+
{:title "This action cannot be undone."
117+
:description "Are you sure you wish to clear the document history?"
118+
:confirm-label "Clear history"
119+
:action [::history.e/clear]}])}
115120
"Clear history"]]
116121
[:div.flex-1 {:ref ref}
117122
[tree ref]]]))

src/renderer/styles.css

+11-9
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
}
108108

109109
.button {
110-
@apply inline-block relative cursor-pointer text-center outline-none;
110+
@apply inline-block relative cursor-pointer text-center outline-none text-nowrap;
111111
background-color: transparent;
112112
color: var(--font-color);
113113
fill: var(--font-color);
@@ -203,8 +203,8 @@ label {
203203
width: auto;
204204

205205
&:hover {
206-
color: var(--font-color-hovered);
207-
cursor: pointer;
206+
color: var(--font-color-hovered);
207+
cursor: pointer;
208208
}
209209
}
210210

@@ -392,14 +392,13 @@ pre {
392392
.fps-wrapper {
393393
@apply drop-shadow-md;
394394

395-
> div {
396-
@apply absolute top-2 left-auto right-2 overflow-hidden font-sans text-sm
397-
px-2 py-1.5 bg-white text-gray-500 !important;
395+
>div {
396+
@apply absolute top-2 left-auto right-2 overflow-hidden font-sans text-sm px-2 py-1.5 bg-white text-gray-500 !important;
398397

399-
> div {
398+
>div {
400399
@apply left-0 right-0 bottom-0 bg-white !important;
401400

402-
> div {
401+
>div {
403402
background-color: var(--accent) !important;
404403
}
405404
}
@@ -421,19 +420,22 @@ pre {
421420
&[data-state='open'][data-side='top'] {
422421
animation-name: slideDownAndFade;
423422
}
423+
424424
&[data-state='open'][data-side='right'] {
425425
animation-name: slideLeftAndFade;
426426
}
427+
427428
&[data-state='open'][data-side='bottom'] {
428429
animation-name: slideUpAndFade;
429430
}
431+
430432
&[data-state='open'][data-side='left'] {
431433
animation-name: slideRightAndFade;
432434
}
433435
}
434436

435437
.popover-arrow,
436-
.menu-arrow {
438+
.menu-arrow {
437439
fill: var(--bg-secondary);
438440
}
439441

0 commit comments

Comments
 (0)