Skip to content

Commit

Permalink
Fix: Articles fetching to be consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
georgipavlov-7DIGIT committed May 9, 2024
1 parent 789486c commit 9208c0b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/blocks/Articles/Articles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const Articles = () => {
const [hasMore, setHasMore] = useState(true);
const [startFrom, setStartFrom] = useState(0);

console.log(startFrom, "startFRom");

//--------------------- Articles ----------------------//
const getArticles = async () => {
// Request Articles ids from the master DB
Expand Down Expand Up @@ -77,19 +79,16 @@ export const Articles = () => {
} = useQuery(["articles", i18n.language, startFrom], getArticles, {
onSuccess: (data) => {
setNumberOfArticles(data.numberOfArticles);
console.log("hasMore in Query", hasMore);
if (hasMore) {
setStartFrom((prev) => prev + data.formattedData.length);
}
setDataToDisplay([...dataToDisplay, ...data.formattedData]);
const newHasMore = data.numberOfArticles > dataToDisplay.length;
setHasMore(newHasMore);
},
});

useEffect(() => {
if (articlesData && articlesData.formattedData) {
setHasMore(numberOfArticles > dataToDisplay.length);
}
}, [articlesData]);

const handleSelectArticle = async (id, newValue) => {
let newData = JSON.parse(JSON.stringify(dataToDisplay));
const index = newData.indexOf(newData.find((x) => x.id === id));
Expand Down

0 comments on commit 9208c0b

Please sign in to comment.