Skip to content

Commit

Permalink
Convert loader function to fetch api in Blocks.js
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyandreevsky committed Mar 14, 2024
1 parent 83603bd commit c9afdd9
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions packages/frontend/src/app/blocks/Blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ const paginateConfig = {
}


export async function loader() {
const paginatedBlocks = await Api.getBlocks(paginateConfig.defaultPage, paginateConfig.pageSize.default, 'desc')
const {resultSet, pagination} = paginatedBlocks

return {blocks: resultSet, total: pagination.total};
}

function Blocks() {
const [loading, setLoading] = useState(true)
const [blocks, setBlocks] = useState([])
Expand All @@ -42,11 +35,15 @@ function Blocks() {

const fetchData = () => {
setLoading(true)

loader().then((res) => {

setBlocks(res.blocks)
setTotal(res.total)
Api.getBlocks(
paginateConfig.defaultPage,
paginateConfig.pageSize.default,
'desc'
).then((res) => {

setBlocks(res.resultSet)
setTotal(res.pagination.total)

}).catch((error)=>{

Expand Down

0 comments on commit c9afdd9

Please sign in to comment.