-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ranking #26 #39
Ranking #26 #39
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PRありがとうございます!以下の点の修正をお願いしたいです!
- mainのコードが古く、コンフリクトしているため、コンフリクトを修正してください。
useFetchRanking
ですが、useState
などのReact組み込みのものを使うより、データフェッチライブラリであるSWRが入ってるため、それを使ったほうが良さそうです。useProfile
などを参考にしてみてください。useSWRInfinite
を使えば無限スクロールのためのページネーション機能も使えます。- 無限スクロールですが、スクロールさせる機能はなくても大丈夫です。
Deploying school-festival-2024 with Cloudflare Pages
|
@shun-shobon |
app/hooks/useFetchRanking.ts
Outdated
const { data } = await supabase | ||
.from("profiles_with_stats") | ||
.select("*") | ||
.order("rank", { ascending: true }) | ||
.range(start, end); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- プレイ回数が0のユーザーは順位が決まっていないため、フィルターする必要があります。
- hasMoreの判別はデータの全数から判別すると良いです。
const { data } = await supabase | |
.from("profiles_with_stats") | |
.select("*") | |
.order("rank", { ascending: true }) | |
.range(start, end); | |
const { data, count } = await supabase | |
.from("profiles_with_stats") | |
.select("*", { count: "exact" }) | |
.not("rank", "is", null) | |
.order("rank", { ascending: true }) | |
.range(start, end); |
app/components/Ranking.tsx
Outdated
const observer = useRef<IntersectionObserver | null>(null); | ||
const loadMoreRef = useRef<HTMLDivElement | null>(null); | ||
|
||
useEffect(() => { | ||
if (isValidating || !loadMoreRef.current) return; | ||
|
||
const observerCallback = (entries: IntersectionObserverEntry[]) => { | ||
if (entries[0].isIntersecting && hasMore && !isValidating) { | ||
loadMore(); | ||
} | ||
}; | ||
|
||
observer.current = new IntersectionObserver(observerCallback); | ||
observer.current.observe(loadMoreRef.current); | ||
|
||
return () => { | ||
if (observer.current && loadMoreRef.current) { | ||
observer.current.unobserve(loadMoreRef.current); | ||
} | ||
}; | ||
}, [isValidating, loadMore, hasMore]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
observerはrefにしなくても良さそうです!
const observer = useRef<IntersectionObserver | null>(null); | |
const loadMoreRef = useRef<HTMLDivElement | null>(null); | |
useEffect(() => { | |
if (isValidating || !loadMoreRef.current) return; | |
const observerCallback = (entries: IntersectionObserverEntry[]) => { | |
if (entries[0].isIntersecting && hasMore && !isValidating) { | |
loadMore(); | |
} | |
}; | |
observer.current = new IntersectionObserver(observerCallback); | |
observer.current.observe(loadMoreRef.current); | |
return () => { | |
if (observer.current && loadMoreRef.current) { | |
observer.current.unobserve(loadMoreRef.current); | |
} | |
}; | |
}, [isValidating, loadMore, hasMore]); | |
const observer = useRef<IntersectionObserver | null>(null); | |
const loadMoreRef = useRef<HTMLDivElement | null>(null); | |
useEffect(() => { | |
if (isValidating || !loadMoreRef.current) return; | |
const observerCallback = (entries: IntersectionObserverEntry[]) => { | |
if (entries[0].isIntersecting && hasMore && !isValidating) { | |
loadMore(); | |
} | |
}; | |
observer.current = new IntersectionObserver(observerCallback); | |
observer.current.observe(loadMoreRef.current); | |
return () => { | |
if (observer.current && loadMoreRef.current) { | |
observer.current.unobserve(loadMoreRef.current); | |
} | |
}; | |
}, [isValidating, loadMore, hasMore]); |
…み込む機能 ランキング機能の作成 #26
3a55424
to
70ea198
Compare
#26 の機能を実装しました