Gate the places query behind an authenticated user so the list is no longer public, and relax the place mutations from admin-only to any signed-in user. Hide the Places tab and skip the fetch entirely for anonymous visitors. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UKvnE448c1FeepmxZkTezz
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup>
|
||||
import { ref, computed } from "vue";
|
||||
import { ref, computed, watch } from "vue";
|
||||
import Slideshow from "@/components/util/Slideshow.vue";
|
||||
import Modal from "@/components/util/Modal.vue";
|
||||
import PlacesTable from "./PlacesTable.vue";
|
||||
@@ -8,16 +8,20 @@ import { useAuthStore } from "@/stores/auth";
|
||||
|
||||
const images = [{ url: "/img/memes/pidgeon.gif", comment: "鸟" }];
|
||||
|
||||
const tabs = [
|
||||
const auth = useAuthStore();
|
||||
const loggedIn = computed(() => auth.loggedIn);
|
||||
|
||||
const tabs = computed(() => [
|
||||
{ id: "collage", label: "鸟" },
|
||||
{ id: "places", label: "Places" },
|
||||
];
|
||||
...(loggedIn.value ? [{ id: "places", label: "Places" }] : []),
|
||||
]);
|
||||
|
||||
const activeTab = ref("collage");
|
||||
const showAdd = ref(false);
|
||||
|
||||
const auth = useAuthStore();
|
||||
const isAdmin = computed(() => !!auth.user?.admin);
|
||||
watch(loggedIn, (isIn) => {
|
||||
if (!isIn && activeTab.value === "places") activeTab.value = "collage";
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -34,7 +38,7 @@ const isAdmin = computed(() => !!auth.user?.admin);
|
||||
</button>
|
||||
<div class="tab-spacer" />
|
||||
<button
|
||||
v-if="isAdmin && activeTab === 'places'"
|
||||
v-if="loggedIn && activeTab === 'places'"
|
||||
class="tab add-btn"
|
||||
title="Add a place / thing to do"
|
||||
@click="showAdd = true"
|
||||
@@ -45,7 +49,7 @@ const isAdmin = computed(() => !!auth.user?.admin);
|
||||
|
||||
<div class="tab-body">
|
||||
<Slideshow v-if="activeTab === 'collage'" :images="images" />
|
||||
<PlacesTable v-else />
|
||||
<PlacesTable v-else-if="loggedIn" />
|
||||
</div>
|
||||
|
||||
<Modal v-model="showAdd">
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
<script setup>
|
||||
import { computed, onMounted } from "vue";
|
||||
import { computed, onMounted, watch } from "vue";
|
||||
import { usePlacesStore } from "@/stores/places";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
|
||||
const places = usePlacesStore();
|
||||
const auth = useAuthStore();
|
||||
const isAdmin = computed(() => !!auth.user?.admin);
|
||||
const loggedIn = computed(() => auth.loggedIn);
|
||||
|
||||
onMounted(() => {
|
||||
if (!places.loaded && !places.loading) places.fetch();
|
||||
if (loggedIn.value && !places.loaded && !places.loading) places.fetch();
|
||||
});
|
||||
|
||||
watch(loggedIn, (isIn) => {
|
||||
if (isIn && !places.loaded && !places.loading) places.fetch();
|
||||
});
|
||||
|
||||
async function toggleDone(place) {
|
||||
if (!isAdmin.value) return;
|
||||
if (!loggedIn.value) return;
|
||||
try {
|
||||
await places.toggleDone(place);
|
||||
} catch (err) {
|
||||
@@ -21,7 +25,7 @@ async function toggleDone(place) {
|
||||
}
|
||||
|
||||
async function remove(place) {
|
||||
if (!isAdmin.value) return;
|
||||
if (!loggedIn.value) return;
|
||||
if (!confirm(`Delete "${place.title}"?`)) return;
|
||||
try {
|
||||
await places.remove(place.id);
|
||||
@@ -49,7 +53,7 @@ async function remove(place) {
|
||||
<th class="col-loc">Where</th>
|
||||
<th class="col-cat">Type</th>
|
||||
<th class="col-cost">Cost</th>
|
||||
<th v-if="isAdmin" class="col-act"></th>
|
||||
<th v-if="loggedIn" class="col-act"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -61,7 +65,7 @@ async function remove(place) {
|
||||
<td>
|
||||
<div class="title-cell">
|
||||
<button
|
||||
v-if="isAdmin"
|
||||
v-if="loggedIn"
|
||||
class="done-toggle"
|
||||
:title="place.done ? 'Mark as pending' : 'Mark as done'"
|
||||
@click="toggleDone(place)"
|
||||
@@ -75,7 +79,7 @@ async function remove(place) {
|
||||
<td class="col-loc">{{ place.location || "—" }}</td>
|
||||
<td class="col-cat">{{ place.category || "—" }}</td>
|
||||
<td class="col-cost">{{ place.cost || "—" }}</td>
|
||||
<td v-if="isAdmin" class="col-act">
|
||||
<td v-if="loggedIn" class="col-act">
|
||||
<button class="row-action" @click="remove(place)" title="Delete">
|
||||
×
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user