terry-staging #16
@@ -150,7 +150,7 @@ export function PopularRankRow({
|
||||
type="button"
|
||||
onClick={() => {
|
||||
if (linkToResource) {
|
||||
navigate(lp(`/resource/${encodeURIComponent(post.id)}`));
|
||||
navigate(lp(`/resource/${encodeURIComponent(post.id)}?single=1`));
|
||||
return;
|
||||
}
|
||||
const params = new URLSearchParams();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
|
||||
import { getJSON } from "../../api";
|
||||
import { langQuery, useI18n, type Lang } from "../../i18n";
|
||||
import { useLocalizedPath } from "../../useLocalizedPath";
|
||||
@@ -25,6 +25,8 @@ function postLangToUiLang(code: string | undefined): Lang | null {
|
||||
|
||||
export function PostRedirect() {
|
||||
const { id } = useParams();
|
||||
const [sp] = useSearchParams();
|
||||
const singleMode = sp.get("single") === "1";
|
||||
const { lang, t } = useI18n();
|
||||
const navigate = useNavigate();
|
||||
const lp = useLocalizedPath();
|
||||
@@ -41,18 +43,25 @@ export function PostRedirect() {
|
||||
|
||||
if (POST_STREAM_USES_MOCK) {
|
||||
const post = MOCK_POSTS.find((p) => p.id === id);
|
||||
const suffix = singleMode ? "&single=1" : "";
|
||||
navigate(
|
||||
lp(post ? `/browse?post=${encodeURIComponent(post.id)}` : "/browse"),
|
||||
{
|
||||
replace: true,
|
||||
},
|
||||
lp(
|
||||
post
|
||||
? `/browse?post=${encodeURIComponent(post.id)}${suffix}`
|
||||
: "/browse",
|
||||
),
|
||||
{ replace: true },
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const goToPostInLang = (post: Post, targetLang: Lang) => {
|
||||
const suffix = singleMode ? "&single=1" : "";
|
||||
navigate(
|
||||
localizePath(`/browse?post=${encodeURIComponent(post.id)}`, targetLang),
|
||||
localizePath(
|
||||
`/browse?post=${encodeURIComponent(post.id)}${suffix}`,
|
||||
targetLang,
|
||||
),
|
||||
{ replace: true },
|
||||
);
|
||||
};
|
||||
@@ -73,7 +82,7 @@ export function PostRedirect() {
|
||||
})
|
||||
.catch(() => navigate(lp("/browse"), { replace: true }));
|
||||
});
|
||||
}, [id, lang, navigate, lp, showToast, t]);
|
||||
}, [id, lang, navigate, lp, showToast, singleMode, t]);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user