-
Notifications
You must be signed in to change notification settings - Fork 25
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
Fix the header #133
base: main
Are you sure you want to change the base?
Fix the header #133
Conversation
WalkthroughThe pull request modifies the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
🔭 Outside diff range comments (1)
src/routes/events/$eventId.tsx (1)
Line range hint
1-45
: Improve type safety with proper interfaces and type guardsThe code lacks proper TypeScript types which could lead to runtime errors:
- Missing interface for event data
- Unsafe type assertions
- Potential null reference issues
Add these type definitions at the top of the file:
interface Event { id: string; name: string; description: string; start_time: string; end_time: string; location: string; fee: number; user_id: string; } interface RouteLoaderData { event: Event; } // Update the loader return type export const Route = createFileRoute('/events/$eventId')({ loader: async ({ params: { eventId } }): Promise<RouteLoaderData> => { const { data, error } = await supabase .from('events') .select('*') .eq('id', eventId) .single(); if (error !== null) { throw error; } return { event: data as Event }; }, component: EventDetails });
🧹 Nitpick comments (1)
src/routes/events/$eventId.tsx (1)
48-50
: Consider a more robust header layout solutionWhile adding
z-index
fixes the immediate header overlap issue, it might mask underlying layout problems. Consider using proper layout structure withsticky
positioning instead.- <div className="relative z-10"> - <Header /> - </div> + <div className="sticky top-0"> + <Header /> + </div>
@@ -42,12 +42,13 @@ const styles = { | |||
function EventDetails() { | |||
const { event } = Route.useLoaderData() | |||
const [join, setJoin] = useState(false) | |||
const [isFavorite, setIsFavorite] = useState(false) |
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.
Implement complete favorites functionality
The favorites feature is currently incomplete:
- State isn't persisted to the database
- Missing initial state from user's existing favorites
- No error handling for network failures
- No loading states during API calls
Consider implementing a more complete solution:
+ const [isLoading, setIsLoading] = useState(false);
- const [isFavorite, setIsFavorite] = useState(false);
+ const [isFavorite, setIsFavorite] = useState<boolean | null>(null);
+ useEffect(() => {
+ const fetchFavoriteStatus = async () => {
+ try {
+ const { data, error } = await supabase
+ .from('favorites')
+ .select('*')
+ .eq('event_id', event.id)
+ .single();
+
+ if (error) throw error;
+ setIsFavorite(!!data);
+ } catch (error) {
+ console.error('Error fetching favorite status:', error);
+ }
+ };
+
+ fetchFavoriteStatus();
+ }, [event.id]);
+ const toggleFavorite = async () => {
+ setIsLoading(true);
+ try {
+ if (isFavorite) {
+ const { error } = await supabase
+ .from('favorites')
+ .delete()
+ .eq('event_id', event.id);
+ if (error) throw error;
+ } else {
+ const { error } = await supabase
+ .from('favorites')
+ .insert({ event_id: event.id });
+ if (error) throw error;
+ }
+ setIsFavorite(!isFavorite);
+ } catch (error) {
+ console.error('Error toggling favorite:', error);
+ } finally {
+ setIsLoading(false);
+ }
+ };
- <div onClick={() => setIsFavorite(!isFavorite)} className="cursor-pointer">
+ <div
+ onClick={toggleFavorite}
+ className={`cursor-pointer ${isLoading ? 'opacity-50' : ''}`}
+ disabled={isLoading}
+ >
Also applies to: 87-96
<button className="btn bottom-1 right-1" | ||
onClick={() => { | ||
if (join) { | ||
(document.getElementById("cancel_modal") as HTMLFormElement).showModal(); | ||
} else { | ||
(document.getElementById("join_modal") as HTMLFormElement).showModal(); | ||
} | ||
}}> | ||
{join ? "已報名" : "報名活動"} | ||
</button> |
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.
🛠️ Refactor suggestion
Improve accessibility of interactive elements
The join button and modals need accessibility improvements:
- Missing ARIA labels
- Modal focus management
- Keyboard navigation support
- <button className="btn bottom-1 right-1"
+ <button
+ className="btn bottom-1 right-1"
+ aria-label={join ? "取消報名活動" : "報名活動"}
+ role="button"
onClick={() => {
if (join) {
- (document.getElementById("cancel_modal") as HTMLFormElement).showModal();
+ const modal = document.getElementById("cancel_modal") as HTMLDialogElement;
+ modal.showModal();
+ modal.querySelector('button')?.focus();
} else {
- (document.getElementById("join_modal") as HTMLFormElement).showModal();
+ const modal = document.getElementById("join_modal") as HTMLDialogElement;
+ modal.showModal();
+ modal.querySelector('button')?.focus();
}
}}>
{join ? "已報名" : "報名活動"}
</button>
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
<button className="btn bottom-1 right-1" | |
onClick={() => { | |
if (join) { | |
(document.getElementById("cancel_modal") as HTMLFormElement).showModal(); | |
} else { | |
(document.getElementById("join_modal") as HTMLFormElement).showModal(); | |
} | |
}}> | |
{join ? "已報名" : "報名活動"} | |
</button> | |
<button | |
className="btn bottom-1 right-1" | |
aria-label={join ? "取消報名活動" : "報名活動"} | |
role="button" | |
onClick={() => { | |
if (join) { | |
const modal = document.getElementById("cancel_modal") as HTMLDialogElement; | |
modal.showModal(); | |
modal.querySelector('button')?.focus(); | |
} else { | |
const modal = document.getElementById("join_modal") as HTMLDialogElement; | |
modal.showModal(); | |
modal.querySelector('button')?.focus(); | |
} | |
}}> | |
{join ? "已報名" : "報名活動"} | |
</button> |
修復header呈現問題、修改收藏寫法、根據新資料庫修點東西
Summary by CodeRabbit