From fef1aa6ce3700f18c9dd1c724fd2ec229b093ea6 Mon Sep 17 00:00:00 2001 From: Jonathan Staab Date: Fri, 25 Nov 2022 08:54:38 -0800 Subject: [PATCH] Add modal for note detail --- src/App.svelte | 30 +++++++++++++++++++++++++++++- src/partials/Note.svelte | 11 ++++++++--- src/partials/NoteDetail.svelte | 13 +++++++++++++ src/routes/Notes.svelte | 2 +- src/routes/UserDetail.svelte | 2 +- src/state/app.js | 2 ++ src/util/html.js | 4 ++-- 7 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 src/partials/NoteDetail.svelte diff --git a/src/App.svelte b/src/App.svelte index bc294457..e7fec7d1 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -4,10 +4,15 @@ import {onMount} from "svelte" import {writable} from "svelte/store" - import {fly} from "svelte/transition" + import {fly, fade} from "svelte/transition" + import {cubicInOut} from "svelte/easing" import {Router, Route, links, navigate} from "svelte-routing" + import {globalHistory} from "svelte-routing/src/history" + import {hasParent} from 'src/util/html' import {store as toast} from "src/state/toast" + import {modal} from "src/state/app" import {user} from 'src/state/user' + import NoteDetail from "src/partials/NoteDetail.svelte" import NotFound from "src/routes/NotFound.svelte" import Notes from "src/routes/Notes.svelte" import Login from "src/routes/Login.svelte" @@ -31,11 +36,16 @@ export let url = "" onMount(() => { + // Close menu on click outside document.querySelector("html").addEventListener("click", e => { if (e.target !== menuIcon) { menuIsOpen.set(false) } }) + + globalHistory.listen(() => { + modal.set(null) + }) }) // Give the animation a moment to finish @@ -47,6 +57,8 @@ } + e.key === 'Escape' && modal.set(null)} /> +
@@ -127,6 +139,22 @@

Coracle

+ {#if $modal} +
+
modal.set(null)} /> + +
+ {/if} + {#if $toast}
+ import cx from 'classnames' import {fly} from 'svelte/transition' import {navigate} from 'svelte-routing' import {ellipsize} from 'hurdak/src/core' import {hasParent} from 'src/util/html' - import {accounts} from "src/state/app" + import {accounts, modal} from "src/state/app" import {formatTimestamp} from 'src/util/misc' import UserBadge from "src/partials/UserBadge.svelte" export let note + export let interactive = false const onClick = e => { if (!['I'].includes(e.target.tagName) && !hasParent('a', e.target)) { - navigate(`/notes/${note.id}`) + modal.set({note}) } } @@ -19,7 +21,10 @@
  • + class={cx("py-2 px-3 flex flex-col gap-2 text-white", { + "hover:bg-dark transition-all cursor-pointer": interactive, + "border border-solid border-black hover:border-medium": interactive, + })}>

    {formatTimestamp(note.created_at)}

    diff --git a/src/partials/NoteDetail.svelte b/src/partials/NoteDetail.svelte new file mode 100644 index 00000000..a42b0ac3 --- /dev/null +++ b/src/partials/NoteDetail.svelte @@ -0,0 +1,13 @@ + + + diff --git a/src/routes/Notes.svelte b/src/routes/Notes.svelte index 6f913bb0..8284ddb5 100644 --- a/src/routes/Notes.svelte +++ b/src/routes/Notes.svelte @@ -34,7 +34,7 @@
      {#each reverse(notes) as n} - + {/each}
    diff --git a/src/routes/UserDetail.svelte b/src/routes/UserDetail.svelte index 0493bee9..711bfc55 100644 --- a/src/routes/UserDetail.svelte +++ b/src/routes/UserDetail.svelte @@ -54,7 +54,7 @@
    {#each reverse(notes) as note} - + {/each}
    diff --git a/src/state/app.js b/src/state/app.js index 1a8cad6b..6c9985bf 100644 --- a/src/state/app.js +++ b/src/state/app.js @@ -4,6 +4,8 @@ import {getLocalJson, setLocalJson, now, timedelta} from "src/util/misc" import {user} from 'src/state/user' import {nostr} from 'src/state/nostr' +export const modal = writable(null) + export const rooms = writable(getLocalJson("coracle/rooms") || {}) rooms.subscribe($rooms => { diff --git a/src/util/html.js b/src/util/html.js index 76ea6840..a605b899 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -46,8 +46,8 @@ export const stripExifData = async file => { } export const hasParent = (tag, e) => { - while (e.parentNode) { - if (e.parentNode.tagName === tag.toUpperCase()) { + while (e) { + if (e.tagName === tag.toUpperCase()) { return true }