From 78bdf731431f31631c5e393591d7282dbe095186 Mon Sep 17 00:00:00 2001 From: TerryM Date: Tue, 26 May 2026 14:07:10 +0800 Subject: [PATCH] feat: enable real posts api by default --- .env.example | 6 +- README.md | 2 +- src/api.test.ts | 1 + .../bubbles/ImageWithTextBubble.tsx | 12 +-- .../messageStream/bubbles/VideoBubble.tsx | 78 ++++++++++++++----- .../messageStream/hooks/usePostStream.ts | 2 +- 6 files changed, 70 insertions(+), 31 deletions(-) diff --git a/.env.example b/.env.example index edc496c..18592e9 100644 --- a/.env.example +++ b/.env.example @@ -13,6 +13,6 @@ VITE_ADMIN_ONLY=false # Optional admin UI base path. Leave empty to use default app behavior. VITE_ADMIN_UI_PREFIX= -# Use mock Post data (Telegram-style resource stream) while backend /api/posts -# endpoints are not yet ready. Set to "false" to hit real API. -VITE_USE_MOCK_POSTS=true +# Use mock Post data (Telegram-style resource stream) only when explicitly enabled. +# Default production/staging behavior should hit the real /api/posts API. +VITE_USE_MOCK_POSTS=false diff --git a/README.md b/README.md index 2eee7a4..d5080a1 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Create a local `.env` only when needed. Do not commit secrets. See `.env.example | `VITE_DISABLE_ADMIN` | When set to `"true"`, public build redirects admin routes away. Production public deploy sets this to `"true"`. | | `VITE_ADMIN_ONLY` | When set to `"true"`, builds the admin-only app entry instead of the public app. | | `VITE_ADMIN_UI_PREFIX` | Optional admin UI base path. If absent in admin-only mode, code uses the secret prefix from `src/adminPaths.ts`. | -| `VITE_USE_MOCK_POSTS` | Telegram-style resource stream (`/browse`, `/category/:slug`) uses mock posts from `src/mocks/mockPosts.ts` when set to `true` (default while backend `/api/posts` is not yet shipped). Set to `"false"` to hit the real API. See `.unipi/docs/specs/2026-05-25-posts-api-contract.md`. | +| `VITE_USE_MOCK_POSTS` | Telegram-style resource stream (`/browse`, `/category/:slug`) uses mock posts from `src/mocks/mockPosts.ts` only when set to `"true"`. Leave unset or set to `"false"` to hit the real `/api/posts` API. See `.unipi/docs/specs/2026-05-25-posts-api-contract.md`. | ## Project layout diff --git a/src/api.test.ts b/src/api.test.ts index 5a32909..fbac350 100644 --- a/src/api.test.ts +++ b/src/api.test.ts @@ -3,6 +3,7 @@ import { describe, expect, it, vi } from "vitest"; async function loadApi(apiUrl = "") { vi.resetModules(); vi.stubEnv("VITE_API_URL", apiUrl); + vi.stubEnv("VITE_API_PREFIX", ""); return import("./api"); } diff --git a/src/components/messageStream/bubbles/ImageWithTextBubble.tsx b/src/components/messageStream/bubbles/ImageWithTextBubble.tsx index ba42481..62e45d2 100644 --- a/src/components/messageStream/bubbles/ImageWithTextBubble.tsx +++ b/src/components/messageStream/bubbles/ImageWithTextBubble.tsx @@ -14,24 +14,26 @@ export function ImageWithTextBubble({ post }: { post: Post }) { att.width && att.height ? `${att.width} / ${att.height}` : "4 / 3"; return ( -
+
{text ? ( -
- {autolink(text)} +
+
+ {autolink(text)} +
) : null}
diff --git a/src/components/messageStream/bubbles/VideoBubble.tsx b/src/components/messageStream/bubbles/VideoBubble.tsx index 5a00e74..5b2fcb5 100644 --- a/src/components/messageStream/bubbles/VideoBubble.tsx +++ b/src/components/messageStream/bubbles/VideoBubble.tsx @@ -1,5 +1,6 @@ -import { Play } from "lucide-react"; +import { Download, Play } from "lucide-react"; import { useRef, useState } from "react"; +import { postNoBody } from "../../../api"; import { useI18n } from "../../../i18n"; import type { Post } from "../../../types/post"; import { useVideoPlayer } from "../overlays/VideoPlayer"; @@ -24,6 +25,8 @@ export function VideoBubble({ post }: { post: Post }) { if (!att) return null; const ratio = att.width && att.height ? `${att.width} / ${att.height}` : "16 / 9"; + const posterUrl = att.posterUrl ?? att.thumbnailUrl; + const previewVideoUrl = att.url.includes("#") ? att.url : `${att.url}#t=0.1`; return (
@@ -48,31 +51,64 @@ export function VideoBubble({ post }: { post: Post }) { className="absolute inset-0 h-full w-full" /> ) : ( - + + )}
{text ? ( diff --git a/src/components/messageStream/hooks/usePostStream.ts b/src/components/messageStream/hooks/usePostStream.ts index 321209a..b85d05f 100644 --- a/src/components/messageStream/hooks/usePostStream.ts +++ b/src/components/messageStream/hooks/usePostStream.ts @@ -8,7 +8,7 @@ import type { Post, PostListResponse, PostScope } from "../../../types/post"; const PAGE_SIZE = 20; const MOCK_DELAY_MS = 200; -const USE_MOCK = import.meta.env.VITE_USE_MOCK_POSTS !== "false"; +const USE_MOCK = import.meta.env.VITE_USE_MOCK_POSTS === "true"; export type PostStreamParams = { scope: PostScope;