mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-05-13 13:17:45 +00:00
fix: mii reviewedAt property for time select and responsiveness for sort menus
also bypassCache profile url query param
This commit is contained in:
parent
af37b05ab1
commit
2209a17687
5 changed files with 16 additions and 5 deletions
|
|
@ -0,0 +1,2 @@
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "miis" ADD COLUMN "reviewedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
@ -89,6 +89,7 @@ model Mii {
|
||||||
allowedCopying Boolean?
|
allowedCopying Boolean?
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
reviewedAt DateTime @default(now())
|
||||||
|
|
||||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
likeCount Int @default(0)
|
likeCount Int @default(0)
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ export async function GET(request: NextRequest) {
|
||||||
...(!quarantined && !userId && { quarantined: false }),
|
...(!quarantined && !userId && { quarantined: false }),
|
||||||
// Time range
|
// Time range
|
||||||
...(timeRange && {
|
...(timeRange && {
|
||||||
createdAt: {
|
reviewedAt: {
|
||||||
gte: new Date(Date.now() - { day: 86400000, week: 604800000, month: 2592000000, year: 31536000000 }[timeRange]),
|
gte: new Date(Date.now() - { day: 86400000, week: 604800000, month: 2592000000, year: 31536000000 }[timeRange]),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,10 @@ interface ApiResponse {
|
||||||
interface Props {
|
interface Props {
|
||||||
userId?: number;
|
userId?: number;
|
||||||
parentPage?: "likes";
|
parentPage?: "likes";
|
||||||
|
bypassCache?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function MiiList({ parentPage, userId }: Props) {
|
export default function MiiList({ parentPage, userId, bypassCache }: Props) {
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const [data, setData] = useState<ApiResponse | null>(null);
|
const [data, setData] = useState<ApiResponse | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
@ -34,6 +35,7 @@ export default function MiiList({ parentPage, userId }: Props) {
|
||||||
const params = new URLSearchParams(searchParams.toString());
|
const params = new URLSearchParams(searchParams.toString());
|
||||||
if (userId) params.append("userId", userId.toString());
|
if (userId) params.append("userId", userId.toString());
|
||||||
if (parentPage) params.append("parentPage", parentPage);
|
if (parentPage) params.append("parentPage", parentPage);
|
||||||
|
if (bypassCache) params.append("bypassCache", "true");
|
||||||
|
|
||||||
fetch(`${import.meta.env.VITE_API_URL}/api/mii/list?${params.toString()}`, { credentials: "include" })
|
fetch(`${import.meta.env.VITE_API_URL}/api/mii/list?${params.toString()}`, { credentials: "include" })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
|
@ -71,7 +73,7 @@ export default function MiiList({ parentPage, userId }: Props) {
|
||||||
<span className="text-lg text-amber-700">{data.totalCount === 1 ? "Mii" : "Miis"}</span>
|
<span className="text-lg text-amber-700">{data.totalCount === 1 ? "Mii" : "Miis"}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="relative flex items-center justify-end gap-2 w-full md:max-w-2/3 max-md:justify-center">
|
<div className="relative flex flex-wrap items-center justify-end gap-2 w-full md:max-w-2/3 max-md:justify-center">
|
||||||
<FilterMenu />
|
<FilterMenu />
|
||||||
<SortSelect />
|
<SortSelect />
|
||||||
<TimeRangeSelect />
|
<TimeRangeSelect />
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,14 @@
|
||||||
import { useParams } from "react-router";
|
import { useParams } from "react-router";
|
||||||
import MiiList from "../../components/mii/list";
|
import MiiList from "../../components/mii/list";
|
||||||
|
import { useStore } from "@nanostores/react";
|
||||||
|
import { session } from "../../session";
|
||||||
|
|
||||||
export default function ProfilePage() {
|
export default function ProfilePage() {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
const $session = useStore(session);
|
||||||
|
|
||||||
return <MiiList userId={Number(id)} />;
|
const userId = Number(id ?? $session?.user?.id);
|
||||||
|
const isOwnProfile = !!$session?.user?.id && userId === Number($session.user.id);
|
||||||
|
|
||||||
|
return <MiiList userId={Number(id)} bypassCache={isOwnProfile} />;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue