fix: align official recommendations behavior
All checks were successful
Deploy to Frontend Servers / deploy (push) Successful in 47s
All checks were successful
Deploy to Frontend Servers / deploy (push) Successful in 47s
This commit is contained in:
@@ -27,11 +27,11 @@ export function LatestUpdateRow({
|
|||||||
className="h-10 w-10 text-ark-gold"
|
className="h-10 w-10 text-ark-gold"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="min-w-0 flex-1 py-0.5">
|
<div className="flex min-w-0 flex-1 self-stretch py-0.5 flex-col">
|
||||||
<div className="text-base font-bold leading-snug text-white line-clamp-2 md:text-lg">
|
<div className="text-base font-bold leading-snug text-white line-clamp-2 md:text-lg">
|
||||||
{r.title}
|
{r.title}
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-4 grid gap-1 text-sm text-[#9b9ca6] md:mt-6">
|
<div className="mt-auto grid gap-1 text-sm text-[#9b9ca6]">
|
||||||
<span>{r.categoryName}</span>
|
<span>{r.categoryName}</span>
|
||||||
<span>
|
<span>
|
||||||
{resourceTypeLabel(t, r.type)}
|
{resourceTypeLabel(t, r.type)}
|
||||||
@@ -58,11 +58,11 @@ export function ComingSoonLatestUpdateRow({ index = 0 }: { index?: number }) {
|
|||||||
<div className="flex shrink-0 items-center justify-center pt-0.5">
|
<div className="flex shrink-0 items-center justify-center pt-0.5">
|
||||||
<CategoryIcon iconKey={iconKey} className="h-10 w-10 text-ark-gold" />
|
<CategoryIcon iconKey={iconKey} className="h-10 w-10 text-ark-gold" />
|
||||||
</div>
|
</div>
|
||||||
<div className="min-w-0 flex-1 py-0.5">
|
<div className="flex min-w-0 flex-1 self-stretch py-0.5 flex-col">
|
||||||
<div className="text-base font-bold leading-snug text-white line-clamp-2 md:text-lg">
|
<div className="text-base font-bold leading-snug text-white line-clamp-2 md:text-lg">
|
||||||
即将到来
|
即将到来
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-4 grid gap-1 text-sm text-[#9b9ca6] md:mt-6">
|
<div className="mt-auto grid gap-1 text-sm text-[#9b9ca6]">
|
||||||
<span>更多内容准备中</span>
|
<span>更多内容准备中</span>
|
||||||
<span>Coming soon</span>
|
<span>Coming soon</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -79,13 +79,13 @@ export function PublicLayout() {
|
|||||||
<header className="sticky top-0 z-40 border-b border-ark-line bg-ark-nav/98 backdrop-blur-md">
|
<header className="sticky top-0 z-40 border-b border-ark-line bg-ark-nav/98 backdrop-blur-md">
|
||||||
<div className="mx-auto max-w-[1280px] px-4 py-[15px] min-[440px]:px-5 sm:px-6 md:px-9 xl:px-0">
|
<div className="mx-auto max-w-[1280px] px-4 py-[15px] min-[440px]:px-5 sm:px-6 md:px-9 xl:px-0">
|
||||||
{/* Single row (md+): logo | scrollable nav (左對齊,可橫向滑動) | 搜尋 + 語言 */}
|
{/* Single row (md+): logo | scrollable nav (左對齊,可橫向滑動) | 搜尋 + 語言 */}
|
||||||
<div className="flex h-10 items-center gap-2 lg:gap-4">
|
<div className="flex h-10 items-center gap-2 min-[1200px]:gap-0 lg:gap-4">
|
||||||
<Link
|
<Link
|
||||||
to="/"
|
to="/"
|
||||||
className="flex min-w-0 shrink-0 items-center gap-2.5 rounded-sm text-xl font-bold tracking-wide text-ark-gold outline-none focus-visible:ring-2 focus-visible:ring-ark-gold/80 focus-visible:ring-offset-2 focus-visible:ring-offset-ark-bg"
|
className="flex min-w-0 shrink-0 items-center gap-2.5 rounded-sm text-xl font-bold tracking-wide text-ark-gold outline-none focus-visible:ring-2 focus-visible:ring-ark-gold/80 focus-visible:ring-offset-2 focus-visible:ring-offset-ark-bg"
|
||||||
>
|
>
|
||||||
<ArkLogoMark className="h-10 w-10 shrink-0" />
|
<ArkLogoMark className="h-10 w-10 shrink-0" />
|
||||||
<span className="max-w-[7.125rem] truncate text-ark-gold sm:inline">
|
<span className="max-w-[8rem] truncate text-ark-gold sm:inline">
|
||||||
{t("brand")}
|
{t("brand")}
|
||||||
</span>
|
</span>
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -53,13 +53,40 @@ export function Browse() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setErr(null);
|
setErr(null);
|
||||||
|
|
||||||
|
if (sort === "recommended") {
|
||||||
|
const p = new URLSearchParams();
|
||||||
|
p.set("lang", lang);
|
||||||
|
p.set("limit", "100");
|
||||||
|
|
||||||
|
getJSON<{ items: Resource[] }>(`/api/resources/recommended?${p}`)
|
||||||
|
.then((r) => {
|
||||||
|
const tagLower = tag.toLowerCase();
|
||||||
|
const officialItems = itemsOrEmpty(r.items)
|
||||||
|
.filter((item) => item.isRecommended)
|
||||||
|
.filter((item) => type === "all" || item.type === type)
|
||||||
|
.filter((item) => !resourceLang || item.language === resourceLang)
|
||||||
|
.filter(
|
||||||
|
(item) =>
|
||||||
|
!tagLower ||
|
||||||
|
item.tags?.some(
|
||||||
|
(itemTag) => itemTag.toLowerCase() === tagLower,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
setTotal(officialItems.length);
|
||||||
|
setItems(officialItems.slice((page - 1) * limit, page * limit));
|
||||||
|
})
|
||||||
|
.catch((e) => setErr(String(e)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
getJSON<{ items: Resource[]; total?: number }>(`/api/resources?${query}`)
|
getJSON<{ items: Resource[]; total?: number }>(`/api/resources?${query}`)
|
||||||
.then((r) => {
|
.then((r) => {
|
||||||
setItems(itemsOrEmpty(r.items));
|
setItems(itemsOrEmpty(r.items));
|
||||||
setTotal(typeof r.total === "number" ? r.total : 0);
|
setTotal(typeof r.total === "number" ? r.total : 0);
|
||||||
})
|
})
|
||||||
.catch((e) => setErr(String(e)));
|
.catch((e) => setErr(String(e)));
|
||||||
}, [query]);
|
}, [lang, limit, page, query, resourceLang, sort, tag, type]);
|
||||||
|
|
||||||
const setPage = (next: number) => {
|
const setPage = (next: number) => {
|
||||||
const n = new URLSearchParams(sp);
|
const n = new URLSearchParams(sp);
|
||||||
|
|||||||
@@ -8,10 +8,7 @@ import {
|
|||||||
ComingSoonLatestUpdateRow,
|
ComingSoonLatestUpdateRow,
|
||||||
LatestUpdateRow,
|
LatestUpdateRow,
|
||||||
} from "../components/LatestUpdateRow";
|
} from "../components/LatestUpdateRow";
|
||||||
import {
|
import { RecommendedCard } from "../components/RecommendedCard";
|
||||||
ComingSoonRecommendedCard,
|
|
||||||
RecommendedCard,
|
|
||||||
} from "../components/RecommendedCard";
|
|
||||||
import { SectionHeader } from "../components/SectionHeader";
|
import { SectionHeader } from "../components/SectionHeader";
|
||||||
import { useI18n } from "../i18n";
|
import { useI18n } from "../i18n";
|
||||||
import { categoryCardLines } from "../utils/categoryDisplay";
|
import { categoryCardLines } from "../utils/categoryDisplay";
|
||||||
@@ -23,6 +20,7 @@ export function Home() {
|
|||||||
const [latest, setLatest] = useState<Resource[]>([]);
|
const [latest, setLatest] = useState<Resource[]>([]);
|
||||||
const [err, setErr] = useState<string | null>(null);
|
const [err, setErr] = useState<string | null>(null);
|
||||||
const recRowRef = useRef<HTMLDivElement>(null);
|
const recRowRef = useRef<HTMLDivElement>(null);
|
||||||
|
const [canScrollRec, setCanScrollRec] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const q = `?lang=${encodeURIComponent(lang)}`;
|
const q = `?lang=${encodeURIComponent(lang)}`;
|
||||||
@@ -42,11 +40,27 @@ export function Home() {
|
|||||||
const iconKeyForResource = (r: Resource) =>
|
const iconKeyForResource = (r: Resource) =>
|
||||||
cats.find((c) => c.id === r.categoryId)?.iconKey ?? "folder";
|
cats.find((c) => c.id === r.categoryId)?.iconKey ?? "folder";
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const row = recRowRef.current;
|
||||||
|
if (!row) {
|
||||||
|
setCanScrollRec(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateCanScroll = () => {
|
||||||
|
setCanScrollRec(row.scrollWidth > row.clientWidth + 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
updateCanScroll();
|
||||||
|
const resizeObserver = new ResizeObserver(updateCanScroll);
|
||||||
|
resizeObserver.observe(row);
|
||||||
|
return () => resizeObserver.disconnect();
|
||||||
|
}, [rec.length]);
|
||||||
|
|
||||||
const scrollRec = (dir: 1 | -1) => {
|
const scrollRec = (dir: 1 | -1) => {
|
||||||
recRowRef.current?.scrollBy({ left: dir * 280, behavior: "smooth" });
|
recRowRef.current?.scrollBy({ left: dir * 280, behavior: "smooth" });
|
||||||
};
|
};
|
||||||
|
|
||||||
const recommendedPlaceholderCount = Math.max(0, 5 - rec.length);
|
|
||||||
const latestPlaceholderCount = Math.max(0, 5 - latest.length);
|
const latestPlaceholderCount = Math.max(0, 5 - latest.length);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -115,20 +129,11 @@ export function Home() {
|
|||||||
<RecommendedCard r={r} visualIndex={index} />
|
<RecommendedCard r={r} visualIndex={index} />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
{Array.from({ length: recommendedPlaceholderCount }).map(
|
|
||||||
(_, index) => (
|
|
||||||
<div
|
|
||||||
key={`recommended-coming-soon-${index}`}
|
|
||||||
className="snap-start"
|
|
||||||
>
|
|
||||||
<ComingSoonRecommendedCard visualIndex={rec.length + index} />
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
<div className="h-1 rounded-full bg-black/80 md:hidden">
|
<div className="h-1 rounded-full bg-black/80 md:hidden">
|
||||||
<div className="h-full w-24 rounded-full bg-[#353740]" />
|
<div className="h-full w-24 rounded-full bg-[#353740]" />
|
||||||
</div>
|
</div>
|
||||||
|
{canScrollRec ? (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => scrollRec(1)}
|
onClick={() => scrollRec(1)}
|
||||||
@@ -137,6 +142,7 @@ export function Home() {
|
|||||||
>
|
>
|
||||||
<ChevronRight className="h-5 w-5" />
|
<ChevronRight className="h-5 w-5" />
|
||||||
</button>
|
</button>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig, loadEnv } from "vite";
|
||||||
import react from "@vitejs/plugin-react";
|
import react from "@vitejs/plugin-react";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
|
const env = loadEnv(mode, process.cwd(), "");
|
||||||
|
const apiProxyTarget = env.DEV_API_PROXY_TARGET || "http://127.0.0.1:8080";
|
||||||
|
|
||||||
|
return {
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
build: {
|
build: {
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
@@ -16,8 +20,9 @@ export default defineConfig({
|
|||||||
server: {
|
server: {
|
||||||
port: 5173,
|
port: 5173,
|
||||||
proxy: {
|
proxy: {
|
||||||
"/api": { target: "http://127.0.0.1:8080", changeOrigin: true },
|
"/api": { target: apiProxyTarget, changeOrigin: true },
|
||||||
"/uploads": { target: "http://127.0.0.1:8080", changeOrigin: true },
|
"/uploads": { target: apiProxyTarget, changeOrigin: true },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user