Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File page index fix #1704

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions web/src/components/FileBrowser/FileBrowserPagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
:max="pageCount"
:maxlength="pageCount"
:rules="[pageIsValid]"
@change="emit('changePage', pageInput)"
/>
<span>of {{ pageCount }}</span>
<v-btn
Expand All @@ -53,7 +54,7 @@
</template>

<script setup lang="ts">
import { ref, watch } from 'vue';
import { toRefs } from 'vue';

const props = defineProps({
page: {
Expand All @@ -72,15 +73,6 @@ function pageIsValid(page: number): boolean {

const emit = defineEmits(['changePage']);

// Note: the v-textfield `v-model` returns a string value despite its type being 'number', so
// we have to handle converting back and forth below.
const pageInput = ref(props.page.toString());
const { page: pageInput } = toRefs(props);

watch(() => props.page, (newPage) => { pageInput.value = newPage.toString(); });
watch(pageInput, (newPage) => {
const page = Number(newPage);
if (page > 0 && page <= props.pageCount) {
emit('changePage', page);
}
});
</script>
17 changes: 11 additions & 6 deletions web/src/views/FileBrowserView/FileBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
v-if="currentDandiset.asset_count"
:page="page"
:page-count="pages"
@changePage="page = $event;"
@changePage="changePage($event)"
/>
</v-container>
</div>
Expand Down Expand Up @@ -437,9 +437,10 @@ function showDelete(item: AssetPath) {
async function getItems() {
updating.value = true;
let resp;
const currentPage = Number(route.query.page) || page.value;
try {
resp = await dandiRest.assetPaths(
props.identifier, props.version, location.value, page.value, FILES_PER_PAGE,
props.identifier, props.version, location.value, currentPage, FILES_PER_PAGE,
);
} catch (e) {
if (axios.isAxiosError(e) && e.response?.status === 404) {
Expand Down Expand Up @@ -502,7 +503,7 @@ watch(location, () => {
if (existingLocation === location.value) { return; }
router.push({
...route,
query: { location: location.value },
query: { location: location.value, page: String(page.value) },
} as RawLocation);
});

Expand All @@ -517,9 +518,13 @@ watch(() => route.query, (newRouteQuery) => {
// Retrieve with new location
getItems();
}, { immediate: true });

// fetch new page of items when a new one is selected
watch(page, getItems);
const changePage = (newPage: number) => {
page.value = newPage;
router.push({
...route,
query: { location: location.value, page: String(page.value) },
} as RawLocation);
};
mvandenburgh marked this conversation as resolved.
Show resolved Hide resolved

// Fetch dandiset if necessary
onMounted(() => {
Expand Down