Added Phase‑1 continuation work across deep links, offline moderation queue, and admin push.

resources/js/admin/mobile/lib.
  - Admin push is end‑to‑end: new backend model/migration/service/job + API endpoints, admin runtime config, push‑aware
    service worker, and a settings toggle via useAdminPushSubscription. Notifications now auto‑refresh on push.
  - New PHP/JS tests: admin push API feature test and queue/haptics unit tests
  Added admin-specific PWA icon assets and wired them into the admin manifest, service worker, and admin shell, plus a
  new “Device & permissions” card in mobile Settings with a persistent storage action and translations.
  Details: public/manifest.json, public/admin-sw.js, resources/views/admin.blade.php, new icons in public/; new hook
  resources/js/admin/mobile/hooks/useDevicePermissions.ts, helpers/tests in resources/js/admin/mobile/lib/
  devicePermissions.ts + resources/js/admin/mobile/lib/devicePermissions.test.ts, and Settings UI updates in resources/
  js/admin/mobile/SettingsPage.tsx with copy in resources/js/admin/i18n/locales/en/management.json and resources/js/
admin/i18n/locales/de/management.json.
This commit is contained in:
Codex Agent
2025-12-28 15:00:47 +01:00
parent 4ce409e918
commit b780d82d62
42 changed files with 2258 additions and 121 deletions

View File

@@ -0,0 +1,34 @@
import { describe, expect, it } from 'vitest';
import { normalizePermissionState, resolveStorageStatus } from './devicePermissions';
describe('normalizePermissionState', () => {
it('maps default to prompt', () => {
expect(normalizePermissionState('default')).toBe('prompt');
});
it('maps undefined to unsupported', () => {
expect(normalizePermissionState(undefined)).toBe('unsupported');
});
it('passes through granted', () => {
expect(normalizePermissionState('granted')).toBe('granted');
});
it('passes through denied', () => {
expect(normalizePermissionState('denied')).toBe('denied');
});
});
describe('resolveStorageStatus', () => {
it('returns unsupported when not supported', () => {
expect(resolveStorageStatus(null, false)).toBe('unsupported');
});
it('returns persisted when granted', () => {
expect(resolveStorageStatus(true, true)).toBe('persisted');
});
it('returns available when supported but not persisted', () => {
expect(resolveStorageStatus(false, true)).toBe('available');
});
});

View File

@@ -0,0 +1,28 @@
export type PermissionStatus = 'granted' | 'denied' | 'prompt' | 'unsupported';
export type StorageStatus = 'persisted' | 'available' | 'unsupported';
type RawPermissionState = PermissionState | 'default' | null | undefined;
export function normalizePermissionState(state: RawPermissionState): PermissionStatus {
if (!state) {
return 'unsupported';
}
if (state === 'default') {
return 'prompt';
}
return state;
}
export function resolveStorageStatus(persisted: boolean | null, supported: boolean): StorageStatus {
if (!supported) {
return 'unsupported';
}
if (persisted) {
return 'persisted';
}
return 'available';
}

View File

@@ -0,0 +1,19 @@
import { describe, expect, it, vi } from 'vitest';
import { triggerHaptic } from './haptics';
describe('triggerHaptic', () => {
it('uses navigator.vibrate when available', () => {
const vibrate = vi.fn();
Object.defineProperty(navigator, 'vibrate', { value: vibrate, configurable: true });
triggerHaptic();
expect(vibrate).toHaveBeenCalled();
});
it('does nothing when vibrate is unavailable', () => {
Object.defineProperty(navigator, 'vibrate', { value: undefined, configurable: true });
expect(() => triggerHaptic('success')).not.toThrow();
});
});

View File

@@ -0,0 +1,19 @@
export type HapticStyle = 'light' | 'medium' | 'heavy' | 'success' | 'warning' | 'error' | 'selection';
const PATTERNS: Record<HapticStyle, number | number[]> = {
light: 10,
medium: 18,
heavy: 26,
success: [10, 28, 10],
warning: [22, 30, 16],
error: [30, 30, 30],
selection: 12,
};
export function triggerHaptic(style: HapticStyle = 'selection'): void {
if (typeof navigator === 'undefined' || typeof navigator.vibrate !== 'function') {
return;
}
navigator.vibrate(PATTERNS[style] ?? PATTERNS.selection);
}

View File

@@ -0,0 +1,49 @@
import { beforeEach, describe, expect, it } from 'vitest';
import {
enqueuePhotoAction,
loadPhotoQueue,
removePhotoAction,
replacePhotoQueue,
type PhotoModerationAction,
} from './photoModerationQueue';
describe('photoModerationQueue', () => {
beforeEach(() => {
window.localStorage.clear();
});
it('enqueues and loads actions', () => {
const queue = enqueuePhotoAction({ eventSlug: 'demo-event', photoId: 12, action: 'approve' });
expect(queue).toHaveLength(1);
const loaded = loadPhotoQueue();
expect(loaded).toHaveLength(1);
expect(loaded[0]?.eventSlug).toBe('demo-event');
expect(loaded[0]?.photoId).toBe(12);
});
it('removes actions by id', () => {
const queue = enqueuePhotoAction({ eventSlug: 'demo-event', photoId: 12, action: 'approve' });
const next = removePhotoAction(queue, queue[0]!.id);
expect(next).toHaveLength(0);
expect(loadPhotoQueue()).toHaveLength(0);
});
it('replaces the queue', () => {
enqueuePhotoAction({ eventSlug: 'demo-event', photoId: 12, action: 'approve' });
const next: PhotoModerationAction[] = [
{
id: 'fixed',
eventSlug: 'another',
photoId: 99,
action: 'hide',
createdAt: new Date().toISOString(),
},
];
replacePhotoQueue(next);
expect(loadPhotoQueue()).toHaveLength(1);
expect(loadPhotoQueue()[0]?.id).toBe('fixed');
});
});

View File

@@ -0,0 +1,69 @@
export type PhotoModerationAction = {
id: string;
eventSlug: string;
photoId: number;
action: 'approve' | 'hide' | 'show' | 'feature' | 'unfeature';
createdAt: string;
};
const STORAGE_KEY = 'fotospiel-admin-photo-queue';
function buildId(): string {
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
return crypto.randomUUID();
}
return `${Date.now()}-${Math.random().toString(16).slice(2, 10)}`;
}
export function loadPhotoQueue(): PhotoModerationAction[] {
if (typeof window === 'undefined') {
return [];
}
try {
const raw = window.localStorage.getItem(STORAGE_KEY);
if (!raw) {
return [];
}
const parsed = JSON.parse(raw);
return Array.isArray(parsed) ? (parsed as PhotoModerationAction[]) : [];
} catch {
return [];
}
}
export function savePhotoQueue(queue: PhotoModerationAction[]): void {
if (typeof window === 'undefined') {
return;
}
try {
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(queue));
} catch {
// Ignore persistence failures.
}
}
export function enqueuePhotoAction(action: Omit<PhotoModerationAction, 'id' | 'createdAt'>): PhotoModerationAction[] {
const queue = loadPhotoQueue();
const entry: PhotoModerationAction = {
...action,
id: buildId(),
createdAt: new Date().toISOString(),
};
const next = [...queue, entry];
savePhotoQueue(next);
return next;
}
export function removePhotoAction(queue: PhotoModerationAction[], id: string): PhotoModerationAction[] {
const next = queue.filter((item) => item.id !== id);
savePhotoQueue(next);
return next;
}
export function replacePhotoQueue(queue: PhotoModerationAction[]): PhotoModerationAction[] {
savePhotoQueue(queue);
return queue;
}