Passes collection object via router to collection page.

This commit is contained in:
mateuswetah 2022-05-27 15:11:00 -03:00
parent a0652dd1d2
commit 06cf31ccea
4 changed files with 42 additions and 15 deletions

View File

@ -1,5 +1,9 @@
<template> <template>
<ion-item class="collection-list-item" v-for="collection of collections" :key="collection.id" :router-link="`/collections/${collection.id}`"> <ion-item
class="collection-list-item"
v-for="collection of collections"
:key="collection.id"
@click="goToCollectionPage(collection)">
<ion-thumbnail slot="start"> <ion-thumbnail slot="start">
<ion-img :src="(collection.thumbnail && collection.thumbnail.thumbnail && collection.thumbnail.thumbnail[0]) ? collection.thumbnail.thumbnail[0] : thumbnailPlaceholder" :alt="collection.name ? collection.name : $('label_collection_without_name')"></ion-img> <ion-img :src="(collection.thumbnail && collection.thumbnail.thumbnail && collection.thumbnail.thumbnail[0]) ? collection.thumbnail.thumbnail[0] : thumbnailPlaceholder" :alt="collection.name ? collection.name : $('label_collection_without_name')"></ion-img>
</ion-thumbnail> </ion-thumbnail>
@ -31,6 +35,7 @@ import {
IonLabel, IonLabel,
IonIcon IonIcon
} from '@ionic/vue'; } from '@ionic/vue';
import { useRouter } from "vue-router";
import { lockClosedOutline, readerOutline, trashOutline } from 'ionicons/icons'; import { lockClosedOutline, readerOutline, trashOutline } from 'ionicons/icons';
import { computed } from 'vue'; import { computed } from 'vue';
@ -47,7 +52,23 @@ export default {
}, },
setup() { setup() {
const thumbnailPlaceholder = computed (() => require('../../assets/placeholder_square_small.png')) const thumbnailPlaceholder = computed (() => require('../../assets/placeholder_square_small.png'))
return { thumbnailPlaceholder, lockClosedOutline, readerOutline, trashOutline } const router = useRouter();
const goToCollectionPage = (collection: any) => {
router .push({
name: 'collection',
params: {
id: collection.id,
collection: JSON.stringify(collection)
}
});
}
return {
thumbnailPlaceholder,
lockClosedOutline,
readerOutline,
trashOutline,
goToCollectionPage
}
}, },
} }
</script> </script>

View File

@ -1,6 +1,6 @@
<template> <template>
<ion-row class="items-list-container"> <ion-row class="items-list-container">
<ion-col size="4" v-for="(item, index) of items" :key="index"> <ion-col size="4" v-for="item of items" :key="item.id">
<ion-card button color="light" > <ion-card button color="light" >
<ion-img :src="(item.thumbnail && item.thumbnail['tainacan-medium'] && item.thumbnail['tainacan-medium'][0]) ? item.thumbnail['tainacan-medium'][0] : thumbnailPlaceholder" :alt="(item.thumbnail_alt ? item.thumbnail_alt : (item.title ? item.title : 'Imagem de item sem título'))"></ion-img> <ion-img :src="(item.thumbnail && item.thumbnail['tainacan-medium'] && item.thumbnail['tainacan-medium'][0]) ? item.thumbnail['tainacan-medium'][0] : thumbnailPlaceholder" :alt="(item.thumbnail_alt ? item.thumbnail_alt : (item.title ? item.title : 'Imagem de item sem título'))"></ion-img>
<ion-card-header> <ion-card-header>

View File

@ -1,5 +1,7 @@
<template> <template>
<base-layout :page-title="$t('collection')" page-default-back-link="/collections"> <base-layout
:page-title="(collectionObject && collectionObject.name) ? collectionObject.name : $t('collection')"
page-default-back-link="/collections">
<ion-refresher slot="fixed" @ionRefresh="doRefresh($event)"> <ion-refresher slot="fixed" @ionRefresh="doRefresh($event)">
<ion-refresher-content></ion-refresher-content> <ion-refresher-content></ion-refresher-content>
</ion-refresher> </ion-refresher>
@ -23,8 +25,7 @@
import { import {
useTainacanStore useTainacanStore
} from '../store/storeTainacan'; } from '../store/storeTainacan';
import { useRoute } from "vue-router"; import { ref, defineComponent } from 'vue';
import { ref } from 'vue';
import { add, documentOutline, documentAttachOutline, documentsOutline } from "ionicons/icons"; import { add, documentOutline, documentAttachOutline, documentsOutline } from "ionicons/icons";
import { import {
@ -39,7 +40,7 @@ import {
import BaseLayout from '@/components/base/BaseLayout.vue'; import BaseLayout from '@/components/base/BaseLayout.vue';
import ItemsList from '@/components/lists/ItemsList.vue'; import ItemsList from '@/components/lists/ItemsList.vue';
export default { export default defineComponent({
components: { components: {
BaseLayout, BaseLayout,
ItemsList, ItemsList,
@ -49,13 +50,15 @@ export default {
IonIcon, IonIcon,
IonButton IonButton
}, },
setup() { props: {
id: String,
collection: String
},
setup(props) {
const isLoading = ref(false); const isLoading = ref(false);
const setIsLoading = (state: boolean) => isLoading.value = state; const setIsLoading = (state: boolean) => isLoading.value = state;
const route = useRoute();
const collectionId = route.params.id + '';
const loadItemsByCollection = async () => { const loadItemsByCollection = async () => {
await tainacanStore.fetchItemsByCollection(collectionId, { perPage: '24', orderBy: 'modified'}); await tainacanStore.fetchItemsByCollection(props.id + '', { perPage: '24', orderBy: 'modified'});
} }
const doRefresh = async (event: any) => { const doRefresh = async (event: any) => {
await loadItemsByCollection(); await loadItemsByCollection();
@ -111,6 +114,8 @@ export default {
console.log('onDidDismiss resolved with role and data', role, data); console.log('onDidDismiss resolved with role and data', role, data);
} }
const collectionObject = props.collection ? JSON.parse(props.collection + '') : false;
let tainacanStore = useTainacanStore(); let tainacanStore = useTainacanStore();
return { return {
@ -120,10 +125,10 @@ export default {
loadItemsByCollection, loadItemsByCollection,
doRefresh, doRefresh,
openActionSheet, openActionSheet,
collectionId,
add, add,
actionSheetLabels, actionSheetLabels,
setActionSheetLabels setActionSheetLabels,
collectionObject
} }
}, },
async created() { async created() {
@ -140,7 +145,7 @@ export default {
await this.loadItemsByCollection(); await this.loadItemsByCollection();
this.setIsLoading(false); this.setIsLoading(false);
}, },
} });
</script> </script>
<style> <style>

View File

@ -26,7 +26,8 @@ const routes: Array<RouteRecordRaw> = [
{ {
path: '/collections/:id', path: '/collections/:id',
component: CollectionPage, component: CollectionPage,
name: 'collection' name: 'collection',
props: true
}, },
{ {
path: '/collections', path: '/collections',