Skip to content

fix:回答後にポイントが即時反映されるように修正 - #28

Merged
Yuji181181 merged 4 commits into
mainfrom
fix/show-point
Oct 19, 2025
Merged

fix:回答後にポイントが即時反映されるように修正#28
Yuji181181 merged 4 commits into
mainfrom
fix/show-point

Conversation

@Yuji181181

Copy link
Copy Markdown
Owner

No description provided.

@Yuji181181
Yuji181181 requested a review from Copilot October 19, 2025 08:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements immediate point reflection after answering surveys by adding a refresh mechanism to the dashboard. The changes ensure that when users complete a survey and earn points, those points are immediately displayed without requiring a manual page refresh.

Key changes:

  • Added a new PointDisplay component that can refresh user points on demand
  • Implemented URL parameter-based refresh triggering for both surveys and points data
  • Created a new API endpoint to fetch current user points

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/schemas/api/users.ts Added schema for user points API response
src/hooks/domain/(authenticated)/survey/[id]/answer/useSurveyAnswerPage.ts Modified redirect to include refresh parameter
src/hooks/domain/(authenticated)/dashboard/useDashboardPage.ts Added refresh logic based on URL parameters
src/components/common/PointDisplay.tsx New component for displaying user points with refresh capability
src/components/common/Header.tsx Replaced inline point display with new PointDisplay component
src/app/api/points/route.ts New API endpoint for fetching user points
src/app/api/(Repository)/point.ts Added getUserPoints function for database queries

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

// URLパラメータをクリーンアップ
useEffect(() => {
if (shouldRefresh === "true") {
window.history.replaceState({}, "", "/dashboard");

Copilot AI Oct 19, 2025

Copy link

Choose a reason for hiding this comment

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

Using window.history.replaceState directly in React can cause issues with client-side routing. Consider using Next.js router's replace method instead for better compatibility with the framework's routing system.

Copilot uses AI. Check for mistakes.
Comment thread src/components/common/PointDisplay.tsx Outdated
Comment on lines +28 to +31
const { data } = useCustomizedSWR(swrKey, userPointsSchema);

const points = data?.currentPoints ?? initialPoints;

Copilot AI Oct 19, 2025

Copy link

Choose a reason for hiding this comment

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

The SWR hook should handle loading and error states. Consider destructuring isLoading and error to provide better user experience during point fetching or when errors occur.

Suggested change
const { data } = useCustomizedSWR(swrKey, userPointsSchema);
const points = data?.currentPoints ?? initialPoints;
const { data, isLoading, error } = useCustomizedSWR(swrKey, userPointsSchema);
const points = data?.currentPoints ?? initialPoints;
if (isLoading) {
return (
<div className="flex items-center gap-2 rounded-lg bg-secondary/10 px-3 py-2">
<span className="font-semibold text-foreground">Loading...</span>
</div>
);
}
if (error) {
return (
<div className="flex items-center gap-2 rounded-lg bg-secondary/10 px-3 py-2">
<span className="font-semibold text-destructive">Error loading points</span>
</div>
);
}

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +18
const swrKey = useMemo(
() =>
shouldRefresh === "true" ? "/api/survey?refresh=true" : "/api/survey",
[shouldRefresh],
);

Copilot AI Oct 19, 2025

Copy link

Choose a reason for hiding this comment

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

The refresh parameter in the SWR key doesn't actually affect the API request since the backend likely ignores this parameter. Consider using SWR's mutate function or a timestamp-based approach for forcing re-fetches instead of modifying the URL.

Copilot uses AI. Check for mistakes.
@Yuji181181 Yuji181181 linked an issue Oct 19, 2025 that may be closed by this pull request
@Yuji181181
Yuji181181 merged commit 41644fd into main Oct 19, 2025
1 check passed
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