Skip to content

Commit

Permalink
add consistency when changing pages
Browse files Browse the repository at this point in the history
  • Loading branch information
crsct authored and lukasjelonek committed Nov 23, 2023
1 parent 88f82f1 commit 4979df4
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/views/search/SearchView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ function populateVariables() {
const decodedQuery = decodeQuery(route.query.query as string);
query.value = decodedQuery.query;
ordering.value = decodedQuery.ordering;
search();
pagination.value.offset = Number.parseInt(route.query.offset as string);
pagination.value.limit = Number.parseInt(route.query.limit as string);
search(pagination.value.offset);
}
}
Expand All @@ -89,6 +91,17 @@ watch(
},
);
function updateQuery(offset = 0) {
router.push({
name: "search",
query: {
offset: offset,
limit: pagination.value.limit,
query: encodeQuery(),
},
});
}
function searchinfo2querybuilderrules(f: SearchInfoField): Rule {
const config = fieldNames[f.field];
const field = config ? config.label : f.field;
Expand Down Expand Up @@ -192,15 +205,6 @@ const fieldNames: Record<string, FieldConfiguration> = {
function search(offset = 0) {
searchState.value.setState(State.Loading);
resetTsvExport();
const encodedQuery = encodeQuery();
router.push({
name: "search",
query: {
offset: pagination.value.offset,
limit: pagination.value.limit,
query: encodedQuery,
},
});
api
.search({
query: unref(query),
Expand All @@ -213,6 +217,7 @@ function search(offset = 0) {
searchState.value.setState(State.Main);
if (r.offset) pagination.value.offset = r.offset;
pagination.value.total = r.total;
updateQuery(r.offset);
})
.catch((err) => pageState.value.setError(err));
}
Expand Down Expand Up @@ -337,7 +342,7 @@ onBeforeUnmount(() => {
v-if="pagination.total > 0"
class="mt-3"
:value="pagination"
@update:offset="search"
@update:offset="updateQuery"
/>
</div>
</Loading>
Expand Down

0 comments on commit 4979df4

Please sign in to comment.