feat: feinschliff für iphone und ipad
- Safe Areas: Header unter Statusleiste/Notch, Ränder im Querformat
- Touch: alle Buttons mind. 44 px, kein Doppeltipp-Zoom-Verzug
- ab 1024 px Breite zwei Spalten für die Clip-Karten
- relative Zeitangaben ('vor 5 Min.'), genaues Datum als Tooltip
- kurze Einblendungen für Speichern, Löschen, Anheften und Fehler
- nach über 60 s im Hintergrund wird die Liste neu geladen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6d58a697e3
commit
57eaede300
19 files changed
+294
-43
No files matched your search
@@ -3,7 +3,7 @@ import { watch } from 'vue'
|
|||||||
import { RouterView } from 'vue-router'
|
import { RouterView } from 'vue-router'
|
||||||
|
|
||||||
import AppHeader from '@/components/AppHeader.vue'
|
import AppHeader from '@/components/AppHeader.vue'
|
||||||
import UpdateBanner from '@/components/UpdateBanner.vue'
|
import ToastHost from '@/components/ToastHost.vue'
|
||||||
import { useAuthStore } from '@/stores/auth'
|
import { useAuthStore } from '@/stores/auth'
|
||||||
import { useClipsStore } from '@/stores/clips'
|
import { useClipsStore } from '@/stores/clips'
|
||||||
import { useSyncStore } from '@/stores/sync'
|
import { useSyncStore } from '@/stores/sync'
|
||||||
@@ -29,5 +29,5 @@ watch(
|
|||||||
<template>
|
<template>
|
||||||
<AppHeader v-if="auth.user" />
|
<AppHeader v-if="auth.user" />
|
||||||
<RouterView />
|
<RouterView />
|
||||||
<UpdateBanner />
|
<ToastHost />
|
||||||
</template>
|
</template>
|
||||||
@@ -32,9 +32,18 @@ body {
|
|||||||
-webkit-text-size-adjust: 100%;
|
-webkit-text-size-adjust: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Top inset is handled by the sticky header (status bar overlays the app on iOS) */
|
||||||
body {
|
body {
|
||||||
padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
|
padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
|
||||||
env(safe-area-inset-left);
|
}
|
||||||
|
|
||||||
|
button,
|
||||||
|
a,
|
||||||
|
select,
|
||||||
|
input,
|
||||||
|
textarea {
|
||||||
|
/* No double-tap-to-zoom delay on touch devices */
|
||||||
|
touch-action: manipulation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- Shared building blocks ------------------------------------------------ */
|
/* --- Shared building blocks ------------------------------------------------ */
|
||||||
@@ -215,3 +224,15 @@ code {
|
|||||||
background: var(--accent);
|
background: var(--accent);
|
||||||
color: var(--bg);
|
color: var(--bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.page.wide {
|
||||||
|
max-width: 72rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Touch devices: every control at least 44 px high */
|
||||||
|
@media (pointer: coarse) {
|
||||||
|
button.small,
|
||||||
|
.button-link.small {
|
||||||
|
min-height: 44px;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,7 +50,7 @@ async function logout(): Promise<void> {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
gap: 0.5rem 1rem;
|
gap: 0.5rem 1rem;
|
||||||
padding: 0.5rem 1rem;
|
padding: calc(0.5rem + env(safe-area-inset-top)) 1rem 0.5rem;
|
||||||
background: var(--surface);
|
background: var(--surface);
|
||||||
border-bottom: 1px solid var(--border);
|
border-bottom: 1px solid var(--border);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ import { RouterLink } from 'vue-router'
|
|||||||
|
|
||||||
import type { Clip } from '@/api/types'
|
import type { Clip } from '@/api/types'
|
||||||
import CopyButton from '@/components/CopyButton.vue'
|
import CopyButton from '@/components/CopyButton.vue'
|
||||||
import { formatDateTime } from '@/utils/format'
|
import { formatDateTime, formatRelative } from '@/utils/format'
|
||||||
import { highlight, languageLabel } from '@/utils/highlight'
|
import { highlight, languageLabel } from '@/utils/highlight'
|
||||||
|
import { now } from '@/utils/now'
|
||||||
|
|
||||||
const props = defineProps<{ clip: Clip }>()
|
const props = defineProps<{ clip: Clip }>()
|
||||||
const emit = defineEmits<{ togglePin: []; remove: [] }>()
|
const emit = defineEmits<{ togglePin: []; remove: [] }>()
|
||||||
@@ -38,7 +39,13 @@ const html = computed(() =>
|
|||||||
<span v-if="clip.pinned" class="badge accent">angeheftet</span>
|
<span v-if="clip.pinned" class="badge accent">angeheftet</span>
|
||||||
<span v-if="clip.kind === 'code'" class="badge">{{ languageLabel(clip.language) }}</span>
|
<span v-if="clip.kind === 'code'" class="badge">{{ languageLabel(clip.language) }}</span>
|
||||||
</div>
|
</div>
|
||||||
<span class="muted small">{{ formatDateTime(clip.updated_at) }}</span>
|
<time
|
||||||
|
class="muted small"
|
||||||
|
:datetime="clip.updated_at"
|
||||||
|
:title="formatDateTime(clip.updated_at)"
|
||||||
|
>
|
||||||
|
{{ formatRelative(clip.updated_at, now) }}
|
||||||
|
</time>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<!-- eslint-disable-next-line vue/no-v-html -- highlight.js output is escaped -->
|
<!-- eslint-disable-next-line vue/no-v-html -- highlight.js output is escaped -->
|
||||||
@@ -61,6 +68,11 @@ const html = computed(() =>
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
.clip {
|
||||||
|
margin: 0;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.clip.pinned {
|
.clip.pinned {
|
||||||
border-color: var(--accent);
|
border-color: var(--accent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ import { computed, ref, watch } from 'vue'
|
|||||||
|
|
||||||
import type { ClipKind } from '@/api/types'
|
import type { ClipKind } from '@/api/types'
|
||||||
import { useClipsStore } from '@/stores/clips'
|
import { useClipsStore } from '@/stores/clips'
|
||||||
|
import { useToastStore } from '@/stores/toast'
|
||||||
import { readClipboardText } from '@/utils/clipboard'
|
import { readClipboardText } from '@/utils/clipboard'
|
||||||
import { detectLanguage, LANGUAGES } from '@/utils/highlight'
|
import { detectLanguage, LANGUAGES } from '@/utils/highlight'
|
||||||
|
|
||||||
const store = useClipsStore()
|
const store = useClipsStore()
|
||||||
|
const toast = useToastStore()
|
||||||
|
|
||||||
const content = ref('')
|
const content = ref('')
|
||||||
const kind = ref<ClipKind>('text')
|
const kind = ref<ClipKind>('text')
|
||||||
@@ -58,6 +60,7 @@ async function save(): Promise<void> {
|
|||||||
content.value = ''
|
content.value = ''
|
||||||
kind.value = 'text'
|
kind.value = 'text'
|
||||||
languageTouched.value = false
|
languageTouched.value = false
|
||||||
|
toast.show('Gespeichert')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error.value = e instanceof Error ? e.message : String(e)
|
error.value = e instanceof Error ? e.message : String(e)
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { applyUpdate, updateAvailable } from '@/pwa'
|
||||||
|
import { useToastStore } from '@/stores/toast'
|
||||||
|
|
||||||
|
const toast = useToastStore()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="toast-host" aria-live="polite">
|
||||||
|
<div v-if="updateAvailable" class="toast update" role="status">
|
||||||
|
<span>Neue Version verfügbar</span>
|
||||||
|
<button type="button" class="primary small" @click="applyUpdate">Neu laden</button>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
v-for="t in toast.toasts"
|
||||||
|
:key="t.id"
|
||||||
|
type="button"
|
||||||
|
class="toast"
|
||||||
|
:class="t.kind"
|
||||||
|
:role="t.kind === 'error' ? 'alert' : 'status'"
|
||||||
|
@click="toast.dismiss(t.id)"
|
||||||
|
>
|
||||||
|
{{ t.text }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.toast-host {
|
||||||
|
position: fixed;
|
||||||
|
left: 50%;
|
||||||
|
bottom: calc(1rem + env(safe-area-inset-bottom));
|
||||||
|
z-index: 20;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
width: min(28rem, calc(100vw - 2rem));
|
||||||
|
transform: translateX(-50%);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 1rem;
|
||||||
|
min-height: 44px;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
box-shadow: 0 4px 16px rgb(0 0 0 / 40%);
|
||||||
|
color: var(--text);
|
||||||
|
font: inherit;
|
||||||
|
text-align: center;
|
||||||
|
pointer-events: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast.error {
|
||||||
|
border-color: var(--error);
|
||||||
|
color: var(--error);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast.update {
|
||||||
|
width: 100%;
|
||||||
|
border-color: var(--accent);
|
||||||
|
padding-right: 0.5rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { applyUpdate, updateAvailable } from '@/pwa'
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div v-if="updateAvailable" class="update-banner" role="status">
|
|
||||||
<span>Neue Version verfügbar</span>
|
|
||||||
<button type="button" class="primary small" @click="applyUpdate">Neu laden</button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.update-banner {
|
|
||||||
position: fixed;
|
|
||||||
left: 50%;
|
|
||||||
bottom: calc(1rem + env(safe-area-inset-bottom));
|
|
||||||
z-index: 20;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 1rem;
|
|
||||||
padding: 0.5rem 0.5rem 0.5rem 1rem;
|
|
||||||
transform: translateX(-50%);
|
|
||||||
background: var(--surface);
|
|
||||||
border: 1px solid var(--accent);
|
|
||||||
border-radius: var(--radius);
|
|
||||||
box-shadow: 0 4px 16px rgb(0 0 0 / 40%);
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -9,6 +9,7 @@ import App from './App.vue'
|
|||||||
import { initPwa } from './pwa'
|
import { initPwa } from './pwa'
|
||||||
import router from './router'
|
import router from './router'
|
||||||
import { useAuthStore } from './stores/auth'
|
import { useAuthStore } from './stores/auth'
|
||||||
|
import { startClock } from './utils/now'
|
||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
|
|
||||||
@@ -25,3 +26,4 @@ setUnauthorizedHandler(() => {
|
|||||||
|
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
initPwa()
|
initPwa()
|
||||||
|
startClock()
|
||||||
@@ -154,6 +154,30 @@ describe('sync store', () => {
|
|||||||
expect(sync.status).toBe('live')
|
expect(sync.status).toBe('live')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('reloads the list after more than 60 s in the background', () => {
|
||||||
|
const sync = useSyncStore()
|
||||||
|
const clips = useClipsStore()
|
||||||
|
clips.loaded = true
|
||||||
|
const load = vi.spyOn(clips, 'load').mockResolvedValue()
|
||||||
|
sync.start()
|
||||||
|
let visibility: DocumentVisibilityState = 'visible'
|
||||||
|
vi.spyOn(document, 'visibilityState', 'get').mockImplementation(() => visibility)
|
||||||
|
const setVisibility = (state: DocumentVisibilityState) => {
|
||||||
|
visibility = state
|
||||||
|
document.dispatchEvent(new Event('visibilitychange'))
|
||||||
|
}
|
||||||
|
|
||||||
|
setVisibility('hidden')
|
||||||
|
vi.advanceTimersByTime(30_000)
|
||||||
|
setVisibility('visible')
|
||||||
|
expect(load).not.toHaveBeenCalled()
|
||||||
|
|
||||||
|
setVisibility('hidden')
|
||||||
|
vi.advanceTimersByTime(61_000)
|
||||||
|
setVisibility('visible')
|
||||||
|
expect(load).toHaveBeenCalledOnce()
|
||||||
|
})
|
||||||
|
|
||||||
it('stop closes the socket and does not reconnect', () => {
|
it('stop closes the socket and does not reconnect', () => {
|
||||||
const sync = useSyncStore()
|
const sync = useSyncStore()
|
||||||
sync.start()
|
sync.start()
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ const MAX_RETRY_MS = 30_000
|
|||||||
// Server pings every 30 s; silence beyond this means the connection is dead
|
// Server pings every 30 s; silence beyond this means the connection is dead
|
||||||
const WATCHDOG_MS = 75_000
|
const WATCHDOG_MS = 75_000
|
||||||
const CLOSE_UNAUTHORIZED = 4401
|
const CLOSE_UNAUTHORIZED = 4401
|
||||||
|
// iOS may keep a dead socket "open" in the background; refresh after longer absences
|
||||||
|
const STALE_AFTER_HIDDEN_MS = 60_000
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Live sync: receives change events over a WebSocket and applies them to the clip store.
|
* Live sync: receives change events over a WebSocket and applies them to the clip store.
|
||||||
@@ -32,6 +34,7 @@ export const useSyncStore = defineStore('sync', () => {
|
|||||||
let retryTimer: ReturnType<typeof setTimeout> | undefined
|
let retryTimer: ReturnType<typeof setTimeout> | undefined
|
||||||
let watchdogTimer: ReturnType<typeof setTimeout> | undefined
|
let watchdogTimer: ReturnType<typeof setTimeout> | undefined
|
||||||
let listenersAdded = false
|
let listenersAdded = false
|
||||||
|
let hiddenSince: number | null = null
|
||||||
|
|
||||||
function handle(message: ServerMessage): void {
|
function handle(message: ServerMessage): void {
|
||||||
const clips = useClipsStore()
|
const clips = useClipsStore()
|
||||||
@@ -108,6 +111,18 @@ export const useSyncStore = defineStore('sync', () => {
|
|||||||
retryDelay = Math.min(retryDelay * 2, MAX_RETRY_MS)
|
retryDelay = Math.min(retryDelay * 2, MAX_RETRY_MS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onVisibilityChange(): void {
|
||||||
|
if (document.visibilityState === 'hidden') {
|
||||||
|
hiddenSince = Date.now()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const away = hiddenSince === null ? 0 : Date.now() - hiddenSince
|
||||||
|
hiddenSince = null
|
||||||
|
const clips = useClipsStore()
|
||||||
|
if (wanted && away >= STALE_AFTER_HIDDEN_MS && clips.loaded) void clips.load()
|
||||||
|
reconnectNow()
|
||||||
|
}
|
||||||
|
|
||||||
/** Reconnect right away, e.g. when an iPhone brings the app back to the foreground. */
|
/** Reconnect right away, e.g. when an iPhone brings the app back to the foreground. */
|
||||||
function reconnectNow(): void {
|
function reconnectNow(): void {
|
||||||
if (!wanted || document.visibilityState !== 'visible') return
|
if (!wanted || document.visibilityState !== 'visible') return
|
||||||
@@ -121,7 +136,7 @@ export const useSyncStore = defineStore('sync', () => {
|
|||||||
function start(): void {
|
function start(): void {
|
||||||
wanted = true
|
wanted = true
|
||||||
if (!listenersAdded) {
|
if (!listenersAdded) {
|
||||||
document.addEventListener('visibilitychange', reconnectNow)
|
document.addEventListener('visibilitychange', onVisibilityChange)
|
||||||
window.addEventListener('online', reconnectNow)
|
window.addEventListener('online', reconnectNow)
|
||||||
listenersAdded = true
|
listenersAdded = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { createPinia, setActivePinia } from 'pinia'
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
|
||||||
|
import { useToastStore } from './toast'
|
||||||
|
|
||||||
|
describe('toast store', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
setActivePinia(createPinia())
|
||||||
|
vi.useFakeTimers()
|
||||||
|
})
|
||||||
|
afterEach(() => vi.useRealTimers())
|
||||||
|
|
||||||
|
it('dismisses info toasts after 2.5 s and errors after 5 s', () => {
|
||||||
|
const toast = useToastStore()
|
||||||
|
toast.show('Gespeichert')
|
||||||
|
toast.error(new Error('Kaputt'))
|
||||||
|
expect(toast.toasts.map((t) => t.text)).toEqual(['Gespeichert', 'Kaputt'])
|
||||||
|
|
||||||
|
vi.advanceTimersByTime(2500)
|
||||||
|
expect(toast.toasts.map((t) => t.kind)).toEqual(['error'])
|
||||||
|
vi.advanceTimersByTime(2500)
|
||||||
|
expect(toast.toasts).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can be dismissed early', () => {
|
||||||
|
const toast = useToastStore()
|
||||||
|
toast.show('Hallo')
|
||||||
|
toast.dismiss(toast.toasts[0]!.id)
|
||||||
|
expect(toast.toasts).toEqual([])
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
export interface Toast {
|
||||||
|
id: number
|
||||||
|
text: string
|
||||||
|
kind: 'info' | 'error'
|
||||||
|
}
|
||||||
|
|
||||||
|
const DURATION_MS = { info: 2500, error: 5000 } as const
|
||||||
|
|
||||||
|
/** Short, self-dismissing notices at the bottom of the screen. */
|
||||||
|
export const useToastStore = defineStore('toast', () => {
|
||||||
|
const toasts = ref<Toast[]>([])
|
||||||
|
let nextId = 1
|
||||||
|
|
||||||
|
function dismiss(id: number): void {
|
||||||
|
toasts.value = toasts.value.filter((t) => t.id !== id)
|
||||||
|
}
|
||||||
|
|
||||||
|
function show(text: string, kind: Toast['kind'] = 'info'): void {
|
||||||
|
const id = nextId++
|
||||||
|
toasts.value.push({ id, text, kind })
|
||||||
|
setTimeout(() => dismiss(id), DURATION_MS[kind])
|
||||||
|
}
|
||||||
|
|
||||||
|
function error(e: unknown): void {
|
||||||
|
show(e instanceof Error ? e.message : String(e), 'error')
|
||||||
|
}
|
||||||
|
|
||||||
|
return { toasts, show, error, dismiss }
|
||||||
|
})
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { describe, expect, it } from 'vitest'
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
import { describeUserAgent, formatDateTime } from './format'
|
import { describeUserAgent, formatDateTime, formatRelative } from './format'
|
||||||
|
|
||||||
describe('describeUserAgent', () => {
|
describe('describeUserAgent', () => {
|
||||||
it.each([
|
it.each([
|
||||||
@@ -36,3 +36,22 @@ describe('formatDateTime', () => {
|
|||||||
expect(formatDateTime('2026-10-25T09:30:00Z')).toMatch(/25\.10\.2026|25\. Okt\. 2026/)
|
expect(formatDateTime('2026-10-25T09:30:00Z')).toMatch(/25\.10\.2026|25\. Okt\. 2026/)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('formatRelative', () => {
|
||||||
|
const now = Date.parse('2026-10-25T12:00:00Z')
|
||||||
|
const ago = (ms: number) => new Date(now - ms).toISOString()
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[10_000, 'gerade eben'],
|
||||||
|
[5 * 60_000, 'vor 5 Min.'],
|
||||||
|
[3 * 3_600_000, 'vor 3 Std.'],
|
||||||
|
[26 * 3_600_000, 'gestern'],
|
||||||
|
[3 * 86_400_000, 'vor 3 Tagen'],
|
||||||
|
])('%i ms ago', (ms, expected) => {
|
||||||
|
expect(formatRelative(ago(ms), now)).toBe(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows the full date after a week', () => {
|
||||||
|
expect(formatRelative(ago(8 * 86_400_000), now)).toBe(formatDateTime(ago(8 * 86_400_000)))
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -7,6 +7,22 @@ export function formatDateTime(iso: string): string {
|
|||||||
return dateTimeFormat.format(new Date(iso))
|
return dateTimeFormat.format(new Date(iso))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relativeFormat = new Intl.RelativeTimeFormat('de-DE', { numeric: 'auto', style: 'short' })
|
||||||
|
|
||||||
|
const MINUTE = 60_000
|
||||||
|
const HOUR = 60 * MINUTE
|
||||||
|
const DAY = 24 * HOUR
|
||||||
|
|
||||||
|
/** "gerade eben", "vor 5 Min.", "vor 3 Std.", "gestern"; older than a week: full date. */
|
||||||
|
export function formatRelative(iso: string, now: number = Date.now()): string {
|
||||||
|
const diff = now - new Date(iso).getTime()
|
||||||
|
if (diff < MINUTE) return 'gerade eben'
|
||||||
|
if (diff < HOUR) return relativeFormat.format(-Math.floor(diff / MINUTE), 'minute')
|
||||||
|
if (diff < DAY) return relativeFormat.format(-Math.floor(diff / HOUR), 'hour')
|
||||||
|
if (diff < 7 * DAY) return relativeFormat.format(-Math.floor(diff / DAY), 'day')
|
||||||
|
return formatDateTime(iso)
|
||||||
|
}
|
||||||
|
|
||||||
// Order matters: iPad/iPhone before macOS, Edge/Chrome before Safari
|
// Order matters: iPad/iPhone before macOS, Edge/Chrome before Safari
|
||||||
const DEVICES: [RegExp, string][] = [
|
const DEVICES: [RegExp, string][] = [
|
||||||
[/iPad/, 'iPad'],
|
[/iPad/, 'iPad'],
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
/** Current time, updated every 30 s, so relative timestamps stay fresh without reloads. */
|
||||||
|
export const now = ref(Date.now())
|
||||||
|
|
||||||
|
let timer: ReturnType<typeof setInterval> | undefined
|
||||||
|
|
||||||
|
export function startClock(): void {
|
||||||
|
timer ??= setInterval(() => (now.value = Date.now()), 30_000)
|
||||||
|
}
|
||||||
@@ -6,12 +6,14 @@ import { ApiError } from '@/api/client'
|
|||||||
import type { Clip, ClipKind } from '@/api/types'
|
import type { Clip, ClipKind } from '@/api/types'
|
||||||
import CopyButton from '@/components/CopyButton.vue'
|
import CopyButton from '@/components/CopyButton.vue'
|
||||||
import { ClipConflictError, useClipsStore } from '@/stores/clips'
|
import { ClipConflictError, useClipsStore } from '@/stores/clips'
|
||||||
|
import { useToastStore } from '@/stores/toast'
|
||||||
import { formatDateTime } from '@/utils/format'
|
import { formatDateTime } from '@/utils/format'
|
||||||
import { detectLanguage, highlight, LANGUAGES } from '@/utils/highlight'
|
import { detectLanguage, highlight, LANGUAGES } from '@/utils/highlight'
|
||||||
|
|
||||||
const props = defineProps<{ id: string }>()
|
const props = defineProps<{ id: string }>()
|
||||||
|
|
||||||
const store = useClipsStore()
|
const store = useClipsStore()
|
||||||
|
const toast = useToastStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const clip = ref<Clip | null>(null)
|
const clip = ref<Clip | null>(null)
|
||||||
@@ -89,6 +91,7 @@ async function save(version = baseVersion.value): Promise<void> {
|
|||||||
conflict.value = null
|
conflict.value = null
|
||||||
leaving = true
|
leaving = true
|
||||||
clip.value = null // nothing left to lose; skip the leave guard
|
clip.value = null // nothing left to lose; skip the leave guard
|
||||||
|
toast.show('Gespeichert')
|
||||||
await router.push('/')
|
await router.push('/')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof ClipConflictError) {
|
if (e instanceof ClipConflictError) {
|
||||||
@@ -113,6 +116,7 @@ async function remove(): Promise<void> {
|
|||||||
try {
|
try {
|
||||||
await store.remove(clip.value.id)
|
await store.remove(clip.value.id)
|
||||||
clip.value = null
|
clip.value = null
|
||||||
|
toast.show('Gelöscht')
|
||||||
await router.push('/')
|
await router.push('/')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
leaving = false
|
leaving = false
|
||||||
|
|||||||
@@ -5,14 +5,17 @@ import type { Clip } from '@/api/types'
|
|||||||
import ClipCard from '@/components/ClipCard.vue'
|
import ClipCard from '@/components/ClipCard.vue'
|
||||||
import QuickAdd from '@/components/QuickAdd.vue'
|
import QuickAdd from '@/components/QuickAdd.vue'
|
||||||
import { useClipsStore } from '@/stores/clips'
|
import { useClipsStore } from '@/stores/clips'
|
||||||
|
import { useToastStore } from '@/stores/toast'
|
||||||
|
|
||||||
const store = useClipsStore()
|
const store = useClipsStore()
|
||||||
|
const toast = useToastStore()
|
||||||
|
|
||||||
async function togglePin(clip: Clip): Promise<void> {
|
async function togglePin(clip: Clip): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await store.update(clip.id, { pinned: !clip.pinned })
|
await store.update(clip.id, { pinned: !clip.pinned })
|
||||||
|
toast.show(clip.pinned ? 'Gelöst' : 'Angeheftet')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
store.error = e instanceof Error ? e.message : String(e)
|
toast.error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,8 +23,9 @@ async function remove(clip: Clip): Promise<void> {
|
|||||||
if (!confirm('Diesen Clip endgültig löschen?')) return
|
if (!confirm('Diesen Clip endgültig löschen?')) return
|
||||||
try {
|
try {
|
||||||
await store.remove(clip.id)
|
await store.remove(clip.id)
|
||||||
|
toast.show('Gelöscht')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
store.error = e instanceof Error ? e.message : String(e)
|
toast.error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +33,7 @@ onMounted(store.load)
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<main class="page">
|
<main class="page wide">
|
||||||
<QuickAdd />
|
<QuickAdd />
|
||||||
|
|
||||||
<p v-if="store.error" class="error" role="alert">{{ store.error }}</p>
|
<p v-if="store.error" class="error" role="alert">{{ store.error }}</p>
|
||||||
@@ -38,6 +42,7 @@ onMounted(store.load)
|
|||||||
Noch keine Clips. Füge oben Text oder Code ein.
|
Noch keine Clips. Füge oben Text oder Code ein.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<div class="clip-grid">
|
||||||
<ClipCard
|
<ClipCard
|
||||||
v-for="clip in store.items"
|
v-for="clip in store.items"
|
||||||
:key="clip.id"
|
:key="clip.id"
|
||||||
@@ -45,6 +50,7 @@ onMounted(store.load)
|
|||||||
@toggle-pin="togglePin(clip)"
|
@toggle-pin="togglePin(clip)"
|
||||||
@remove="remove(clip)"
|
@remove="remove(clip)"
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
v-if="store.items.length < store.total"
|
v-if="store.items.length < store.total"
|
||||||
@@ -63,6 +69,21 @@ onMounted(store.load)
|
|||||||
padding: 2rem 0;
|
padding: 2rem 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.clip-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr);
|
||||||
|
align-items: start;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* iPad landscape and desktop: two columns */
|
||||||
|
@media (min-width: 1024px) {
|
||||||
|
.clip-grid {
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.more {
|
.more {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ async function submit(): Promise<void> {
|
|||||||
.login {
|
.login {
|
||||||
max-width: 24rem;
|
max-width: 24rem;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 15vh 1rem 2rem;
|
padding: calc(15vh + env(safe-area-inset-top)) 1rem 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ function retry(): void {
|
|||||||
.offline {
|
.offline {
|
||||||
max-width: 28rem;
|
max-width: 28rem;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 20vh 1rem 2rem;
|
padding: calc(20vh + env(safe-area-inset-top)) 1rem 2rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
Reference in new issue
Block a user