-
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
apply swr for list page #34
base: main
Are you sure you want to change the base?
Changes from 5 commits
6de73e3
352f26b
69ba4e1
eca60ea
1fd7882
f33b221
5baa0ca
1ad7029
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { firebase } from "../../../firebase"; | ||
import "firebase/firestore"; | ||
|
||
export const DeleteNewsById = async (id: string): Promise<void> => { | ||
export const deleteNewsById = async (id: string): Promise<void> => { | ||
await firebase.firestore().collection("news").doc(id).delete(); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import "firebase/firestore"; | ||
import { News } from "../models/news"; | ||
import useSWR from 'swr'; | ||
import { retrieveNews } from "../firestore/news/retrieveNews"; | ||
|
||
interface UseNewListData { | ||
newsList: News[]; | ||
isError: boolean; | ||
isLoading: boolean; | ||
} | ||
|
||
export function useNewListData() { | ||
const { data, error } = useSWR("useNewListData", async () => { | ||
return await retrieveNews(); | ||
}); | ||
|
||
return { | ||
newsList: data, | ||
isError: !!error, | ||
isLoading: !data && !error, | ||
} as UseNewListData; | ||
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. @duoctvd |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import "firebase/firestore"; | ||
import { News } from "../models/news"; | ||
import useSWR from 'swr'; | ||
import { retrieveNewsById } from "../firestore/news/retrieveNewsById"; | ||
|
||
interface useRetrieveNewsDataById { | ||
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. @duoctvd |
||
news: News; | ||
isError: boolean; | ||
isLoading: boolean; | ||
} | ||
|
||
export function useRetrieveNewsDataById(newsId:string): useRetrieveNewsDataById { | ||
|
||
const { data, error } = useSWR(newsId ? "useRetrieveNewsDataById" : null, async () => { | ||
return await retrieveNewsById(newsId); | ||
}); | ||
|
||
return { | ||
news: data, | ||
isError: !!error, | ||
isLoading: !data && !error, | ||
} as useRetrieveNewsDataById; | ||
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. tương tự ở trên, bỏ |
||
} |
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.
@duoctvd
Thêm kiểu trả về ở function để khi code của mình viết nó trả về không đúng thì fix lại code.
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.
@bit-thuynt: sorry chị! em nhớ hôm qua em thêm cho nó rồi! mà chắc em adjust code debug sao sao sao push lên nó lại bị xóa đi, để em thêm lại