Skip to content

Commit

Permalink
[wip] notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc committed Oct 30, 2023
1 parent 724188e commit 5806afb
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 221 deletions.
141 changes: 3 additions & 138 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@
},
"main": "resources/main.js",
"devDependencies": {
"@radix-ui/react-context-menu": "^2.1.5",
"@radix-ui/react-context-menu": "2.1.5",
"@radix-ui/react-dropdown-menu": "2.0.5",
"@radix-ui/react-menubar": "1.0.3",
"@radix-ui/react-popover": "1.0.6",
"@radix-ui/react-select": "1.2.2",
"@radix-ui/react-toast": "^1.1.5",
"@radix-ui/react-tooltip": "1.0.6",
"@re-path/react-color": "^2.19.4",
"@re-path/react-color": "2.19.4",
"@sentry/react": "7.66.0",
"@types/react": "17.0.2",
"@types/react-dom": "17.0.2",
Expand Down Expand Up @@ -97,7 +96,7 @@
"postcss-nested": "6.0.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-fps": "^1.0.6",
"react-fps": "1.0.6",
"react-frame-component": "5.2.6",
"react-svg": "16.1.16",
"shadow-cljs": "2.25.8",
Expand Down
1 change: 1 addition & 0 deletions src/renderer/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
[renderer.elements.core]
[renderer.reepl.core]
[renderer.attribute.core]
[renderer.notification.core]
[renderer.reepl.replumb :as replumb]
[replumb.repl :as repl]
[renderer.views :as views]
Expand Down
1 change: 1 addition & 0 deletions src/renderer/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:documents {}
:document-tabs []
:system-fonts []
:notifications []
:debug-info? false
:pen-mode? false
:repl/mode :cljs
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/notification/core.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(ns renderer.notification.core
(:require [renderer.notification.events]
[renderer.notification.subs]))
19 changes: 19 additions & 0 deletions src/renderer/notification/events.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(ns renderer.notification.events
(:require
[re-frame.core :as rf]
[renderer.utils.vec :as vec]))

(rf/reg-event-db
:notification/add
(fn [db [_ notification]]
(update db :notifications conj notification)))

(rf/reg-event-db
:notification/remove
(fn [db [_ index]]
(update db :notifications #(vec/remove-by-index % index))))

#_(rf/reg-event-db
:notification/clear
(fn [db [_]]
(assoc db :notifications [])))
12 changes: 12 additions & 0 deletions src/renderer/notification/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.toast {
@apply flex level-3 rounded shadow-md p-4 relative;

width: 390px;
max-width: 100vw;
}

.toast-description {
grid-area: description;
margin: 0;
line-height: 1.3;
}
8 changes: 8 additions & 0 deletions src/renderer/notification/subs.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns renderer.notification.subs
(:require
[re-frame.core :as rf]))

(rf/reg-sub
:notifications
(fn [db [_]]
(-> db :notifications)))
19 changes: 19 additions & 0 deletions src/renderer/notification/views.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(ns renderer.notification.views
(:require
[re-frame.core :as rf]
[renderer.components :as comp]))

(defn main
[]
(let [notifications @(rf/subscribe [:notifications])]
[:div.fixed.flex.flex-col.m-4.right-0.bottom-0.gap-2
(map-indexed (fn [index notification]
[:div.toast
{:key index}
[:div.toast-description
(:content notification)]
[comp/icon-button
{:title "Dismiss"
:icon "times"
:action #(rf/dispatch-sync [:notification/remove index])}]])
notifications)]))
64 changes: 0 additions & 64 deletions src/renderer/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -467,68 +467,4 @@ pre {
&[data-state='delayed-open'][data-side='left'] {
animation-name: slideRightAndFade;
}
}


.toast-viewport {
@apply fixed flex flex-col p-4 right-0 bottom-0 gap-2;

width: 390px;
max-width: 100vw;
list-style: none;
z-index: 2147483647;
outline: none;
}

.toast-root {
@apply grid level-3 rounded shadow-md p-4 relative;

grid-template-areas: 'title action' 'description action';
grid-template-columns: auto max-content;
column-gap: 15px;
align-items: center;

&[data-state='open'] {
animation: slideUpAndFade 150ms cubic-bezier(0.16, 1, 0.3, 1);
}

&[data-state='closed'] {
animation: hide 100ms ease-in;
}

&[data-swipe='move'] {
transform: translateX(var(--radix-toast-swipe-move-x));
}

&[data-swipe='cancel'] {
transform: translateX(0);
transition: transform 200ms ease-out;
}

&[data-swipe='end'] {
animation: swipeOut 100ms ease-out;
}
}

.toast-title {
@apply text-lg;

grid-area: title;
margin-bottom: 5px;
font-weight: 500;
color: var(--slate-12);
}

.toast-description {
grid-area: description;
margin: 0;
line-height: 1.3;
}

.toast-action {
grid-area: action;
}

.toast-close {
@apply absolute top-4 right-4;
}
10 changes: 7 additions & 3 deletions src/renderer/tools/dropper.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@

(defmethod tools/activate :dropper
[db]
;; TODO side effect within db handler
;; FIXME side effect within db handler
(if (.-EyeDropper js/window)
(do (-> (js/EyeDropper.)
(.open)
(.then (fn [result]
(rf/dispatch [:elements/fill (.-sRGBHex result)])
(rf/dispatch [:document/set-fill (.-sRGBHex result)])
(rf/dispatch [:set-tool :select])))
(.catch #(rf/dispatch [:set-tool :select])))
(.catch (fn [error]
(rf/dispatch [:notification/add {:content (str error)}])
(rf/dispatch [:set-tool :select]))))
(handlers/set-message db [:div "Click anywhere to pick a color."]))
(tools/set-tool db :select)))
(-> db
(update :notifications conj "Your browser does not support the EyeDropper API")
(tools/set-tool :select))))



Loading

0 comments on commit 5806afb

Please sign in to comment.