mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-26 10:35:40 +00:00
other fixes
This commit is contained in:
parent
b5b65af6b4
commit
25e01d9606
5 changed files with 66 additions and 33 deletions
14
frontend/app/router.options.ts
Normal file
14
frontend/app/router.options.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import type { RouterConfig } from "@nuxt/schema";
|
||||||
|
|
||||||
|
export default <RouterConfig>{
|
||||||
|
scrollBehavior(to, from, savedPosition) {
|
||||||
|
console.log(to, from, savedPosition);
|
||||||
|
if (savedPosition) {
|
||||||
|
return savedPosition;
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
top: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
|
@ -29,9 +29,7 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="mb-2 text-clip three-line">
|
<Markdown class="mb-2 text-clip three-line" :source="item.description" />
|
||||||
{{ item.description }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="flex gap-2 flex-wrap -mr-1 mt-auto justify-end">
|
<div class="flex gap-2 flex-wrap -mr-1 mt-auto justify-end">
|
||||||
<LabelChip v-for="label in top3" :key="label.id" :label="label" size="sm" />
|
<LabelChip v-for="label in top3" :key="label.id" :label="label" size="sm" />
|
||||||
|
|
|
@ -2,12 +2,12 @@ const cache = {
|
||||||
currency: "",
|
currency: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
export function ResetCurrency() {
|
export function resetCurrency() {
|
||||||
cache.currency = "";
|
cache.currency = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function useFormatCurrency() {
|
export async function useFormatCurrency() {
|
||||||
if (!cache.currency) {
|
if (cache.currency === "") {
|
||||||
const client = useUserApi();
|
const client = useUserApi();
|
||||||
|
|
||||||
const { data: group } = await client.group.get();
|
const { data: group } = await client.group.get();
|
||||||
|
|
|
@ -102,6 +102,9 @@
|
||||||
|
|
||||||
const username = computed(() => authStore.self?.name || "User");
|
const username = computed(() => authStore.self?.name || "User");
|
||||||
|
|
||||||
|
// Preload currency format
|
||||||
|
useFormatCurrency();
|
||||||
|
|
||||||
const modals = reactive({
|
const modals = reactive({
|
||||||
item: false,
|
item: false,
|
||||||
location: false,
|
location: false,
|
||||||
|
|
|
@ -21,32 +21,34 @@
|
||||||
const items = ref<ItemSummary[]>([]);
|
const items = ref<ItemSummary[]>([]);
|
||||||
const total = ref(0);
|
const total = ref(0);
|
||||||
|
|
||||||
const page = useRouteQuery("page", 1);
|
const page1 = useRouteQuery("page", 1);
|
||||||
|
|
||||||
|
const page = computed({
|
||||||
|
get: () => page1.value,
|
||||||
|
set: value => {
|
||||||
|
page1.value = value;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const pageSize = useRouteQuery("pageSize", 21);
|
const pageSize = useRouteQuery("pageSize", 21);
|
||||||
const query = useRouteQuery("q", "");
|
const query = useRouteQuery("q", "");
|
||||||
const advanced = useRouteQuery("advanced", false);
|
const advanced = useRouteQuery("advanced", false);
|
||||||
const includeArchived = useRouteQuery("archived", false);
|
const includeArchived = useRouteQuery("archived", false);
|
||||||
|
|
||||||
const hasNext = computed(() => {
|
const totalPages = computed(() => Math.ceil(total.value / pageSize.value));
|
||||||
return page.value * pageSize.value < total.value;
|
const hasNext = computed(() => page.value * pageSize.value < total.value);
|
||||||
});
|
const hasPrev = computed(() => page.value > 1);
|
||||||
|
|
||||||
const totalPages = computed(() => {
|
const itemsTitle = ref<HTMLDivElement>();
|
||||||
return Math.ceil(total.value / pageSize.value);
|
|
||||||
});
|
|
||||||
|
|
||||||
function next() {
|
|
||||||
page.value = Math.min(Math.ceil(total.value / pageSize.value), page.value + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const hasPrev = computed(() => {
|
|
||||||
return page.value > 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
function prev() {
|
function prev() {
|
||||||
page.value = Math.max(1, page.value - 1);
|
page.value = Math.max(1, page.value - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function next() {
|
||||||
|
page.value = Math.min(Math.ceil(total.value / pageSize.value), page.value + 1);
|
||||||
|
}
|
||||||
|
|
||||||
async function resetPageSearch() {
|
async function resetPageSearch() {
|
||||||
if (searchLocked.value) {
|
if (searchLocked.value) {
|
||||||
return;
|
return;
|
||||||
|
@ -67,17 +69,15 @@
|
||||||
|
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
|
||||||
const locations = selectedLocations.value.map(l => l.id);
|
|
||||||
const labels = selectedLabels.value.map(l => l.id);
|
|
||||||
|
|
||||||
const { data, error } = await api.items.getAll({
|
const { data, error } = await api.items.getAll({
|
||||||
q: query.value || "",
|
q: query.value || "",
|
||||||
locations,
|
locations: locIDs.value,
|
||||||
labels,
|
labels: labIDs.value,
|
||||||
includeArchived: includeArchived.value,
|
includeArchived: includeArchived.value,
|
||||||
page: page.value,
|
page: page.value,
|
||||||
pageSize: pageSize.value,
|
pageSize: pageSize.value,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
page.value = Math.max(1, page.value - 1);
|
page.value = Math.max(1, page.value - 1);
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
@ -130,6 +130,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
window.scroll({
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
behavior: "smooth",
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const locationsStore = useLocationStore();
|
const locationsStore = useLocationStore();
|
||||||
|
@ -141,16 +146,18 @@
|
||||||
const selectedLocations = ref<LocationOutCount[]>([]);
|
const selectedLocations = ref<LocationOutCount[]>([]);
|
||||||
const selectedLabels = ref<LabelSummary[]>([]);
|
const selectedLabels = ref<LabelSummary[]>([]);
|
||||||
|
|
||||||
|
const locIDs = computed(() => selectedLocations.value.map(l => l.id));
|
||||||
|
const labIDs = computed(() => selectedLabels.value.map(l => l.id));
|
||||||
|
|
||||||
watchPostEffect(() => {
|
watchPostEffect(() => {
|
||||||
if (!queryParamsInitialized.value) {
|
if (!queryParamsInitialized.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const labelIds = selectedLabels.value.map(l => l.id);
|
|
||||||
router.push({
|
router.push({
|
||||||
query: {
|
query: {
|
||||||
...router.currentRoute.value.query,
|
...router.currentRoute.value.query,
|
||||||
lab: labelIds,
|
lab: labIDs.value,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -160,11 +167,10 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const locIds = selectedLocations.value.map(l => l.id);
|
|
||||||
router.push({
|
router.push({
|
||||||
query: {
|
query: {
|
||||||
...router.currentRoute.value.query,
|
...router.currentRoute.value.query,
|
||||||
loc: locIds,
|
loc: locIDs.value,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -176,8 +182,20 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
watchDebounced([selectedLocations, selectedLabels, query], resetPageSearch, { debounce: 250, maxWait: 1000 });
|
// resetPageHash computes a JSON string that is used to detect if the search
|
||||||
watch(includeArchived, resetPageSearch);
|
// parameters have changed. If they have changed, the page is reset to 1.
|
||||||
|
const resetPageHash = computed(() => {
|
||||||
|
const map = {
|
||||||
|
q: query.value,
|
||||||
|
includeArchived: includeArchived.value,
|
||||||
|
locations: locIDs.value,
|
||||||
|
labels: labIDs.value,
|
||||||
|
};
|
||||||
|
|
||||||
|
return JSON.stringify(map);
|
||||||
|
});
|
||||||
|
|
||||||
|
watchDebounced(resetPageHash, resetPageSearch, { debounce: 250, maxWait: 1000 });
|
||||||
|
|
||||||
watchDebounced([page, pageSize], search, { debounce: 250, maxWait: 1000 });
|
watchDebounced([page, pageSize], search, { debounce: 250, maxWait: 1000 });
|
||||||
</script>
|
</script>
|
||||||
|
@ -210,7 +228,7 @@
|
||||||
</div>
|
</div>
|
||||||
</BaseCard>
|
</BaseCard>
|
||||||
<section class="mt-10">
|
<section class="mt-10">
|
||||||
<BaseSectionHeader> Items </BaseSectionHeader>
|
<BaseSectionHeader ref="itemsTitle"> Items </BaseSectionHeader>
|
||||||
<p class="text-base font-medium flex items-center">
|
<p class="text-base font-medium flex items-center">
|
||||||
{{ total }} Results
|
{{ total }} Results
|
||||||
<span class="text-base ml-auto"> Page {{ page }} of {{ totalPages }}</span>
|
<span class="text-base ml-auto"> Page {{ page }} of {{ totalPages }}</span>
|
||||||
|
@ -221,7 +239,7 @@
|
||||||
|
|
||||||
<div class="hidden first:inline text-xl">No Items Found</div>
|
<div class="hidden first:inline text-xl">No Items Found</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="items.length > 0" class="mt-10 flex gap-2 flex-col items-center">
|
<div v-if="items.length > 0 && (hasNext || hasPrev)" class="mt-10 flex gap-2 flex-col items-center">
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button :disabled="!hasPrev" class="btn text-no-transform" @click="prev">
|
<button :disabled="!hasPrev" class="btn text-no-transform" @click="prev">
|
||||||
|
|
Loading…
Reference in a new issue