Skip to content
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

Merged
merged 14 commits into from
Nov 6, 2024
Merged

Ranking #26 #39

merged 14 commits into from
Nov 6, 2024

Conversation

K-Yoshizawa
Copy link
Contributor

#26 の機能を実装しました

Copy link
Member

@shun-shobon shun-shobon left a 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を使えば無限スクロールのためのページネーション機能も使えます。
  • 無限スクロールですが、スクロールさせる機能はなくても大丈夫です。

Copy link

cloudflare-workers-and-pages bot commented Oct 29, 2024

Deploying school-festival-2024 with  Cloudflare Pages  Cloudflare Pages

Latest commit: b221aee
Status: ✅  Deploy successful!
Preview URL: https://b6102ebe.school-festival-2024.pages.dev
Branch Preview URL: https://ranking--26.school-festival-2024.pages.dev

View logs

@K-Yoshizawa
Copy link
Contributor Author

@shun-shobon
恐らく修正が完了したので、再レビューをお願いします!

Comment on lines 18 to 22
const { data } = await supabase
.from("profiles_with_stats")
.select("*")
.order("rank", { ascending: true })
.range(start, end);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • プレイ回数が0のユーザーは順位が決まっていないため、フィルターする必要があります。
  • hasMoreの判別はデータの全数から判別すると良いです。
Suggested change
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);

Comment on lines 31 to 51
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]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

observerはrefにしなくても良さそうです!

Suggested change
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]);

@shun-shobon shun-shobon merged commit 316d085 into main Nov 6, 2024
4 checks passed
@shun-shobon shun-shobon deleted the ranking-#26 branch November 6, 2024 15:54
@shun-shobon shun-shobon mentioned this pull request Nov 6, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants