feat: projekte teilen im frontend
Teilen-Bereich auf der Projektseite mit Mitgliedern und Rollen, Verlassen für Mitglieder. Geteilte Projekte mit Symbol und Besitzer, Clips anderer mit "von <Name>"; ohne Schreibrecht keine Bearbeiten- Buttons und eine reine Leseansicht. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d3a52c25a7
commit
4ae459cf53
17 files changed
+533
-95
No files matched your search
@@ -40,6 +40,9 @@ export type ExpiryDays = 0 | 1 | 7 | 30
|
||||
|
||||
export interface Clip {
|
||||
id: number
|
||||
/** Creator; differs from the current user for clips in shared projects */
|
||||
user_id: number
|
||||
owner_name: string
|
||||
kind: ClipKind
|
||||
title: string | null
|
||||
content: string
|
||||
@@ -65,13 +68,32 @@ export type ClipInput = Partial<
|
||||
export type ProjectColor =
|
||||
'blue' | 'teal' | 'green' | 'amber' | 'orange' | 'red' | 'pink' | 'violet'
|
||||
|
||||
export type ProjectRole = 'owner' | 'edit' | 'read'
|
||||
|
||||
export interface Project {
|
||||
id: number
|
||||
name: string
|
||||
color: ProjectColor
|
||||
/** The current user's role in this project */
|
||||
role: ProjectRole
|
||||
owner_name: string
|
||||
/** Clips of all members */
|
||||
clip_count: number
|
||||
/** Users it is shared with, without the owner */
|
||||
member_count: number
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export type ProjectInput = Partial<Pick<Project, 'name' | 'color'>>
|
||||
|
||||
export interface Member {
|
||||
user_id: number
|
||||
username: string
|
||||
role: ProjectRole
|
||||
}
|
||||
|
||||
export interface UserName {
|
||||
id: number
|
||||
username: string
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { RouterLink } from 'vue-router'
|
||||
import type { Clip } from '@/api/types'
|
||||
import CopyButton from '@/components/CopyButton.vue'
|
||||
import ProjectDot from '@/components/ProjectDot.vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useProjectsStore } from '@/stores/projects'
|
||||
import { formatBytes, formatDateTime, formatExpiry, formatRelative } from '@/utils/format'
|
||||
import { highlight, languageLabel } from '@/utils/highlight'
|
||||
@@ -16,9 +17,12 @@ const props = withDefaults(defineProps<{ clip: Clip; showProject?: boolean }>(),
|
||||
const emit = defineEmits<{ togglePin: []; remove: []; selectProject: [id: number] }>()
|
||||
|
||||
const projects = useProjectsStore()
|
||||
const auth = useAuthStore()
|
||||
const project = computed(() =>
|
||||
props.clip.project_id === null ? undefined : projects.byId.get(props.clip.project_id),
|
||||
)
|
||||
const canEdit = computed(() => projects.canEditClip(props.clip))
|
||||
const fromOther = computed(() => props.clip.user_id !== auth.user?.id)
|
||||
|
||||
const PREVIEW_LINES = 10
|
||||
const PREVIEW_CHARS = 2000
|
||||
@@ -64,13 +68,12 @@ const html = computed(() =>
|
||||
</button>
|
||||
<span v-if="clip.kind === 'code'" class="badge">{{ languageLabel(clip.language) }}</span>
|
||||
</div>
|
||||
<time
|
||||
class="muted small"
|
||||
:datetime="clip.updated_at"
|
||||
:title="formatDateTime(clip.updated_at)"
|
||||
>
|
||||
{{ formatRelative(clip.updated_at, now) }}
|
||||
</time>
|
||||
<span class="muted small when">
|
||||
<template v-if="fromOther">von {{ clip.owner_name }} · </template>
|
||||
<time :datetime="clip.updated_at" :title="formatDateTime(clip.updated_at)">
|
||||
{{ formatRelative(clip.updated_at, now) }}
|
||||
</time>
|
||||
</span>
|
||||
</header>
|
||||
|
||||
<div v-if="clip.file" class="file">
|
||||
@@ -108,11 +111,13 @@ const html = computed(() =>
|
||||
</a>
|
||||
</template>
|
||||
<CopyButton v-else :text="clip.content" />
|
||||
<RouterLink :to="`/clips/${clip.id}`" class="button-link small">Bearbeiten</RouterLink>
|
||||
<button type="button" class="small" @click="emit('togglePin')">
|
||||
{{ clip.pinned ? 'Lösen' : 'Anheften' }}
|
||||
</button>
|
||||
<button type="button" class="small danger" @click="emit('remove')">Löschen</button>
|
||||
<template v-if="canEdit">
|
||||
<RouterLink :to="`/clips/${clip.id}`" class="button-link small">Bearbeiten</RouterLink>
|
||||
<button type="button" class="small" @click="emit('togglePin')">
|
||||
{{ clip.pinned ? 'Lösen' : 'Anheften' }}
|
||||
</button>
|
||||
<button type="button" class="small danger" @click="emit('remove')">Löschen</button>
|
||||
</template>
|
||||
</footer>
|
||||
</article>
|
||||
</template>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { RouterLink } from 'vue-router'
|
||||
|
||||
import ProjectDot from '@/components/ProjectDot.vue'
|
||||
import SharedIcon from '@/components/SharedIcon.vue'
|
||||
import { useProjectsStore } from '@/stores/projects'
|
||||
import type { ProjectFilter } from '@/utils/projects'
|
||||
|
||||
@@ -33,6 +34,10 @@ const projects = useProjectsStore()
|
||||
>
|
||||
<ProjectDot :color="project.color" />
|
||||
<span class="name">{{ project.name }}</span>
|
||||
<SharedIcon
|
||||
v-if="project.role !== 'owner' || project.member_count > 0"
|
||||
:title="project.role === 'owner' ? 'Geteilt' : `Geteilt von ${project.owner_name}`"
|
||||
/>
|
||||
<span class="count">{{ project.clip_count }}</span>
|
||||
</button>
|
||||
<button
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
|
||||
import { api } from '@/api/client'
|
||||
import type { Member, Project, ProjectRole, UserName } from '@/api/types'
|
||||
import { useProjectsStore } from '@/stores/projects'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
|
||||
const props = defineProps<{ project: Project }>()
|
||||
|
||||
const projects = useProjectsStore()
|
||||
const toast = useToastStore()
|
||||
|
||||
const ROLE_LABELS: Record<ProjectRole, string> = {
|
||||
owner: 'Besitzer',
|
||||
edit: 'Bearbeiten',
|
||||
read: 'Lesen',
|
||||
}
|
||||
|
||||
const members = ref<Member[]>([])
|
||||
const users = ref<UserName[]>([])
|
||||
const newUser = ref('')
|
||||
const newRole = ref<ProjectRole>('edit')
|
||||
const error = ref<string | null>(null)
|
||||
const busy = ref(false)
|
||||
|
||||
// Only users who are not in the project yet
|
||||
const candidates = computed(() => {
|
||||
const taken = new Set(members.value.map((m) => m.user_id))
|
||||
return users.value.filter((u) => !taken.has(u.id))
|
||||
})
|
||||
|
||||
async function run(action: () => Promise<Member[] | void>, message?: string): Promise<void> {
|
||||
busy.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const result = await action()
|
||||
if (result) members.value = result
|
||||
if (message) toast.show(message)
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : String(e)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function add(): Promise<void> {
|
||||
const username = newUser.value
|
||||
return run(async () => {
|
||||
const result = await projects.addMember(props.project.id, username, newRole.value)
|
||||
newUser.value = ''
|
||||
return result
|
||||
}, `Mit ${username} geteilt`)
|
||||
}
|
||||
|
||||
function setRole(member: Member, role: ProjectRole): Promise<void> {
|
||||
return run(() => projects.setMemberRole(props.project.id, member.user_id, role))
|
||||
}
|
||||
|
||||
function remove(member: Member): Promise<void> {
|
||||
const text =
|
||||
`${member.username} aus „${props.project.name}“ entfernen? ` +
|
||||
`Clips von ${member.username} in diesem Projekt landen bei ihr bzw. ihm unter „Ohne Projekt“.`
|
||||
if (!confirm(text)) return Promise.resolve()
|
||||
return run(async () => {
|
||||
await projects.removeMember(props.project.id, member.user_id)
|
||||
return projects.members(props.project.id)
|
||||
}, `${member.username} entfernt`)
|
||||
}
|
||||
|
||||
onMounted(() =>
|
||||
run(async () => {
|
||||
users.value = await api.get<UserName[]>('/users')
|
||||
return projects.members(props.project.id)
|
||||
}),
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="members" aria-label="Mitglieder">
|
||||
<ul class="member-list">
|
||||
<li v-for="member in members" :key="member.user_id" class="member">
|
||||
<span class="member-name">{{ member.username }}</span>
|
||||
<span v-if="member.role === 'owner'" class="muted small">{{ ROLE_LABELS.owner }}</span>
|
||||
<div v-else class="controls">
|
||||
<select
|
||||
:value="member.role"
|
||||
:aria-label="`Rolle von ${member.username}`"
|
||||
:disabled="busy"
|
||||
class="role"
|
||||
@change="setRole(member, ($event.target as HTMLSelectElement).value as ProjectRole)"
|
||||
>
|
||||
<option value="edit">{{ ROLE_LABELS.edit }}</option>
|
||||
<option value="read">{{ ROLE_LABELS.read }}</option>
|
||||
</select>
|
||||
<button type="button" class="small danger" :disabled="busy" @click="remove(member)">
|
||||
Entfernen
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<form v-if="candidates.length > 0" class="add" @submit.prevent="add">
|
||||
<select v-model="newUser" aria-label="Benutzer" required class="user">
|
||||
<option value="" disabled>Benutzer wählen …</option>
|
||||
<option v-for="u in candidates" :key="u.id" :value="u.username">{{ u.username }}</option>
|
||||
</select>
|
||||
<select v-model="newRole" aria-label="Rolle" class="role">
|
||||
<option value="edit">{{ ROLE_LABELS.edit }}</option>
|
||||
<option value="read">{{ ROLE_LABELS.read }}</option>
|
||||
</select>
|
||||
<button type="submit" class="primary small" :disabled="busy || !newUser">Teilen</button>
|
||||
</form>
|
||||
<p v-else-if="users.length === 0" class="muted small">
|
||||
Es gibt keine anderen Benutzer. Ein Admin kann unter „Benutzer“ welche anlegen.
|
||||
</p>
|
||||
<p class="muted small hint">
|
||||
Bearbeiten: Clips und Dateien anlegen, ändern und löschen. Lesen: ansehen, kopieren,
|
||||
herunterladen.
|
||||
</p>
|
||||
<p v-if="error" class="error small" role="alert">{{ error }}</p>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.members {
|
||||
display: grid;
|
||||
gap: 0.75rem;
|
||||
margin-top: 0.75rem;
|
||||
padding-top: 0.75rem;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.member-list {
|
||||
display: grid;
|
||||
gap: 0.5rem;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.member,
|
||||
.add {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.member-name {
|
||||
flex: 1;
|
||||
min-width: 6rem;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.role {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
/* Role and remove button wrap together, below the name if needed */
|
||||
.controls {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.user {
|
||||
flex: 1;
|
||||
width: auto;
|
||||
min-width: 10rem;
|
||||
}
|
||||
|
||||
.small {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.hint,
|
||||
.error {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -1,15 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
import { useProjectsStore } from '@/stores/projects'
|
||||
|
||||
const model = defineModel<number | null>({ required: true })
|
||||
/** Also offer this project even without write access (the clip is already in it). */
|
||||
const props = defineProps<{ keep?: number | null }>()
|
||||
const projects = useProjectsStore()
|
||||
|
||||
const options = computed(() =>
|
||||
projects.items.filter((p) => projects.canWrite(p.role) || p.id === props.keep),
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<select v-model="model" aria-label="Projekt" class="project-select">
|
||||
<option :value="null">Ohne Projekt</option>
|
||||
<option v-for="project in projects.items" :key="project.id" :value="project.id">
|
||||
{{ project.name }}
|
||||
<option v-for="project in options" :key="project.id" :value="project.id">
|
||||
{{ project.role === 'owner' ? project.name : `${project.name} (von ${project.owner_name})` }}
|
||||
</option>
|
||||
</select>
|
||||
</template>
|
||||
|
||||
@@ -38,9 +38,11 @@ watch([content, kind], () => {
|
||||
|
||||
// New clips go to the project currently shown
|
||||
watch(
|
||||
() => store.filter.project,
|
||||
(filter) => {
|
||||
projectId.value = typeof filter === 'number' ? filter : null
|
||||
() => [store.filter.project, projects.writable] as const,
|
||||
([filter]) => {
|
||||
// Only projects we may put clips into; read-only shared projects fall back to none
|
||||
const writable = typeof filter === 'number' && projects.writable.some((p) => p.id === filter)
|
||||
projectId.value = writable ? filter : null
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
@@ -169,7 +171,7 @@ async function save(): Promise<void> {
|
||||
>
|
||||
<option v-for="l in LANGUAGES" :key="l.id" :value="l.id">{{ l.label }}</option>
|
||||
</select>
|
||||
<ProjectSelect v-if="projects.items.length > 0" v-model="projectId" />
|
||||
<ProjectSelect v-if="projects.writable.length > 0" v-model="projectId" />
|
||||
<div class="spacer"></div>
|
||||
<div class="buttons">
|
||||
<button type="button" @click="paste">Einfügen</button>
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<template>
|
||||
<!-- Two people: marks projects shared with others -->
|
||||
<svg class="shared-icon" viewBox="0 0 16 16" width="14" height="14" aria-hidden="true">
|
||||
<circle cx="5.5" cy="5" r="2.5" fill="currentColor" />
|
||||
<circle cx="11" cy="5.5" r="2" fill="currentColor" opacity="0.7" />
|
||||
<path d="M1 13.5c0-2.5 2-4 4.5-4s4.5 1.5 4.5 4z" fill="currentColor" />
|
||||
<path
|
||||
d="M10.5 13.5c0-1.6-.5-2.8-1.4-3.6.5-.2 1.1-.4 1.9-.4 2.2 0 4 1.3 4 4z"
|
||||
fill="currentColor"
|
||||
opacity="0.7"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.shared-icon {
|
||||
flex: none;
|
||||
color: var(--muted);
|
||||
}
|
||||
</style>
|
||||
@@ -8,6 +8,8 @@ import { ClipConflictError, matchesFilter, useClipsStore } from './clips'
|
||||
function clip(overrides: Partial<Clip> = {}): Clip {
|
||||
return {
|
||||
id: 1,
|
||||
user_id: 1,
|
||||
owner_name: 'anna',
|
||||
kind: 'text',
|
||||
title: null,
|
||||
content: 'hello',
|
||||
@@ -174,16 +176,22 @@ describe('clips store', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('detaches clips from a deleted project like the backend', () => {
|
||||
it('detaches clips from a deleted or left project like the backend', () => {
|
||||
const store = useClipsStore()
|
||||
store.upsert(clip({ id: 1, project_id: 4, version: 2 }))
|
||||
store.upsert(clip({ id: 2, project_id: 5 }))
|
||||
store.upsert(clip({ id: 3, project_id: 4, user_id: 2, owner_name: 'bert' }))
|
||||
const listener = vi.fn()
|
||||
store.subscribe(listener)
|
||||
|
||||
store.detachProject(4)
|
||||
store.detachProject(4, 1)
|
||||
|
||||
const byId = Object.fromEntries(store.items.map((c) => [c.id, c]))
|
||||
// Own clip stays without project, the other member's clip is no longer visible
|
||||
expect(byId[1]).toMatchObject({ project_id: null, version: 3 })
|
||||
expect(byId[2]).toMatchObject({ project_id: 5, version: 1 })
|
||||
expect(byId[3]).toBeUndefined()
|
||||
expect(listener).toHaveBeenCalledWith({ deleted: 3 })
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -113,10 +113,14 @@ export const useClipsStore = defineStore('clips', () => {
|
||||
emit({ deleted: id })
|
||||
}
|
||||
|
||||
/** Mirror the backend after a project was deleted: its clips lose the project. */
|
||||
function detachProject(projectId: number): void {
|
||||
/**
|
||||
* Mirror the backend after a project was deleted or left: own clips lose the project,
|
||||
* clips of other members are no longer visible.
|
||||
*/
|
||||
function detachProject(projectId: number, myId: number | undefined): void {
|
||||
for (const clip of items.value.filter((c) => c.project_id === projectId)) {
|
||||
upsert({ ...clip, project_id: null, version: clip.version + 1 })
|
||||
if (clip.user_id === myId) upsert({ ...clip, project_id: null, version: clip.version + 1 })
|
||||
else removeLocal(clip.id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,39 @@
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { Project } from '@/api/types'
|
||||
import type { Clip, Project } from '@/api/types'
|
||||
|
||||
import { useAuthStore } from './auth'
|
||||
import { useProjectsStore } from './projects'
|
||||
|
||||
function clipOf(overrides: Partial<Clip>): Clip {
|
||||
return {
|
||||
id: 1,
|
||||
user_id: 1,
|
||||
owner_name: 'anna',
|
||||
kind: 'text',
|
||||
title: null,
|
||||
content: 'x',
|
||||
language: null,
|
||||
pinned: false,
|
||||
project_id: null,
|
||||
file: null,
|
||||
version: 1,
|
||||
created_at: '2026-10-25T10:00:00Z',
|
||||
updated_at: '2026-10-25T10:00:00Z',
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
function project(overrides: Partial<Project> = {}): Project {
|
||||
return {
|
||||
id: 1,
|
||||
name: 'Work',
|
||||
color: 'blue',
|
||||
role: 'owner',
|
||||
owner_name: 'anna',
|
||||
clip_count: 0,
|
||||
member_count: 0,
|
||||
created_at: '2026-10-25T10:00:00Z',
|
||||
updated_at: '2026-10-25T10:00:00Z',
|
||||
...overrides,
|
||||
@@ -60,6 +83,21 @@ describe('projects store', () => {
|
||||
expect(fetchMock).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('knows who may edit which clip', () => {
|
||||
useAuthStore().user = { id: 1, username: 'anna', role: 'user', is_active: true, created_at: '' }
|
||||
const store = useProjectsStore()
|
||||
store.upsert(project({ id: 1, role: 'edit', owner_name: 'bert' }))
|
||||
store.upsert(project({ id: 2, name: 'Read', role: 'read', owner_name: 'bert' }))
|
||||
const base = clipOf({ user_id: 2 })
|
||||
|
||||
expect(store.canEditClip({ ...base, project_id: 1 })).toBe(true)
|
||||
expect(store.canEditClip({ ...base, project_id: 2 })).toBe(false)
|
||||
expect(store.canEditClip({ ...base, project_id: null })).toBe(false)
|
||||
// Own clips always
|
||||
expect(store.canEditClip({ ...base, user_id: 1, project_id: 2 })).toBe(true)
|
||||
expect(store.writable.map((p) => p.id)).toEqual([1])
|
||||
})
|
||||
|
||||
it('reset forgets everything', () => {
|
||||
const store = useProjectsStore()
|
||||
store.upsert(project())
|
||||
|
||||
@@ -2,7 +2,9 @@ import { defineStore } from 'pinia'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import { api } from '@/api/client'
|
||||
import type { Project, ProjectInput } from '@/api/types'
|
||||
import type { Clip, Member, Project, ProjectInput, ProjectRole } from '@/api/types'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useClipsStore } from '@/stores/clips'
|
||||
import { foldCase } from '@/utils/projects'
|
||||
|
||||
// Clip counts are refreshed after clip changes, bundled so bursts cause one request
|
||||
@@ -19,6 +21,18 @@ export const useProjectsStore = defineStore('projects', () => {
|
||||
let refreshTimer: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
const byId = computed(() => new Map(items.value.map((p) => [p.id, p])))
|
||||
/** Projects new clips may be put into */
|
||||
const writable = computed(() => items.value.filter((p) => canWrite(p.role)))
|
||||
|
||||
function canWrite(role: ProjectRole | undefined): boolean {
|
||||
return role === 'owner' || role === 'edit'
|
||||
}
|
||||
|
||||
/** Mirrors backend access rules: own clips always, others' only in editable projects. */
|
||||
function canEditClip(clip: Clip): boolean {
|
||||
if (clip.user_id === useAuthStore().user?.id) return true
|
||||
return clip.project_id !== null && canWrite(byId.value.get(clip.project_id)?.role)
|
||||
}
|
||||
|
||||
function upsert(project: Project): void {
|
||||
const index = items.value.findIndex((p) => p.id === project.id)
|
||||
@@ -66,10 +80,39 @@ export const useProjectsStore = defineStore('projects', () => {
|
||||
removeLocal(id)
|
||||
}
|
||||
|
||||
// --- Members (owner manages, members may leave) ---
|
||||
|
||||
function members(id: number): Promise<Member[]> {
|
||||
return api.get<Member[]>(`/projects/${id}/members`)
|
||||
}
|
||||
|
||||
function addMember(id: number, username: string, role: ProjectRole): Promise<Member[]> {
|
||||
return api.post<Member[]>(`/projects/${id}/members`, { username, role })
|
||||
}
|
||||
|
||||
function setMemberRole(id: number, userId: number, role: ProjectRole): Promise<Member[]> {
|
||||
return api.patch<Member[]>(`/projects/${id}/members/${userId}`, { role })
|
||||
}
|
||||
|
||||
async function removeMember(id: number, userId: number): Promise<void> {
|
||||
await api.delete(`/projects/${id}/members/${userId}`)
|
||||
}
|
||||
|
||||
async function leave(id: number): Promise<void> {
|
||||
const me = useAuthStore().user?.id
|
||||
if (me === undefined) return
|
||||
await removeMember(id, me)
|
||||
removeLocal(id)
|
||||
useClipsStore().detachProject(id, me)
|
||||
}
|
||||
|
||||
return {
|
||||
items,
|
||||
loaded,
|
||||
byId,
|
||||
writable,
|
||||
canWrite,
|
||||
canEditClip,
|
||||
upsert,
|
||||
removeLocal,
|
||||
reset,
|
||||
@@ -78,5 +121,10 @@ export const useProjectsStore = defineStore('projects', () => {
|
||||
create,
|
||||
update,
|
||||
remove,
|
||||
members,
|
||||
addMember,
|
||||
setMemberRole,
|
||||
removeMember,
|
||||
leave,
|
||||
}
|
||||
})
|
||||
@@ -4,6 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { setUnauthorizedHandler } from '@/api/client'
|
||||
import type { Clip } from '@/api/types'
|
||||
|
||||
import { useAuthStore } from './auth'
|
||||
import { useClipsStore } from './clips'
|
||||
import { useProjectsStore } from './projects'
|
||||
import { useSyncStore } from './sync'
|
||||
@@ -42,6 +43,8 @@ const latest = () => FakeSocket.instances.at(-1)!
|
||||
|
||||
const clip: Clip = {
|
||||
id: 7,
|
||||
user_id: 1,
|
||||
owner_name: 'anna',
|
||||
kind: 'text',
|
||||
title: null,
|
||||
content: 'live',
|
||||
@@ -96,6 +99,7 @@ describe('sync store', () => {
|
||||
})
|
||||
|
||||
it('applies project events', () => {
|
||||
useAuthStore().user = { id: 1, username: 'anna', role: 'user', is_active: true, created_at: '' }
|
||||
const sync = useSyncStore()
|
||||
const clips = useClipsStore()
|
||||
const projects = useProjectsStore()
|
||||
@@ -105,7 +109,10 @@ describe('sync store', () => {
|
||||
id: 3,
|
||||
name: 'Work',
|
||||
color: 'blue',
|
||||
role: 'owner',
|
||||
owner_name: 'anna',
|
||||
clip_count: 1,
|
||||
member_count: 0,
|
||||
created_at: '2026-10-25T10:00:00Z',
|
||||
updated_at: '2026-10-25T10:00:00Z',
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ref } from 'vue'
|
||||
|
||||
import { notifyUnauthorized } from '@/api/client'
|
||||
import type { Clip, Project } from '@/api/types'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useClipsStore } from '@/stores/clips'
|
||||
import { useProjectsStore } from '@/stores/projects'
|
||||
|
||||
@@ -59,12 +60,16 @@ export const useSyncStore = defineStore('sync', () => {
|
||||
projects.scheduleRefresh()
|
||||
break
|
||||
case 'project.created':
|
||||
projects.upsert(message.data)
|
||||
// Shared with us: its clips belong in the list now
|
||||
if (message.data.role !== 'owner' && clips.loaded) void clips.load()
|
||||
break
|
||||
case 'project.updated':
|
||||
projects.upsert(message.data)
|
||||
break
|
||||
case 'project.deleted':
|
||||
projects.removeLocal(message.data.id)
|
||||
clips.detachProject(message.data.id)
|
||||
clips.detachProject(message.data.id, useAuthStore().user?.id)
|
||||
break
|
||||
case 'ping':
|
||||
break
|
||||
|
||||
@@ -17,6 +17,8 @@ const upload = vi.mocked(uploadFile)
|
||||
function fileClip(id: number, name: string): Clip {
|
||||
return {
|
||||
id,
|
||||
user_id: 1,
|
||||
owner_name: 'anna',
|
||||
kind: 'file',
|
||||
title: null,
|
||||
content: name,
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { Clip, ClipKind, ExpiryDays } from '@/api/types'
|
||||
import CopyButton from '@/components/CopyButton.vue'
|
||||
import ProjectSelect from '@/components/ProjectSelect.vue'
|
||||
import { ClipConflictError, useClipsStore } from '@/stores/clips'
|
||||
import { useProjectsStore } from '@/stores/projects'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
import { EXPIRY_OPTIONS } from '@/utils/expiry'
|
||||
import { formatBytes, formatDateTime, formatExpiry } from '@/utils/format'
|
||||
@@ -16,6 +17,7 @@ import { detectLanguage, highlight, LANGUAGES } from '@/utils/highlight'
|
||||
const props = defineProps<{ id: string }>()
|
||||
|
||||
const store = useClipsStore()
|
||||
const projects = useProjectsStore()
|
||||
const toast = useToastStore()
|
||||
const router = useRouter()
|
||||
|
||||
@@ -65,6 +67,8 @@ const previewHtml = computed(() =>
|
||||
)
|
||||
|
||||
const isFile = computed(() => clip.value?.kind === 'file')
|
||||
// Reached by URL only; the card hides "Bearbeiten" without write access
|
||||
const readOnly = computed(() => clip.value !== null && !projects.canEditClip(clip.value))
|
||||
|
||||
/** Applied right away, like pinning; does not touch the form. */
|
||||
async function changeExpiry(event: Event): Promise<void> {
|
||||
@@ -212,85 +216,97 @@ onMounted(async () => {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<p v-if="readOnly" class="card notice" role="status">
|
||||
Nur Lesezugriff: Dieser Clip liegt in einem Projekt von {{ clip?.owner_name }}, das mit dir
|
||||
nur zum Lesen geteilt ist.
|
||||
</p>
|
||||
|
||||
<form v-if="clip" class="card form" @submit.prevent="save()">
|
||||
<label>
|
||||
Titel (optional)
|
||||
<input v-model="title" maxlength="200" />
|
||||
</label>
|
||||
<fieldset :disabled="readOnly" class="fields">
|
||||
<label>
|
||||
Titel (optional)
|
||||
<input v-model="title" maxlength="200" />
|
||||
</label>
|
||||
|
||||
<template v-if="clip.file">
|
||||
<div class="file-info">
|
||||
<strong class="file-name">{{ clip.file.name }}</strong>
|
||||
<span class="muted small">
|
||||
{{ formatBytes(clip.file.size) }} · {{ formatExpiry(clip.file.expires_at) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<ProjectSelect v-model="projectId" />
|
||||
<select aria-label="Aufbewahren" class="expiry" value="" @change="changeExpiry">
|
||||
<option value="" disabled>Aufbewahrung ändern …</option>
|
||||
<option v-for="o in EXPIRY_OPTIONS" :key="o.days" :value="o.days">
|
||||
{{ o.days === 0 ? 'Unbegrenzt' : `${o.label} ab jetzt` }}
|
||||
</option>
|
||||
<template v-if="clip.file">
|
||||
<div class="file-info">
|
||||
<strong class="file-name">{{ clip.file.name }}</strong>
|
||||
<span class="muted small">
|
||||
{{ formatBytes(clip.file.size) }} · {{ formatExpiry(clip.file.expires_at) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<ProjectSelect v-model="projectId" :keep="clip.project_id" />
|
||||
<select aria-label="Aufbewahren" class="expiry" value="" @change="changeExpiry">
|
||||
<option value="" disabled>Aufbewahrung ändern …</option>
|
||||
<option v-for="o in EXPIRY_OPTIONS" :key="o.days" :value="o.days">
|
||||
{{ o.days === 0 ? 'Unbegrenzt' : `${o.label} ab jetzt` }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-else class="row">
|
||||
<div class="segmented" role="radiogroup" aria-label="Art">
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="kind === 'text'"
|
||||
:class="{ active: kind === 'text' }"
|
||||
@click="kind = 'text'"
|
||||
>
|
||||
Text
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="kind === 'code'"
|
||||
:class="{ active: kind === 'code' }"
|
||||
@click="kind = 'code'"
|
||||
>
|
||||
Code
|
||||
</button>
|
||||
</div>
|
||||
<select v-if="kind === 'code'" v-model="language" aria-label="Sprache" class="language">
|
||||
<option v-for="l in LANGUAGES" :key="l.id" :value="l.id">{{ l.label }}</option>
|
||||
</select>
|
||||
<ProjectSelect v-model="projectId" :keep="clip.project_id" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-else class="row">
|
||||
<div class="segmented" role="radiogroup" aria-label="Art">
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="kind === 'text'"
|
||||
:class="{ active: kind === 'text' }"
|
||||
@click="kind = 'text'"
|
||||
>
|
||||
Text
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="kind === 'code'"
|
||||
:class="{ active: kind === 'code' }"
|
||||
@click="kind = 'code'"
|
||||
>
|
||||
Code
|
||||
</button>
|
||||
</div>
|
||||
<select v-if="kind === 'code'" v-model="language" aria-label="Sprache" class="language">
|
||||
<option v-for="l in LANGUAGES" :key="l.id" :value="l.id">{{ l.label }}</option>
|
||||
</select>
|
||||
<ProjectSelect v-model="projectId" />
|
||||
</div>
|
||||
<textarea
|
||||
v-if="!isFile"
|
||||
v-model="content"
|
||||
:class="{ mono: kind === 'code' }"
|
||||
rows="14"
|
||||
autocapitalize="off"
|
||||
spellcheck="false"
|
||||
@keydown.enter.ctrl.prevent="save()"
|
||||
@keydown.enter.meta.prevent="save()"
|
||||
></textarea>
|
||||
|
||||
<textarea
|
||||
v-if="!isFile"
|
||||
v-model="content"
|
||||
:class="{ mono: kind === 'code' }"
|
||||
rows="14"
|
||||
autocapitalize="off"
|
||||
spellcheck="false"
|
||||
@keydown.enter.ctrl.prevent="save()"
|
||||
@keydown.enter.meta.prevent="save()"
|
||||
></textarea>
|
||||
|
||||
<template v-if="previewHtml !== null">
|
||||
<span class="muted small">Vorschau</span>
|
||||
<!-- eslint-disable-next-line vue/no-v-html -- highlight.js output is escaped -->
|
||||
<pre class="preview"><code class="hljs" v-html="previewHtml"></code></pre>
|
||||
</template>
|
||||
<template v-if="previewHtml !== null">
|
||||
<span class="muted small">Vorschau</span>
|
||||
<!-- eslint-disable-next-line vue/no-v-html -- highlight.js output is escaped -->
|
||||
<pre class="preview"><code class="hljs" v-html="previewHtml"></code></pre>
|
||||
</template>
|
||||
</fieldset>
|
||||
|
||||
<div class="actions">
|
||||
<button type="submit" class="primary" :disabled="busy || remoteDeleted || !content.trim()">
|
||||
<button
|
||||
v-if="!readOnly"
|
||||
type="submit"
|
||||
class="primary"
|
||||
:disabled="busy || remoteDeleted || !content.trim()"
|
||||
>
|
||||
Speichern
|
||||
</button>
|
||||
<a v-if="clip.file" :href="`/api/files/${clip.id}`" download class="button-link"
|
||||
>Herunterladen</a
|
||||
>
|
||||
<CopyButton v-else :text="content" />
|
||||
<RouterLink to="/" class="button-link">Abbrechen</RouterLink>
|
||||
<RouterLink to="/" class="button-link">{{ readOnly ? 'Zurück' : 'Abbrechen' }}</RouterLink>
|
||||
<div class="spacer"></div>
|
||||
<button type="button" class="danger" @click="remove">Löschen</button>
|
||||
<button v-if="!readOnly" type="button" class="danger" @click="remove">Löschen</button>
|
||||
</div>
|
||||
<p class="muted small">
|
||||
Angelegt {{ formatDateTime(clip.created_at) }} · zuletzt geändert
|
||||
@@ -322,6 +338,17 @@ onMounted(async () => {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
/* Groups the inputs so they can be disabled together; no visual box */
|
||||
.fields {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: 0.75rem;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.file-info {
|
||||
display: grid;
|
||||
padding: 0.75rem;
|
||||
|
||||
@@ -4,6 +4,8 @@ import { ref } from 'vue'
|
||||
import type { Project, ProjectColor } from '@/api/types'
|
||||
import ColorPicker from '@/components/ColorPicker.vue'
|
||||
import ProjectDot from '@/components/ProjectDot.vue'
|
||||
import ProjectMembers from '@/components/ProjectMembers.vue'
|
||||
import SharedIcon from '@/components/SharedIcon.vue'
|
||||
import { useProjectsStore } from '@/stores/projects'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
|
||||
@@ -15,6 +17,7 @@ const newColor = ref<ProjectColor>('blue')
|
||||
const createError = ref<string | null>(null)
|
||||
const busy = ref(false)
|
||||
|
||||
const sharingId = ref<number | null>(null)
|
||||
const editingId = ref<number | null>(null)
|
||||
const editName = ref('')
|
||||
const editColor = ref<ProjectColor>('blue')
|
||||
@@ -61,6 +64,25 @@ async function saveEdit(project: Project): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
function toggleSharing(project: Project): void {
|
||||
sharingId.value = sharingId.value === project.id ? null : project.id
|
||||
}
|
||||
|
||||
async function leave(project: Project): Promise<void> {
|
||||
if (
|
||||
!confirm(
|
||||
`Projekt „${project.name}“ von ${project.owner_name} verlassen? Deine Clips darin landen bei „Ohne Projekt“.`,
|
||||
)
|
||||
)
|
||||
return
|
||||
try {
|
||||
await projects.leave(project.id)
|
||||
toast.show('Projekt verlassen')
|
||||
} catch (e) {
|
||||
toast.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(project: Project): Promise<void> {
|
||||
const n = project.clip_count
|
||||
const clips =
|
||||
@@ -69,7 +91,8 @@ async function remove(project: Project): Promise<void> {
|
||||
: n === 1
|
||||
? ' Der Clip bleibt erhalten und landet bei „Ohne Projekt“.'
|
||||
: ` Die ${n} Clips bleiben erhalten und landen bei „Ohne Projekt“.`
|
||||
if (!confirm(`Projekt „${project.name}“ löschen?${clips}`)) return
|
||||
const shared = project.member_count > 0 ? ' Es wird auch für alle Mitglieder entfernt.' : ''
|
||||
if (!confirm(`Projekt „${project.name}“ löschen?${clips}${shared}`)) return
|
||||
try {
|
||||
await projects.remove(project.id)
|
||||
toast.show('Projekt gelöscht')
|
||||
@@ -121,16 +144,39 @@ async function remove(project: Project): Promise<void> {
|
||||
<RouterLink :to="{ path: '/', query: { p: project.id } }" class="name">
|
||||
<ProjectDot :color="project.color" />
|
||||
<span>{{ project.name }}</span>
|
||||
<SharedIcon v-if="project.role !== 'owner' || project.member_count > 0" />
|
||||
</RouterLink>
|
||||
<span class="muted small">
|
||||
{{ project.clip_count }} {{ project.clip_count === 1 ? 'Clip' : 'Clips' }}
|
||||
<template v-if="project.role !== 'owner'">
|
||||
· von {{ project.owner_name }} ·
|
||||
{{ project.role === 'edit' ? 'Bearbeiten' : 'Lesen' }}
|
||||
</template>
|
||||
<template v-else-if="project.member_count > 0">
|
||||
· geteilt mit {{ project.member_count }}
|
||||
</template>
|
||||
</span>
|
||||
<div class="spacer"></div>
|
||||
<div class="buttons">
|
||||
<div v-if="project.role === 'owner'" class="buttons">
|
||||
<button
|
||||
type="button"
|
||||
class="small"
|
||||
:aria-expanded="sharingId === project.id"
|
||||
@click="toggleSharing(project)"
|
||||
>
|
||||
Teilen
|
||||
</button>
|
||||
<button type="button" class="small" @click="startEdit(project)">Bearbeiten</button>
|
||||
<button type="button" class="small danger" @click="remove(project)">Löschen</button>
|
||||
</div>
|
||||
<div v-else class="buttons">
|
||||
<button type="button" class="small danger" @click="leave(project)">Verlassen</button>
|
||||
</div>
|
||||
</div>
|
||||
<ProjectMembers
|
||||
v-if="sharingId === project.id && editingId !== project.id"
|
||||
:project="project"
|
||||
/>
|
||||
</li>
|
||||
</ul>
|
||||
</main>
|
||||
|
||||
Reference in new issue
Block a user