feat: Instagram-shaped URLs, Instagram-shaped gestures, iOS-feel animations
Docker Build and Publish / build-and-push (push) Failing after 10s
Docker Build and Publish / build-and-push (push) Failing after 10s
Navigation gestures Horizontal swipe used to advance the carousel and then, on the last slide, fling you into the next post — one gesture meaning two things. Horizontal is now carousel-only. On touch, vertical swipe moves between posts (down on the first post still dismisses, keeping drag-to-close where it can't mean "previous"). Desktop keeps the arrows outside the modal. URLs Permalinks now mirror Instagram: /<archive>/ profile /<archive>/reels/ tab /<archive>/p/<shortcode>/ post A post URL carries no tab, as on Instagram; the tab is re-derived from the post's source, so opening a reel link lands on the Reels tab with next/prev paging through reels. Sidecar posts keep directory-scoped ids internally but expose only the shortcode. The old ?a=&t=&p= form is still parsed so existing links keep working, and reserved prefixes (api, archives, assets…) can never be mistaken for a profile name. Animations Adds a shared motion vocabulary tuned to feel native: critically damped springs rather than fixed-duration easing, and gestures hand their exit velocity to the animation so a flick continues instead of restarting. Post transitions animate along the axis the input implies — vertical for a swipe, horizontal for the arrows. Modal and story viewer present/dismiss with a scale, tiles and highlight circles get touch-down feedback, and prefers-reduced-motion is honoured throughout. Adds 22 routing tests (58 total). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011uBWhwV3wFQ5MBCcMHHem7
This commit is contained in:
co-authored by
Claude Opus 5
parent
0cff91edae
commit
877d21ff1f
@@ -0,0 +1,44 @@
|
||||
import type { Transition } from 'motion/react';
|
||||
|
||||
/**
|
||||
* Shared motion vocabulary, tuned to feel like a native iOS app.
|
||||
*
|
||||
* Two rules do most of the work:
|
||||
* - UIKit animates with springs, not fixed-duration easing, so gestures hand
|
||||
* their exit velocity to the animation and motion continues rather than
|
||||
* restarting.
|
||||
* - iOS springs are critically damped. They settle firmly with no visible
|
||||
* bounce; overshoot reads as "web animation", not "native".
|
||||
*/
|
||||
|
||||
/** The curve UIKit uses for sheet presentation. */
|
||||
export const IOS_EASE = [0.32, 0.72, 0, 1] as const;
|
||||
|
||||
/** Moving between peers: carousel slides, next/previous post. */
|
||||
export const NAVIGATE: Transition = { type: 'spring', stiffness: 420, damping: 40, mass: 1 };
|
||||
|
||||
/** Presenting or dismissing a surface. Slightly softer than navigation. */
|
||||
export const PRESENT: Transition = { type: 'spring', stiffness: 320, damping: 34, mass: 1 };
|
||||
|
||||
/** Backdrops and cross-fades, where a spring would feel fussy. */
|
||||
export const FADE: Transition = { duration: 0.28, ease: IOS_EASE };
|
||||
|
||||
/** Touch-down feedback. Fast enough to feel like a direct response. */
|
||||
export const PRESS: Transition = { type: 'spring', stiffness: 600, damping: 30 };
|
||||
|
||||
/**
|
||||
* Continue a drag into its animation.
|
||||
*
|
||||
* Handing the gesture's exit velocity to the spring is what separates "the
|
||||
* sheet kept moving because I flicked it" from "the sheet started a new
|
||||
* animation once I let go".
|
||||
*/
|
||||
export const withVelocity = (velocity: number, base: Transition = NAVIGATE): Transition => ({
|
||||
...base,
|
||||
velocity,
|
||||
});
|
||||
|
||||
/** True when the viewer has asked the OS to reduce motion. */
|
||||
export const prefersReducedMotion = () =>
|
||||
typeof window !== 'undefined' &&
|
||||
window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
@@ -0,0 +1,114 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { buildPath, findPostBySlug, parseRoute, postSlug, tabForSource } from './routing';
|
||||
import { Post } from '../types';
|
||||
|
||||
const post = (id: string, source?: Post['source']): Post => ({
|
||||
id, date: '2024-01-01', username: 'u', caption: '', media: [], thumbnail: '', source,
|
||||
});
|
||||
|
||||
describe('parseRoute', () => {
|
||||
it('reads the explorer root', () => {
|
||||
expect(parseRoute('/')).toEqual({ archive: null, tab: 'posts', post: null });
|
||||
});
|
||||
|
||||
it('reads a profile', () => {
|
||||
expect(parseRoute('/4utumn07/')).toEqual({ archive: '4utumn07', tab: 'posts', post: null });
|
||||
});
|
||||
|
||||
it('reads a profile without a trailing slash', () => {
|
||||
expect(parseRoute('/4utumn07')).toEqual({ archive: '4utumn07', tab: 'posts', post: null });
|
||||
});
|
||||
|
||||
it('reads a tab', () => {
|
||||
expect(parseRoute('/4utumn07/reels/').tab).toBe('reels');
|
||||
expect(parseRoute('/4utumn07/saved/').tab).toBe('saved');
|
||||
});
|
||||
|
||||
it('reads a post in Instagram form', () => {
|
||||
expect(parseRoute('/4utumn07/p/Db5tIoRCcvm/')).toEqual({
|
||||
archive: '4utumn07', tab: 'posts', post: 'Db5tIoRCcvm',
|
||||
});
|
||||
});
|
||||
|
||||
it('decodes archive names containing spaces', () => {
|
||||
expect(parseRoute('/Heejin_Bubble%20heejinmedia/').archive).toBe('Heejin_Bubble heejinmedia');
|
||||
});
|
||||
|
||||
it('does not treat reserved prefixes as archives', () => {
|
||||
for (const path of ['/api/archives', '/archives/x/y.jpg', '/assets/index.js']) {
|
||||
expect(parseRoute(path).archive).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('still understands the legacy query form', () => {
|
||||
expect(parseRoute('/', '?a=4utumn07&t=reels&p=ABC')).toEqual({
|
||||
archive: '4utumn07', tab: 'reels', post: 'ABC',
|
||||
});
|
||||
});
|
||||
|
||||
it('ignores an unknown tab', () => {
|
||||
expect(parseRoute('/', '?a=u&t=bogus').tab).toBe('posts');
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildPath', () => {
|
||||
it.each([
|
||||
[{ archive: null, tab: 'posts', post: null }, '/'],
|
||||
[{ archive: '4utumn07', tab: 'posts', post: null }, '/4utumn07/'],
|
||||
[{ archive: '4utumn07', tab: 'reels', post: null }, '/4utumn07/reels/'],
|
||||
[{ archive: '4utumn07', tab: 'posts', post: 'Db5tIoRCcvm' }, '/4utumn07/p/Db5tIoRCcvm/'],
|
||||
] as const)('builds %j', (route, expected) => {
|
||||
expect(buildPath(route as any)).toBe(expected);
|
||||
});
|
||||
|
||||
it('omits the tab from a post URL, matching Instagram', () => {
|
||||
expect(buildPath({ archive: 'u', tab: 'reels', post: 'ABC' })).toBe('/u/p/ABC/');
|
||||
});
|
||||
|
||||
it('encodes archive names with spaces', () => {
|
||||
expect(buildPath({ archive: 'a b', tab: 'posts', post: null })).toBe('/a%20b/');
|
||||
});
|
||||
|
||||
it('round-trips through parseRoute', () => {
|
||||
for (const route of [
|
||||
{ archive: '4utumn07', tab: 'posts' as const, post: null },
|
||||
{ archive: '4utumn07', tab: 'reels' as const, post: null },
|
||||
{ archive: 'Heejin_Bubble heejinmedia', tab: 'posts' as const, post: null },
|
||||
]) {
|
||||
expect(parseRoute(buildPath(route))).toEqual(route);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('postSlug / findPostBySlug', () => {
|
||||
it('uses the bare shortcode for base posts', () => {
|
||||
expect(postSlug(post('Db5tIoRCcvm'))).toBe('Db5tIoRCcvm');
|
||||
});
|
||||
|
||||
it('strips the sidecar directory from the slug', () => {
|
||||
expect(postSlug(post('story highlights - u - Sunstory/C5dQPEYpd9W'))).toBe('C5dQPEYpd9W');
|
||||
});
|
||||
|
||||
it('resolves a slug back to its post', () => {
|
||||
const posts = [post('AAA'), post('4utumn07 - reels/BBB', 'reels')];
|
||||
expect(findPostBySlug(posts, 'BBB')?.id).toBe('4utumn07 - reels/BBB');
|
||||
expect(findPostBySlug(posts, 'AAA')?.id).toBe('AAA');
|
||||
});
|
||||
|
||||
it('prefers an exact id match over a shortcode match', () => {
|
||||
const posts = [post('x/ABC'), post('ABC')];
|
||||
expect(findPostBySlug(posts, 'ABC')?.id).toBe('ABC');
|
||||
});
|
||||
|
||||
it('returns undefined for an unknown slug', () => {
|
||||
expect(findPostBySlug([post('AAA')], 'ZZZ')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('tabForSource', () => {
|
||||
it('sends reels to the reels tab and everything else to posts', () => {
|
||||
expect(tabForSource('reels')).toBe('reels');
|
||||
expect(tabForSource('posts')).toBe('posts');
|
||||
expect(tabForSource(undefined)).toBe('posts');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,85 @@
|
||||
import { Post, SourceKind } from '../types';
|
||||
|
||||
/**
|
||||
* Instagram-shaped paths.
|
||||
*
|
||||
* / the archive explorer
|
||||
* /<archive>/ a profile, posts tab
|
||||
* /<archive>/reels/ a profile, reels tab
|
||||
* /<archive>/saved/
|
||||
* /<archive>/p/<shortcode>/ a single post
|
||||
*
|
||||
* The older `?a=&t=&p=` query form is still parsed so existing links keep
|
||||
* working; it is never written back.
|
||||
*/
|
||||
|
||||
export type Tab = 'posts' | 'reels' | 'saved';
|
||||
|
||||
const TABS: Tab[] = ['posts', 'reels', 'saved'];
|
||||
|
||||
/**
|
||||
* Path prefixes the app must never treat as an archive name, or a profile
|
||||
* called "api" would shadow the backend.
|
||||
*/
|
||||
const RESERVED = new Set(['api', 'archives', 'assets', 'p', 'fonts', 'sw.js', 'manifest.webmanifest']);
|
||||
|
||||
export interface Route {
|
||||
archive: string | null;
|
||||
tab: Tab;
|
||||
/** Post shortcode, i.e. the trailing segment of a post id. */
|
||||
post: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A post's URL slug.
|
||||
*
|
||||
* Sidecar posts carry a directory-scoped id (`story highlights - u - H/ABC`)
|
||||
* so ids stay unique across sources, but only the shortcode belongs in a URL.
|
||||
*/
|
||||
export const postSlug = (post: Pick<Post, 'id'>): string => {
|
||||
const tail = post.id.split('/').pop() ?? post.id;
|
||||
return encodeURIComponent(tail);
|
||||
};
|
||||
|
||||
/** Find the post a slug refers to, preferring an exact id match. */
|
||||
export const findPostBySlug = (posts: Post[], slug: string): Post | undefined => {
|
||||
const decoded = decodeURIComponent(slug);
|
||||
return posts.find(p => p.id === decoded)
|
||||
?? posts.find(p => (p.id.split('/').pop() ?? p.id) === decoded);
|
||||
};
|
||||
|
||||
/** Which tab shows a given post, so a deep link lands on the right one. */
|
||||
export const tabForSource = (source?: SourceKind): Tab => (source === 'reels' ? 'reels' : 'posts');
|
||||
|
||||
export const parseRoute = (pathname: string, search = ''): Route => {
|
||||
const segments = pathname.split('/').filter(Boolean).map(decodeURIComponent);
|
||||
|
||||
if (segments.length && !RESERVED.has(segments[0])) {
|
||||
const [archive, second, third] = segments;
|
||||
|
||||
if (second === 'p' && third) return { archive, tab: 'posts', post: third };
|
||||
if (second && TABS.includes(second as Tab)) return { archive, tab: second as Tab, post: null };
|
||||
return { archive, tab: 'posts', post: null };
|
||||
}
|
||||
|
||||
// Legacy query form: ?a=<archive>&t=<tab>&p=<post id>
|
||||
const params = new URLSearchParams(search);
|
||||
const archive = params.get('a');
|
||||
const tab = params.get('t');
|
||||
return {
|
||||
archive: archive || null,
|
||||
tab: tab && TABS.includes(tab as Tab) ? (tab as Tab) : 'posts',
|
||||
post: params.get('p'),
|
||||
};
|
||||
};
|
||||
|
||||
export const buildPath = ({ archive, tab, post }: Route): string => {
|
||||
if (!archive) return '/';
|
||||
|
||||
const base = `/${encodeURIComponent(archive)}`;
|
||||
// A post URL omits the tab, matching Instagram; the tab is re-derived from
|
||||
// the post itself when the link is opened.
|
||||
if (post) return `${base}/p/${post}/`;
|
||||
if (tab !== 'posts') return `${base}/${tab}/`;
|
||||
return `${base}/`;
|
||||
};
|
||||
Reference in New Issue
Block a user