Improve guest help routing and loading
This commit is contained in:
32
resources/js/guest/lib/__tests__/helpRouting.test.ts
Normal file
32
resources/js/guest/lib/__tests__/helpRouting.test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { getHelpSlugForPathname } from '../helpRouting';
|
||||
|
||||
describe('getHelpSlugForPathname', () => {
|
||||
it('returns a getting-started slug for home paths', () => {
|
||||
expect(getHelpSlugForPathname('/')).toBe('getting-started');
|
||||
expect(getHelpSlugForPathname('/e/demo')).toBe('getting-started');
|
||||
});
|
||||
|
||||
it('returns null for help pages', () => {
|
||||
expect(getHelpSlugForPathname('/help')).toBeNull();
|
||||
expect(getHelpSlugForPathname('/help/gallery-and-sharing')).toBeNull();
|
||||
expect(getHelpSlugForPathname('/e/demo/help/gallery-and-sharing')).toBeNull();
|
||||
});
|
||||
|
||||
it('maps gallery related pages', () => {
|
||||
expect(getHelpSlugForPathname('/e/demo/gallery')).toBe('gallery-and-sharing');
|
||||
expect(getHelpSlugForPathname('/e/demo/photo/123')).toBe('gallery-and-sharing');
|
||||
expect(getHelpSlugForPathname('/e/demo/slideshow')).toBe('gallery-and-sharing');
|
||||
});
|
||||
|
||||
it('maps upload related pages', () => {
|
||||
expect(getHelpSlugForPathname('/e/demo/upload')).toBe('uploading-photos');
|
||||
expect(getHelpSlugForPathname('/e/demo/queue')).toBe('upload-troubleshooting');
|
||||
});
|
||||
|
||||
it('maps tasks and achievements', () => {
|
||||
expect(getHelpSlugForPathname('/e/demo/tasks')).toBe('tasks-and-missions');
|
||||
expect(getHelpSlugForPathname('/e/demo/tasks/12')).toBe('tasks-and-missions');
|
||||
expect(getHelpSlugForPathname('/e/demo/achievements')).toBe('achievements-and-badges');
|
||||
});
|
||||
});
|
||||
44
resources/js/guest/lib/helpRouting.ts
Normal file
44
resources/js/guest/lib/helpRouting.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
export function getHelpSlugForPathname(pathname: string): string | null {
|
||||
if (!pathname) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const normalized = pathname
|
||||
.replace(/^\/e\/[^/]+/, '')
|
||||
.replace(/\/+$/g, '')
|
||||
.toLowerCase();
|
||||
|
||||
if (!normalized || normalized === '/') {
|
||||
return 'getting-started';
|
||||
}
|
||||
|
||||
if (normalized.startsWith('/help')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (normalized.startsWith('/gallery') || normalized.startsWith('/photo') || normalized.startsWith('/slideshow')) {
|
||||
return 'gallery-and-sharing';
|
||||
}
|
||||
|
||||
if (normalized.startsWith('/upload')) {
|
||||
return 'uploading-photos';
|
||||
}
|
||||
|
||||
if (normalized.startsWith('/queue')) {
|
||||
return 'upload-troubleshooting';
|
||||
}
|
||||
|
||||
if (normalized.startsWith('/tasks')) {
|
||||
return 'tasks-and-missions';
|
||||
}
|
||||
|
||||
if (normalized.startsWith('/achievements')) {
|
||||
return 'achievements-and-badges';
|
||||
}
|
||||
|
||||
if (normalized.startsWith('/settings')) {
|
||||
return 'settings-and-cache';
|
||||
}
|
||||
|
||||
return 'how-fotospiel-works';
|
||||
}
|
||||
Reference in New Issue
Block a user