feat: introducing team (HBE-86) (#36)

This commit is contained in:
Anwarul Islam
2023-03-21 16:35:01 +06:00
committed by GitHub
parent 2244fb0523
commit 8b1d8e6a90
30 changed files with 1733 additions and 439 deletions

View File

@@ -23,17 +23,18 @@ export function usePagedQuery<
const fetchNextPage = async () => {
fetching.value = true;
try {
const result = await client.query(query, {
...variables,
cursor: list.value.length > 0
? getCursor(list.value.at(-1))
: undefined
}).toPromise();
const result = await client
.query(query, {
...variables,
cursor:
list.value.length > 0 ? getCursor(list.value.at(-1)) : undefined,
})
.toPromise();
const resultList = getList(result.data!);
if (resultList.length < 20) {
hasNextPage.value = false
hasNextPage.value = false;
}
list.value.push(...resultList);
@@ -42,22 +43,30 @@ export function usePagedQuery<
error.value = true;
}
fetching.value = false;
}
};
onMounted(async () => {
await fetchNextPage()
await fetchNextPage();
});
const goToNextPage = async () => {
if (hasNextPage.value) {
await fetchNextPage()
await fetchNextPage();
}
};
const refetch = async () => {
currentPage.value = 0;
hasNextPage.value = true;
list.value = [];
await fetchNextPage();
};
return {
fetching,
error,
goToNextPage,
refetch,
list,
hasNextPage,
};