forked from polka_billy/porridger
moved hooks to separate directories, added stories fallback
This commit is contained in:
26
front/src/hooks/api/useHomeAnnouncementList.js
Normal file
26
front/src/hooks/api/useHomeAnnouncementList.js
Normal file
@ -0,0 +1,26 @@
|
||||
import useFetch from './useFetch'
|
||||
import { API_URL } from '../../config'
|
||||
import { removeNull } from '../../utils'
|
||||
|
||||
const initialAnnouncements = { list_of_announcements: [], Success: true }
|
||||
|
||||
const useHomeAnnouncementList = (filters) => {
|
||||
const { data, loading, error } = useFetch(
|
||||
API_URL + '/announcements?' + new URLSearchParams(removeNull(filters)),
|
||||
null,
|
||||
initialAnnouncements
|
||||
)
|
||||
|
||||
const annList = data.list_of_announcements
|
||||
|
||||
const res = annList.map(ann => ({
|
||||
...ann,
|
||||
lat: ann.latitude,
|
||||
lng: ann.longtitude,
|
||||
bestBy: ann.best_by
|
||||
}))
|
||||
|
||||
return { data: error ? [] : res, loading, error }
|
||||
}
|
||||
|
||||
export default useHomeAnnouncementList
|
Reference in New Issue
Block a user