Skip to content

Commit

Permalink
Merge pull request #72 from REAN-Foundation/drug-search-issue
Browse files Browse the repository at this point in the history
Fixed drug search issue.
  • Loading branch information
rupali-inflection authored Oct 7, 2024
2 parents 5a81c4d + 52c8690 commit 978dac3
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/routes/users/[userId]/drugs/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
export let data: PageServerData;
$: isLoading = false;
let retrivedDrugs;
$: drugs = data.drugs.Items;
const userId = $page.params.userId;
Expand Down Expand Up @@ -48,7 +49,7 @@
} satisfies PaginationSettings;
async function searchDrug(model) {
let url = `/api/server/drugs/search?`;
let url = `/api/server/drugs/search?`;
if (sortOrder) url += `sortOrder=${sortOrder}`;
else url += `sortOrder=ascending`;
Expand All @@ -64,7 +65,9 @@
const searchResult = await res.json();
totalDrugsCount = searchResult.TotalCount;
drugs = searchResult.Items.map((item, index) => ({ ...item, index: index + 1 }));
if (totalDrugsCount > 0) {
isLoading = false;
}
}
$:{
Expand All @@ -73,7 +76,10 @@
retrivedDrugs = drugs.slice(
paginationSettings.page * paginationSettings.limit,
paginationSettings.page * paginationSettings.limit + paginationSettings.limit
);
);
if (retrivedDrugs.length > 0) {
isLoading = false;
}
}
$: if (browser)
searchDrug({
Expand All @@ -86,11 +92,16 @@
});
function onPageChange(e: CustomEvent): void {
isLoading = true;
let pageIndex = e.detail;
itemsPerPage = items * (pageIndex + 1);
}
function onAmountChange(e: CustomEvent): void {
if (drugName || genericName) {
isLoading = true;
drugs = [];
}
itemsPerPage = e.detail * (paginationSettings.page + 1);
items = itemsPerPage;
}
Expand Down Expand Up @@ -197,8 +208,8 @@
<tbody class="!bg-white dark:!bg-inherit">
{#if retrivedDrugs.length <= 0 }
<tr>
<td colspan="6">No records found</td>
</tr>
<td colspan="6">{isLoading ? 'Loading...' : 'No records found'}</td>
</tr>
{:else}
{#each retrivedDrugs as row}
<tr class="!border-b !border-b-secondary-100 dark:!border-b-surface-700">
Expand Down

0 comments on commit 978dac3

Please sign in to comment.