-
Notifications
You must be signed in to change notification settings - Fork 0
feat: connect daily tips to backend #90
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { useQuery } from '@tanstack/react-query' | ||
| import { API_ENDPOINTS } from '@/constants/api.constants' | ||
| import { apiService } from '@/services/api/api.service' | ||
| import type { DailyTip } from '@/services/api/tips.service' | ||
|
|
||
| export const useDailyTip = () => { | ||
| const { data, isLoading, error } = useQuery({ | ||
| queryKey: ['dailyTip'], | ||
| queryFn: () => apiService.get<DailyTip>(API_ENDPOINTS.tips), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You had implemented |
||
| }) | ||
|
|
||
| return { tip: data, isLoading, error } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,20 @@ | ||
| import { useTranslation } from 'react-i18next' | ||
| import { SGLTypography } from '@/components/UI/Typography/SGLTypography' | ||
| import { titleAndDescriptionStyles } from './styles' | ||
| import { useDailyTip } from '@/hooks/useDailyTip' | ||
|
|
||
| export const TitleAndDescription = () => { | ||
| const { t } = useTranslation() | ||
| const { tip, isLoading, error } = useDailyTip() | ||
|
|
||
| if (isLoading) return null | ||
| if (error || !tip) return null | ||
|
Comment on lines
+8
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t render a blank section on error/no-data. On Line 8-9, Proposed fix- if (isLoading) return null
- if (error || !tip) return null
+ if (isLoading) return null
+ if (error || !tip) {
+ return (
+ <>
+ <SGLTypography variant="smallTitle" styles={titleAndDescriptionStyles.title}>
+ Daily tip
+ </SGLTypography>
+ <SGLTypography variant="smallText" styles={titleAndDescriptionStyles.description}>
+ Tip is currently unavailable.
+ </SGLTypography>
+ </>
+ )
+ }🤖 Prompt for AI Agents
Comment on lines
+8
to
+9
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Component should return JSX return </> instead of null |
||
|
|
||
| return ( | ||
| <> | ||
| <SGLTypography variant="smallTitle" styles={titleAndDescriptionStyles.title}> | ||
| {t('daily.tip.title')} | ||
| {tip.title} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you removed the translation support? |
||
| </SGLTypography> | ||
| <SGLTypography variant="smallText" styles={titleAndDescriptionStyles.description}> | ||
| {t('daily.tip.description')} | ||
| {tip.description} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. change the language |
||
| </SGLTypography> | ||
| </> | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { apiService } from './api.service' | ||
|
|
||
| export interface DailyTip { | ||
| title: string | ||
| description: string | ||
| } | ||
|
|
||
| export const getDailyTip = (): Promise<DailyTip> => { | ||
| return apiService.get<DailyTip>('/tips/daily') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider to use const and move it to the appropriate file
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. API_ENDPOINTS.tips |
||
| } | ||
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.
why did you remove it? This is a reference for a working route