feat: add telegram-style resource stream

This commit is contained in:
TerryM
2026-05-25 05:25:57 +08:00
parent aaebd7ccd1
commit a784f159fe
45 changed files with 3201 additions and 1160 deletions

View File

@@ -0,0 +1,30 @@
import { useEffect } from "react";
import { Navigate, useParams } from "react-router-dom";
import { MOCK_POSTS } from "../mocks/mockPosts";
import { POST_STREAM_USES_MOCK } from "../components/messageStream/hooks/usePostStream";
export function PostRedirect() {
const { id } = useParams();
// Real-API branch placeholder: when backend ships /api/posts/:id, fetch and
// navigate to /category/<categorySlug>#post-<id>. For now mock lookup.
const post = id ? MOCK_POSTS.find((p) => p.id === id) : undefined;
useEffect(() => {
if (post) {
requestAnimationFrame(() => {
document
.getElementById(`post-${post.id}`)
?.scrollIntoView({ behavior: "smooth", block: "center" });
});
}
}, [post]);
if (!POST_STREAM_USES_MOCK && !post) {
// TODO: replace with real fetch when /api/posts/:id ships.
return <Navigate to="/browse" replace />;
}
if (!post) return <Navigate to="/browse" replace />;
return (
<Navigate to={`/category/${post.categorySlug}#post-${post.id}`} replace />
);
}