8b49ea896a
Drift-audit Group 2 (Phase-8 amputation — live wiring, no consumer): - Recurring tasks never recurred: spawn_recurring_tasks() had no caller. Register it as a 15-min interval job in the event scheduler (which app.py already starts/stops). Also add a deleted_at IS NULL guard to the spawn query in the same change, so a trashed recurring parent can never resurrect children once the sweep is live. - Event reminders were stamped reminder_sent_at but never delivered. _fire_reminders now creates an 'event_reminder' in-app notification before stamping, so a delivery failure stays retryable. Frontend NotificationsPanel renders the new type (⏰ + message); message logic pulled into a notifMessage() helper. - Remove the dead _fire_push_notif no-op stub (push left in Phase 8) and its three create_task call sites — no more throwaway tasks per share. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
170 lines
4.2 KiB
Vue
170 lines
4.2 KiB
Vue
<script setup lang="ts">
|
|
import { X } from "lucide-vue-next";
|
|
import { onMounted } from 'vue'
|
|
import { useRouter } from 'vue-router'
|
|
import { useNotificationsStore } from '@/stores/notifications'
|
|
import { relativeTime } from '@/composables/useRelativeTime'
|
|
|
|
const emit = defineEmits<{ close: [] }>()
|
|
const store = useNotificationsStore()
|
|
const router = useRouter()
|
|
|
|
const typeIcon: Record<string, string> = {
|
|
project_shared: '📁',
|
|
note_shared: '📝',
|
|
group_added: '👥',
|
|
event_reminder: '⏰',
|
|
}
|
|
|
|
function notifMessage(n: { type: string; payload: Record<string, unknown> }): string {
|
|
const p = n.payload
|
|
switch (n.type) {
|
|
case 'project_shared':
|
|
return ` shared "${p.project_title}" with you as ${p.permission}`
|
|
case 'note_shared':
|
|
return ` shared "${p.note_title}" with you as ${p.permission}`
|
|
case 'group_added':
|
|
return ` added you to "${p.group_name}" as ${p.role}`
|
|
case 'event_reminder':
|
|
return `Reminder: "${p.title}" is coming up`
|
|
default:
|
|
return ''
|
|
}
|
|
}
|
|
|
|
async function handleClick(notif: { id: number; payload: Record<string, unknown> }) {
|
|
await store.markRead(notif.id)
|
|
const url = notif.payload.url as string | undefined
|
|
if (url) {
|
|
emit('close')
|
|
router.push(url)
|
|
}
|
|
}
|
|
|
|
onMounted(() => store.fetchAll())
|
|
</script>
|
|
|
|
<template>
|
|
<div class="notif-panel" role="dialog" aria-label="Notifications">
|
|
<header class="notif-panel-header">
|
|
<span class="notif-panel-title">Notifications</span>
|
|
<button
|
|
v-if="store.count > 0"
|
|
class="btn-mark-all"
|
|
@click="store.markAll()"
|
|
>Mark all read</button>
|
|
</header>
|
|
|
|
<ul class="notif-list" v-if="store.items.length">
|
|
<li
|
|
v-for="n in store.items"
|
|
:key="n.id"
|
|
class="notif-item"
|
|
@click="handleClick(n)"
|
|
>
|
|
<span class="notif-icon">{{ typeIcon[n.type] ?? '🔔' }}</span>
|
|
<div class="notif-body">
|
|
<p class="notif-msg">
|
|
<strong v-if="n.payload.invited_by">{{ n.payload.invited_by }}</strong>
|
|
{{ notifMessage(n) }}
|
|
</p>
|
|
<span class="notif-time">{{ relativeTime(n.created_at) }}</span>
|
|
</div>
|
|
<button class="btn-notif-close" @click.stop="store.markRead(n.id)" aria-label="Dismiss"><X :size="16" /></button>
|
|
</li>
|
|
</ul>
|
|
<div v-else class="notif-empty">No unread notifications</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.notif-panel {
|
|
position: absolute;
|
|
top: calc(100% + 8px);
|
|
right: 0;
|
|
width: 340px;
|
|
max-height: 400px;
|
|
overflow-y: auto;
|
|
background: var(--color-surface);
|
|
border: 1px solid var(--color-border);
|
|
border-radius: var(--radius-lg);
|
|
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
|
|
z-index: 500;
|
|
}
|
|
|
|
.notif-panel-header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 0.75rem 1rem;
|
|
border-bottom: 1px solid var(--color-border);
|
|
position: sticky;
|
|
top: 0;
|
|
background: var(--color-surface);
|
|
}
|
|
|
|
.notif-panel-title {
|
|
font-weight: 700;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.btn-mark-all {
|
|
background: none;
|
|
border: none;
|
|
color: var(--color-primary);
|
|
font-size: 0.78rem;
|
|
cursor: pointer;
|
|
padding: 0;
|
|
}
|
|
.btn-mark-all:hover { text-decoration: underline; }
|
|
|
|
.notif-list {
|
|
list-style: none;
|
|
padding: 0;
|
|
margin: 0;
|
|
}
|
|
|
|
.notif-item {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
gap: 0.6rem;
|
|
padding: 0.75rem 1rem;
|
|
border-bottom: 1px solid var(--color-border);
|
|
cursor: pointer;
|
|
transition: background 0.1s;
|
|
}
|
|
.notif-item:last-child { border-bottom: none; }
|
|
.notif-item:hover { background: var(--color-hover); }
|
|
|
|
.notif-icon { font-size: 1.2rem; flex-shrink: 0; margin-top: 0.1rem; }
|
|
|
|
.notif-body { flex: 1; min-width: 0; }
|
|
.notif-msg {
|
|
margin: 0 0 0.2rem;
|
|
font-size: 0.85rem;
|
|
color: var(--color-text);
|
|
line-height: 1.4;
|
|
word-break: break-word;
|
|
}
|
|
.notif-time { font-size: 0.75rem; color: var(--color-muted); }
|
|
|
|
.btn-notif-close {
|
|
background: none;
|
|
border: none;
|
|
color: var(--color-muted);
|
|
cursor: pointer;
|
|
font-size: 0.8rem;
|
|
padding: 0.1rem 0.25rem;
|
|
flex-shrink: 0;
|
|
transition: color 0.1s;
|
|
}
|
|
.btn-notif-close:hover { color: var(--color-text); }
|
|
|
|
.notif-empty {
|
|
padding: 1.5rem;
|
|
text-align: center;
|
|
color: var(--color-muted);
|
|
font-size: 0.88rem;
|
|
}
|
|
</style>
|