Open home widget create forms in popup modals
The Places tab already popped its create form up over the page; every other /stp widget swapped its contents for the form instead, which meant losing sight of the list you were adding to and a cramped form inside a grid cell. Extract the Places modal into a shared components/util/Modal.vue (teleported backdrop, click-outside and Escape to close) and use it for the Feed, Bookmarks, Favorites, Consumption and Rowing create forms as well. Widget headers keep their normal titles now that each form carries its own heading in the modal. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KcFtkisHcKJuTZAnv3fVzA
This commit is contained in:
+1
-1
@@ -54,7 +54,7 @@ Note that Tailwind's spacing unit is set to **3px** (not the default 4px), so `p
|
|||||||
|
|
||||||
- Use Tailwind utilities for layout and one-off tweaks. Reach for a scoped `<style>` only for what utilities can't express: `grid-template-areas`, keyframe animations, media-query-specific layouts.
|
- Use Tailwind utilities for layout and one-off tweaks. Reach for a scoped `<style>` only for what utilities can't express: `grid-template-areas`, keyframe animations, media-query-specific layouts.
|
||||||
- Never hard-code a colour in a component; use a token. The one exception is `<canvas>` drawing (MobileAutomata), which can't read CSS variables.
|
- Never hard-code a colour in a component; use a token. The one exception is `<canvas>` drawing (MobileAutomata), which can't read CSS variables.
|
||||||
- Home widgets: wrap the title in `<Header>`; admin-only create forms use `<CreateToggle v-model="showCreate">` in the header's `#action` slot.
|
- Home widgets: wrap the title in `<Header>`; admin-only create forms use `<CreateToggle v-model="showCreate">` in the header's `#action` slot and render the form inside a `<Modal v-model="showCreate">` so it pops up over the page instead of replacing the widget.
|
||||||
- Crossfading content in place: `<Transition name="fade">` inside a `position: relative` parent. Route changes use `<Transition name="slide">`.
|
- Crossfading content in place: `<Transition name="fade">` inside a `position: relative` parent. Route changes use `<Transition name="slide">`.
|
||||||
|
|
||||||
## Production Build
|
## Production Build
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { useAuthStore } from "@/stores/auth";
|
import { useAuthStore } from "@/stores/auth";
|
||||||
|
|
||||||
// "+" / "x" button, shown to admins only. Toggles a home widget between its
|
// "+" / "x" button, shown to admins only. Opens a home widget's create form in
|
||||||
// normal view and its create form. Designed for <Header>'s #action slot.
|
// a popup <Modal>. Designed for <Header>'s #action slot.
|
||||||
const show = defineModel({ type: Boolean, default: false });
|
const show = defineModel({ type: Boolean, default: false });
|
||||||
const auth = useAuthStore();
|
const auth = useAuthStore();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<script setup>
|
||||||
|
import { watch, onUnmounted } from "vue";
|
||||||
|
|
||||||
|
// Popup modal: a dimmed backdrop over the page with the content floated on top.
|
||||||
|
// Closes on backdrop click or Escape. Used by the home widgets so their create
|
||||||
|
// forms pop up instead of replacing the widget's contents.
|
||||||
|
const open = defineModel({ type: Boolean, default: false });
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
maxWidth: { type: String, default: "420px" },
|
||||||
|
});
|
||||||
|
|
||||||
|
function onKeydown(e) {
|
||||||
|
if (e.key === "Escape") open.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
open,
|
||||||
|
(isOpen) => {
|
||||||
|
if (isOpen) {
|
||||||
|
window.addEventListener("keydown", onKeydown);
|
||||||
|
} else {
|
||||||
|
window.removeEventListener("keydown", onKeydown);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
onUnmounted(() => window.removeEventListener("keydown", onKeydown));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Teleport to="body">
|
||||||
|
<div v-if="open" class="modal-backdrop" @click.self="open = false">
|
||||||
|
<div class="modal bdr-1" :style="{ maxWidth: props.maxWidth }">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Teleport>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.modal-backdrop {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background-color: rgba(0, 0, 0, 0.65);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 50;
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal {
|
||||||
|
background-color: var(--color-surface);
|
||||||
|
padding: 16px;
|
||||||
|
width: 100%;
|
||||||
|
max-height: 90vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed, ref, defineAsyncComponent } from "vue";
|
import { computed, ref, defineAsyncComponent } from "vue";
|
||||||
import LinkTable from "@/components/util/LinkTable.vue";
|
import LinkTable from "@/components/util/LinkTable.vue";
|
||||||
|
import Modal from "@/components/util/Modal.vue";
|
||||||
import Header from "@/components/text/Header.vue";
|
import Header from "@/components/text/Header.vue";
|
||||||
import CreateToggle from "@/components/input/CreateToggle.vue";
|
import CreateToggle from "@/components/input/CreateToggle.vue";
|
||||||
import { useHomeDataStore } from "@/stores/homeData";
|
import { useHomeDataStore } from "@/stores/homeData";
|
||||||
@@ -26,16 +27,10 @@ const groupedBookmarks = computed(() => {
|
|||||||
<template>
|
<template>
|
||||||
<div class="bookmarks-wrapper">
|
<div class="bookmarks-wrapper">
|
||||||
<Header class="text-left">
|
<Header class="text-left">
|
||||||
{{ showCreate ? "Create Bookmark" : "Bookmarks" }}
|
Bookmarks
|
||||||
<template #action><CreateToggle v-model="showCreate" /></template>
|
<template #action><CreateToggle v-model="showCreate" /></template>
|
||||||
</Header>
|
</Header>
|
||||||
<CreateBookmark
|
<div class="bookmarks-scroll">
|
||||||
v-if="showCreate"
|
|
||||||
class="flex-1 min-h-0 p-1"
|
|
||||||
@done="showCreate = false"
|
|
||||||
@cancel="showCreate = false"
|
|
||||||
/>
|
|
||||||
<div v-if="!showCreate" class="bookmarks-scroll">
|
|
||||||
<LinkTable
|
<LinkTable
|
||||||
v-for="group in groupedBookmarks"
|
v-for="group in groupedBookmarks"
|
||||||
:key="group[0]"
|
:key="group[0]"
|
||||||
@@ -43,6 +38,12 @@ const groupedBookmarks = computed(() => {
|
|||||||
:items="group[1]"
|
:items="group[1]"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<Modal v-model="showCreate">
|
||||||
|
<CreateBookmark
|
||||||
|
@done="showCreate = false"
|
||||||
|
@cancel="showCreate = false"
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed } from "vue";
|
import { ref, computed } from "vue";
|
||||||
import Slideshow from "@/components/util/Slideshow.vue";
|
import Slideshow from "@/components/util/Slideshow.vue";
|
||||||
|
import Modal from "@/components/util/Modal.vue";
|
||||||
import PlacesTable from "./PlacesTable.vue";
|
import PlacesTable from "./PlacesTable.vue";
|
||||||
import CreatePlace from "@/views/admin/CreatePlace.vue";
|
import CreatePlace from "@/views/admin/CreatePlace.vue";
|
||||||
import { useAuthStore } from "@/stores/auth";
|
import { useAuthStore } from "@/stores/auth";
|
||||||
@@ -47,16 +48,9 @@ const isAdmin = computed(() => !!auth.user?.admin);
|
|||||||
<PlacesTable v-else />
|
<PlacesTable v-else />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Teleport to="body">
|
<Modal v-model="showAdd">
|
||||||
<div v-if="showAdd" class="modal-backdrop" @click.self="showAdd = false">
|
<CreatePlace @done="showAdd = false" @cancel="showAdd = false" />
|
||||||
<div class="modal bdr-1">
|
</Modal>
|
||||||
<CreatePlace
|
|
||||||
@done="showAdd = false"
|
|
||||||
@cancel="showAdd = false"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Teleport>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -114,24 +108,4 @@ const isAdmin = computed(() => !!auth.user?.admin);
|
|||||||
position: relative;
|
position: relative;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-backdrop {
|
|
||||||
position: fixed;
|
|
||||||
inset: 0;
|
|
||||||
background-color: rgba(0, 0, 0, 0.65);
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
z-index: 50;
|
|
||||||
padding: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.modal {
|
|
||||||
background-color: var(--color-surface);
|
|
||||||
padding: 16px;
|
|
||||||
width: 100%;
|
|
||||||
max-width: 420px;
|
|
||||||
max-height: 90vh;
|
|
||||||
overflow-y: auto;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import AutoScroll from "@/components/util/AutoScroll.vue";
|
import AutoScroll from "@/components/util/AutoScroll.vue";
|
||||||
|
import Modal from "@/components/util/Modal.vue";
|
||||||
import LinkTable from "@/components/util/LinkTable.vue";
|
import LinkTable from "@/components/util/LinkTable.vue";
|
||||||
import Header from "@/components/text/Header.vue";
|
import Header from "@/components/text/Header.vue";
|
||||||
import CreateToggle from "@/components/input/CreateToggle.vue";
|
import CreateToggle from "@/components/input/CreateToggle.vue";
|
||||||
@@ -18,21 +19,21 @@ const showCreate = ref(false);
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col items-center">
|
<div class="flex flex-col items-center">
|
||||||
<Header>
|
<Header>
|
||||||
{{ showCreate ? "Create Activity" : "Consumption" }}
|
Consumption
|
||||||
<template #action><CreateToggle v-model="showCreate" /></template>
|
<template #action><CreateToggle v-model="showCreate" /></template>
|
||||||
</Header>
|
</Header>
|
||||||
<CreateActivity
|
<AutoScroll class="flex-1 w-full">
|
||||||
v-if="showCreate"
|
|
||||||
class="flex-1 w-full p-1"
|
|
||||||
@done="showCreate = false"
|
|
||||||
@cancel="showCreate = false"
|
|
||||||
/>
|
|
||||||
<AutoScroll v-if="!showCreate" class="flex-1 w-full">
|
|
||||||
<LinkTable
|
<LinkTable
|
||||||
variant="table"
|
variant="table"
|
||||||
class="w-full"
|
class="w-full"
|
||||||
:items="activityStore.activity"
|
:items="activityStore.activity"
|
||||||
/>
|
/>
|
||||||
</AutoScroll>
|
</AutoScroll>
|
||||||
|
<Modal v-model="showCreate">
|
||||||
|
<CreateActivity
|
||||||
|
@done="showCreate = false"
|
||||||
|
@cancel="showCreate = false"
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import Header from "@/components/text/Header.vue";
|
|||||||
import CreateToggle from "@/components/input/CreateToggle.vue";
|
import CreateToggle from "@/components/input/CreateToggle.vue";
|
||||||
import LinkTable from "@/components/util/LinkTable.vue";
|
import LinkTable from "@/components/util/LinkTable.vue";
|
||||||
import AutoScroll from "@/components/util/AutoScroll.vue";
|
import AutoScroll from "@/components/util/AutoScroll.vue";
|
||||||
|
import Modal from "@/components/util/Modal.vue";
|
||||||
|
|
||||||
import { ref, defineAsyncComponent } from "vue";
|
import { ref, defineAsyncComponent } from "vue";
|
||||||
import { useFavoritesStore } from "@/stores/favorites";
|
import { useFavoritesStore } from "@/stores/favorites";
|
||||||
@@ -18,21 +19,21 @@ const showCreate = ref(false);
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col items-center">
|
<div class="flex flex-col items-center">
|
||||||
<Header>
|
<Header>
|
||||||
{{ showCreate ? "Create Favorite" : "favs" }}
|
favs
|
||||||
<template #action><CreateToggle v-model="showCreate" /></template>
|
<template #action><CreateToggle v-model="showCreate" /></template>
|
||||||
</Header>
|
</Header>
|
||||||
<CreateFavorite
|
<AutoScroll class="w-full flex-1">
|
||||||
v-if="showCreate"
|
|
||||||
class="w-full flex-1 p-1"
|
|
||||||
@done="showCreate = false"
|
|
||||||
@cancel="showCreate = false"
|
|
||||||
/>
|
|
||||||
<AutoScroll v-if="!showCreate" class="w-full flex-1">
|
|
||||||
<LinkTable
|
<LinkTable
|
||||||
variant="table"
|
variant="table"
|
||||||
class="w-full"
|
class="w-full"
|
||||||
:items="favoritesStore.favorites"
|
:items="favoritesStore.favorites"
|
||||||
/>
|
/>
|
||||||
</AutoScroll>
|
</AutoScroll>
|
||||||
|
<Modal v-model="showCreate">
|
||||||
|
<CreateFavorite
|
||||||
|
@done="showCreate = false"
|
||||||
|
@cancel="showCreate = false"
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import Button from "@/components/input/Button.vue";
|
import Button from "@/components/input/Button.vue";
|
||||||
import Markdown from "@/components/util/Markdown.vue";
|
import Markdown from "@/components/util/Markdown.vue";
|
||||||
|
import Modal from "@/components/util/Modal.vue";
|
||||||
import Header from "@/components/text/Header.vue";
|
import Header from "@/components/text/Header.vue";
|
||||||
import CreateToggle from "@/components/input/CreateToggle.vue";
|
import CreateToggle from "@/components/input/CreateToggle.vue";
|
||||||
|
|
||||||
@@ -46,17 +47,10 @@ function deletePost() {
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col flex-1 min-h-0">
|
<div class="flex flex-col flex-1 min-h-0">
|
||||||
<Header>
|
<Header>
|
||||||
{{ showCreate ? "Create Post" : post.title }}
|
{{ post.title }}
|
||||||
<template #action><CreateToggle v-model="showCreate" /></template>
|
<template #action><CreateToggle v-model="showCreate" /></template>
|
||||||
</Header>
|
</Header>
|
||||||
<CreatePost
|
|
||||||
v-if="showCreate"
|
|
||||||
class="flex-1 min-h-0 p-1"
|
|
||||||
@done="showCreate = false"
|
|
||||||
@cancel="showCreate = false"
|
|
||||||
/>
|
|
||||||
<div
|
<div
|
||||||
v-if="!showCreate"
|
|
||||||
class="flex flex-col flex-1 min-h-0 p-1 overflow-auto text-left items-start justify-start"
|
class="flex flex-col flex-1 min-h-0 p-1 overflow-auto text-left items-start justify-start"
|
||||||
>
|
>
|
||||||
<small>Created at: {{ new Date(post.createdAt).toLocaleString() }}</small>
|
<small>Created at: {{ new Date(post.createdAt).toLocaleString() }}</small>
|
||||||
@@ -74,6 +68,9 @@ function deletePost() {
|
|||||||
>Delete</Button
|
>Delete</Button
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
<Modal v-model="showCreate" max-width="560px">
|
||||||
|
<CreatePost @done="showCreate = false" @cancel="showCreate = false" />
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, defineAsyncComponent } from "vue";
|
import { ref, computed, defineAsyncComponent } from "vue";
|
||||||
import Header from "@/components/text/Header.vue";
|
import Header from "@/components/text/Header.vue";
|
||||||
|
import Modal from "@/components/util/Modal.vue";
|
||||||
import CreateToggle from "@/components/input/CreateToggle.vue";
|
import CreateToggle from "@/components/input/CreateToggle.vue";
|
||||||
import { useHomeDataStore } from "@/stores/homeData";
|
import { useHomeDataStore } from "@/stores/homeData";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
@@ -116,17 +117,14 @@ function formatValue(key, val) {
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col h-full overflow-hidden">
|
<div class="flex flex-col h-full overflow-hidden">
|
||||||
<Header>
|
<Header>
|
||||||
{{ showCreate ? "Upload Rowing" : "Rowing" }}
|
Rowing
|
||||||
<template #action><CreateToggle v-model="showCreate" /></template>
|
<template #action><CreateToggle v-model="showCreate" /></template>
|
||||||
</Header>
|
</Header>
|
||||||
|
|
||||||
<CreateRowing
|
<Modal v-model="showCreate">
|
||||||
v-if="showCreate"
|
<CreateRowing @done="showCreate = false" @cancel="showCreate = false" />
|
||||||
class="flex-1 p-1"
|
</Modal>
|
||||||
@done="showCreate = false"
|
<div v-if="loading" class="flex-1 flex items-center justify-center">
|
||||||
@cancel="showCreate = false"
|
|
||||||
/>
|
|
||||||
<div v-else-if="loading" class="flex-1 flex items-center justify-center">
|
|
||||||
<p>Loading...</p>
|
<p>Loading...</p>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="error" class="flex-1 flex items-center justify-center">
|
<div v-else-if="error" class="flex-1 flex items-center justify-center">
|
||||||
|
|||||||
Reference in New Issue
Block a user