This commit is contained in:
joycitta-siqueira 2022-04-16 00:35:52 -03:00
parent f02f342c61
commit 8585ba1ad4
13 changed files with 354 additions and 54 deletions

137
package-lock.json generated
View File

@ -8,14 +8,17 @@
"name": "tainacanteste",
"version": "0.0.1",
"dependencies": {
"@awesome-cordova-plugins/ionic-webview": "^5.41.0",
"@capacitor/app": "1.1.1",
"@capacitor/core": "3.4.3",
"@capacitor/haptics": "1.1.4",
"@capacitor/keyboard": "1.2.2",
"@capacitor/status-bar": "1.0.8",
"@ionic/storage": "^3.0.6",
"@ionic/vue": "^6.0.0",
"@ionic/vue-router": "^6.0.0",
"axios": "^0.26.1",
"cordova-plugin-ionic-webview": "^5.0.0",
"core-js": "^3.6.5",
"pinia": "^2.0.12",
"vue": "^3.2.21",
@ -59,6 +62,30 @@
"node": ">=6.0.0"
}
},
"node_modules/@awesome-cordova-plugins/core": {
"version": "5.41.0",
"resolved": "https://registry.npmjs.org/@awesome-cordova-plugins/core/-/core-5.41.0.tgz",
"integrity": "sha512-pWGAvz3bfiSx5k7iqDM4O6miJwIAGXhSM0odjMo4Vh/9gOGf603Whg57eeQwikmP/ysH+HKGCxJ885W+wPEpmw==",
"peer": true,
"dependencies": {
"@types/cordova": "latest"
},
"peerDependencies": {
"rxjs": "^5.5.0 || ^6.5.0 || ^7.3.0"
}
},
"node_modules/@awesome-cordova-plugins/ionic-webview": {
"version": "5.41.0",
"resolved": "https://registry.npmjs.org/@awesome-cordova-plugins/ionic-webview/-/ionic-webview-5.41.0.tgz",
"integrity": "sha512-u9p8aCmTfyIsbsicSrUyXOq1PfUTQl0H+Au207qsJR/1WD2gg1Ral/Hl3cnY8yxIFdFjLZXPBrrfryIv9m3PyQ==",
"dependencies": {
"@types/cordova": "latest"
},
"peerDependencies": {
"@awesome-cordova-plugins/core": "^5.1.0",
"rxjs": "^5.5.0 || ^6.5.0 || ^7.3.0"
}
},
"node_modules/@babel/code-frame": {
"version": "7.16.7",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.16.7.tgz",
@ -2205,6 +2232,14 @@
"node": ">=8"
}
},
"node_modules/@ionic/storage": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/@ionic/storage/-/storage-3.0.6.tgz",
"integrity": "sha512-sw+zSJINIpbQCGZR9mEtb9N0WmZLuhcMVqOZJBqLuDACAMdXqG39zmp5nSVqhGI1/9X3nd0K5gVn6icyVfUnUg==",
"dependencies": {
"localforage": "^1.9.0"
}
},
"node_modules/@ionic/utils-array": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@ionic/utils-array/-/utils-array-2.1.5.tgz",
@ -3336,6 +3371,11 @@
"@types/node": "*"
}
},
"node_modules/@types/cordova": {
"version": "0.0.34",
"resolved": "https://registry.npmjs.org/@types/cordova/-/cordova-0.0.34.tgz",
"integrity": "sha1-6nrd907Ow9dimCegw54smt3HPQQ="
},
"node_modules/@types/eslint": {
"version": "7.29.0",
"resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.29.0.tgz",
@ -6542,6 +6582,24 @@
"url": "https://opencollective.com/webpack"
}
},
"node_modules/cordova-plugin-ionic-webview": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/cordova-plugin-ionic-webview/-/cordova-plugin-ionic-webview-5.0.0.tgz",
"integrity": "sha512-Wq0kCanxubK/JroTW4Mp5soayScnRyiY1eCkbwiz1Dyt1xHOiOW/v+1miqtBHtnZhcXw25TulCKAVJzkNBdmyg==",
"engines": {
"cordovaDependencies": {
"2.0.0": {
"cordova-android": ">=6.4.0",
"cordova-ios": ">=4.0.0-dev"
},
"3.1.0": {
"cordova": ">=7.1.0",
"cordova-android": ">=6.4.0",
"cordova-ios": ">=4.0.0-dev"
}
}
}
},
"node_modules/core-js": {
"version": "3.21.1",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.21.1.tgz",
@ -9771,6 +9829,11 @@
"node": ">= 4"
}
},
"node_modules/immediate": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
"integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps="
},
"node_modules/import-fresh": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz",
@ -12638,6 +12701,14 @@
"node": ">= 0.8.0"
}
},
"node_modules/lie": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz",
"integrity": "sha1-mkNrLMd0bKWd56QfpGmz77dr2H4=",
"dependencies": {
"immediate": "~3.0.5"
}
},
"node_modules/lilconfig": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.0.4.tgz",
@ -12715,6 +12786,14 @@
"json5": "lib/cli.js"
}
},
"node_modules/localforage": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/localforage/-/localforage-1.10.0.tgz",
"integrity": "sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==",
"dependencies": {
"lie": "3.1.1"
}
},
"node_modules/locate-path": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
@ -15520,7 +15599,6 @@
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.5.tgz",
"integrity": "sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw==",
"dev": true,
"dependencies": {
"tslib": "^2.1.0"
}
@ -18373,6 +18451,23 @@
"@jridgewell/trace-mapping": "^0.3.0"
}
},
"@awesome-cordova-plugins/core": {
"version": "5.41.0",
"resolved": "https://registry.npmjs.org/@awesome-cordova-plugins/core/-/core-5.41.0.tgz",
"integrity": "sha512-pWGAvz3bfiSx5k7iqDM4O6miJwIAGXhSM0odjMo4Vh/9gOGf603Whg57eeQwikmP/ysH+HKGCxJ885W+wPEpmw==",
"peer": true,
"requires": {
"@types/cordova": "latest"
}
},
"@awesome-cordova-plugins/ionic-webview": {
"version": "5.41.0",
"resolved": "https://registry.npmjs.org/@awesome-cordova-plugins/ionic-webview/-/ionic-webview-5.41.0.tgz",
"integrity": "sha512-u9p8aCmTfyIsbsicSrUyXOq1PfUTQl0H+Au207qsJR/1WD2gg1Ral/Hl3cnY8yxIFdFjLZXPBrrfryIv9m3PyQ==",
"requires": {
"@types/cordova": "latest"
}
},
"@babel/code-frame": {
"version": "7.16.7",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.16.7.tgz",
@ -19907,6 +20002,14 @@
}
}
},
"@ionic/storage": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/@ionic/storage/-/storage-3.0.6.tgz",
"integrity": "sha512-sw+zSJINIpbQCGZR9mEtb9N0WmZLuhcMVqOZJBqLuDACAMdXqG39zmp5nSVqhGI1/9X3nd0K5gVn6icyVfUnUg==",
"requires": {
"localforage": "^1.9.0"
}
},
"@ionic/utils-array": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@ionic/utils-array/-/utils-array-2.1.5.tgz",
@ -20799,6 +20902,11 @@
"@types/node": "*"
}
},
"@types/cordova": {
"version": "0.0.34",
"resolved": "https://registry.npmjs.org/@types/cordova/-/cordova-0.0.34.tgz",
"integrity": "sha1-6nrd907Ow9dimCegw54smt3HPQQ="
},
"@types/eslint": {
"version": "7.29.0",
"resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.29.0.tgz",
@ -23271,6 +23379,11 @@
}
}
},
"cordova-plugin-ionic-webview": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/cordova-plugin-ionic-webview/-/cordova-plugin-ionic-webview-5.0.0.tgz",
"integrity": "sha512-Wq0kCanxubK/JroTW4Mp5soayScnRyiY1eCkbwiz1Dyt1xHOiOW/v+1miqtBHtnZhcXw25TulCKAVJzkNBdmyg=="
},
"core-js": {
"version": "3.21.1",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.21.1.tgz",
@ -25676,6 +25789,11 @@
"integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==",
"dev": true
},
"immediate": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
"integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps="
},
"import-fresh": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz",
@ -27802,6 +27920,14 @@
"type-check": "~0.4.0"
}
},
"lie": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz",
"integrity": "sha1-mkNrLMd0bKWd56QfpGmz77dr2H4=",
"requires": {
"immediate": "~3.0.5"
}
},
"lilconfig": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.0.4.tgz",
@ -27858,6 +27984,14 @@
}
}
},
"localforage": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/localforage/-/localforage-1.10.0.tgz",
"integrity": "sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==",
"requires": {
"lie": "3.1.1"
}
},
"locate-path": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
@ -29912,7 +30046,6 @@
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.5.tgz",
"integrity": "sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw==",
"dev": true,
"requires": {
"tslib": "^2.1.0"
}

View File

@ -10,14 +10,17 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"@awesome-cordova-plugins/ionic-webview": "^5.41.0",
"@capacitor/app": "1.1.1",
"@capacitor/core": "3.4.3",
"@capacitor/haptics": "1.1.4",
"@capacitor/keyboard": "1.2.2",
"@capacitor/status-bar": "1.0.8",
"@ionic/storage": "^3.0.6",
"@ionic/vue": "^6.0.0",
"@ionic/vue-router": "^6.0.0",
"axios": "^0.26.1",
"cordova-plugin-ionic-webview": "^5.0.0",
"core-js": "^3.6.5",
"pinia": "^2.0.12",
"vue": "^3.2.21",

View File

@ -0,0 +1,56 @@
<template>
<ion-loading
:is-open="isOpenRef"
cssClass="my-custom-class"
message="Carregando..."
>
</ion-loading>
<ion-list>
<ion-item v-for="collection of collectionStore.collections" :key="collection.id" :router-link="`/collections/${collection.id}`">
<ion-thumbnail slot="start">
<ion-img v-if="collection.thumbnail.thumbnail[0]" :src="collection.thumbnail.thumbnail[0]" :alt="collection.name"></ion-img>
<ion-img v-else :src="image" :alt="collection.name"></ion-img>
</ion-thumbnail>
<ion-label> {{ collection.name }} </ion-label>
</ion-item>
</ion-list>
</template>
<script lang="ts">
import {
useCollectionsStore
} from '../store/storeCollection';
import {
IonList,
IonItem,
IonImg,
IonThumbnail,
IonLoading,
IonLabel,
} from '@ionic/vue';
import { computed, ref } from 'vue';
export default {
components: {
IonList,
IonItem,
IonImg,
IonThumbnail,
IonLabel,
IonLoading
},
setup() {
const image = computed (() => require('../assets/placeholder_square_small.png'))
const isOpenRef = ref(false);
const setOpen = (state: boolean) => isOpenRef.value = state;
let collectionStore = useCollectionsStore();
return { image, isOpenRef, setOpen, collectionStore }
},
async created(){
this.setOpen(true);
await this.collectionStore.fetchCollections();
this.setOpen(false);
},
}
</script>

View File

@ -0,0 +1,51 @@
<template>
<ion-loading
:is-open="isOpenRef"
cssClass="my-custom-class"
message="Carregando..."
>
</ion-loading>
<ion-card v-for="item of collectionStore.items" :key="item.id">
<ion-card-title v-if="item.title"> {{ item.title }} </ion-card-title>
<ion-card-title v-else>Item não possui título</ion-card-title>
<ion-card-content>
<ion-img :src="item.thumbnail.medium[0]" :alt="item.title"></ion-img>
</ion-card-content>
</ion-card>
</template>
<script lang="ts">
import {
useCollectionsStore
} from '../store/storeCollection';
import {
IonCard,
IonLoading,
} from '@ionic/vue';
import { ref } from 'vue';
export default {
components: {
IonCard,
IonLoading,
},
setup() {
const isOpenRef = ref(false);
const setOpen = (state: boolean) => isOpenRef.value = state;
let collectionStore = useCollectionsStore();
return { isOpenRef, setOpen, collectionStore }
},
data() {
return {
items: [],
collectionId: this.$route.params.id,
};
},
async created(){
this.setOpen(true)
await this.collectionStore.fetchItems()
this.setOpen(false)
},
}
</script>

View File

@ -11,7 +11,7 @@
<ion-title> {{ pageTitle }} </ion-title>
</ion-toolbar>
<ion-toolbar>
<ion-title> Login: {{collectionsStore.userLogin }} Senha: {{collectionsStore.userPassword }} </ion-title>
<ion-title> Login: {{collectionStore.userLogin }} Senha: {{collectionStore.userPassword }} </ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
@ -23,7 +23,7 @@
<script>
import {
useCollectionsStore
} from '../../store/storeCollections';
} from '../../store/storeCollection';
import {
IonPage,
IonHeader,
@ -49,9 +49,9 @@ export default {
},
setup(){
const image = computed (() => require('../../assets/logo.png'))
let collectionsStore = useCollectionsStore();
let collectionStore = useCollectionsStore();
return {
image, collectionsStore,
image, collectionStore,
}
}

View File

@ -7,7 +7,7 @@
>
</ion-loading>
<ion-list>
<ion-item v-for="collection of collectionsStore.collections" :key="collection.id" :router-link="`/collections/${collection.id}`">
<ion-item v-for="collection of collectionStore.collections" :key="collection.id" :router-link="`/collections/${collection.id}`">
<ion-thumbnail slot="start">
<ion-img v-if="collection.thumbnail.thumbnail[0]" :src="collection.thumbnail.thumbnail[0]" :alt="collection.name"></ion-img>
<ion-img v-else :src="image" :alt="collection.name"></ion-img>
@ -21,7 +21,7 @@
<script lang="ts">
import {
useCollectionsStore
} from '../store/storeCollections';
} from '../store/storeCollection';
import {
IonList,
IonItem,
@ -46,13 +46,13 @@ export default {
const image = computed (() => require('../assets/placeholder_square_small.png'))
const isOpenRef = ref(false);
const setOpen = (state: boolean) => isOpenRef.value = state;
let collectionsStore = useCollectionsStore();
return { image, isOpenRef, setOpen, collectionsStore }
let collectionStore = useCollectionsStore();
return { image, isOpenRef, setOpen, collectionStore }
},
async created(){
this.setOpen(true);
await this.collectionsStore.fetchFullCollections();
await this.collectionStore.fetchFullCollections();
this.setOpen(false);
},
}

View File

@ -1,7 +1,5 @@
<template>
<base-layout>
<ion-button expand="block" @click="openPage">Acessar WordPress</ion-button>
<ion-toolbar>
<ion-label>Coleções</ion-label>
</ion-toolbar>
@ -20,8 +18,8 @@
</template>
<script>
import BaseCollectionList from '@/components/base/BaseCollectionList.vue';
import BaseItemList from '@/components/base/BaseItemList.vue';
import BaseCollectionList from '@/components/CollectionList.vue';
import BaseItemList from '@/components/ItemList.vue';
import BaseLayout from '@/components/base/BaseLayout.vue';

View File

@ -6,7 +6,7 @@
message="Carregando..."
>
</ion-loading>
<ion-card v-for="item of collectionsStore.items" :key="item.id">
<ion-card v-for="item of collectionStore.items" :key="item.id">
<ion-card-title v-if="item.title"> {{ item.title }} </ion-card-title>
<ion-card-title v-else>Item não possui título</ion-card-title>
<ion-card-content>
@ -19,7 +19,7 @@
<script lang="ts">
import {
useCollectionsStore
} from '../store/storeCollections';
} from '../store/storeCollection';
import {
IonCard,
IonLoading,
@ -35,8 +35,8 @@ export default {
setup() {
const isOpenRef = ref(false);
const setOpen = (state: boolean) => isOpenRef.value = state;
let collectionsStore = useCollectionsStore();
return { isOpenRef, setOpen, collectionsStore }
let collectionStore = useCollectionsStore();
return { isOpenRef, setOpen, collectionStore }
},
data() {
@ -48,7 +48,7 @@ export default {
async created(){
this.setOpen(true)
await this.collectionsStore.fetchItemsByCollection(this.collectionId)
await this.collectionStore.fetchItemsByCollection(this.collectionId)
this.setOpen(false)
},
}

View File

@ -6,7 +6,7 @@
message="Carregando..."
>
</ion-loading>
<ion-card v-for="item of collectionsStore.items" :key="item.id">
<ion-card v-for="item of collectionStore.items" :key="item.id">
<ion-card-title v-if="item.title"> {{ item.title }} </ion-card-title>
<ion-card-title v-else>Item não possui título</ion-card-title>
<ion-card-content>
@ -19,7 +19,7 @@
<script lang="ts">
import {
useCollectionsStore
} from '../store/storeCollections';
} from '../store/storeCollection';
import {
IonCard,
IonLoading,
@ -35,8 +35,8 @@ export default {
setup() {
const isOpenRef = ref(false);
const setOpen = (state: boolean) => isOpenRef.value = state;
let collectionsStore = useCollectionsStore();
return { isOpenRef, setOpen, collectionsStore }
let collectionStore = useCollectionsStore();
return { isOpenRef, setOpen, collectionStore }
},
data() {
return {
@ -47,7 +47,7 @@ export default {
async created(){
this.setOpen(true)
await this.collectionsStore.fetchFullItems()
await this.collectionStore.fetchFullItems()
this.setOpen(false)
},
}

View File

@ -40,9 +40,9 @@
</template>
<script lang="ts">
import {
useCollectionsStore
} from '../store/storeCollections';
import { useCollectionsStore } from '../store/storeCollection';
import { useUserStore } from '../store/storeUser';
import {
IonImg,
IonList,
@ -68,15 +68,17 @@ export default {
setup(){
const image = computed (() => require('../assets/logoLogin.png'));
let collectionsStore = useCollectionsStore();
return { image, collectionsStore }
let collectionStore = useCollectionsStore();
let userStore = useUserStore();
return { image, collectionStore, userStore }
},
methods: {
login(){
this.collectionsStore.siteUrl = this.siteUrl;
this.collectionsStore.userLogin = this.userLogin;
this.collectionsStore.userPassword = this.userPassword;
this.$router.push('/collections');
async login(){
await this.userStore.userLogin(this.siteUrl);
// this.collectionStore.siteUrl = this.siteUrl;
// this.collectionStore.userLogin = this.userLogin;
// this.collectionStore.userPassword = this.userPassword;
this.$router.push('/homeview');
}
}

View File

@ -1,36 +1,42 @@
import { createRouter, createWebHistory } from '@ionic/vue-router';
import { RouteRecordRaw } from 'vue-router';
import LoginForm from '../pages/LoginForm.vue';
import { useUserStore } from '../store/storeUser'
import HomeView from '../pages/HomeView.vue';
import LoginForm from '../pages/LoginForm.vue';
import ItemsByCollection from '../pages/ItemsByCollection.vue';
import CollectionsFull from '../pages/ColletionsFull.vue';
import ItemsFull from '../pages/ItemsFull.vue';
const routes: Array<RouteRecordRaw> = [
{
path: '/',
redirect: '/home'
redirect: '/homeview'
},
{
path: '/home',
component: LoginForm
path: '/homeview',
component: HomeView,
name: 'homeview'
},
{
path: '/collections',
component: () => import('../pages/HomeCollectionItensList.vue')
path: '/loginform',
component: LoginForm,
name: 'loginform'
},
{
path: '/collections/:id',
component: () => import('../pages/ItemsListbyCollection.vue')
},
{
path: '/collectionsitems',
component: () => import('../pages/HomeCollectionItensList.vue')//mudar
path: '/itemsbycollection/:id',
component: ItemsByCollection,
name: 'itemsbycollection'
},
{
path: '/collectionsfull',
component: () => import('../pages/ColletionsFullList.vue')
component: CollectionsFull,
name: 'collectionsfull'
},
{
path: '/itemsfull',
component: () => import('../pages/ItemsFullList.vue')
component: ItemsFull,
name: 'itemsfull'
}
]
@ -39,4 +45,12 @@ const router = createRouter({
routes
})
router.beforeEach(async(to, from, next) => {
const userStore = useUserStore();
await userStore.checkUserLogin();
if (to.name !== 'loginform' && !userStore.userIsLoggedIn) next({ name: 'loginform' })
else next()
})
export default router

View File

@ -1,5 +1,6 @@
import { defineStore } from 'pinia';
import axios from 'axios';
import { useUserStore } from '../store/storeUser';
const useCollectionsStore = defineStore('collections', {
state () {
@ -15,7 +16,8 @@ const useCollectionsStore = defineStore('collections', {
actions: {
async fetchCollections() {
try {
const response = await axios.get(`${this.siteUrl}/wp-json/tainacan/v2/collections?perpage=4&orderby=modified`);
const userStore = useUserStore();
const response = await axios.get(`${userStore.userSiteUrl}/wp-json/tainacan/v2/collections?perpage=4&orderby=modified`);
this.collections = response.data;
} catch (err) {
this.collections = [];
@ -25,7 +27,8 @@ const useCollectionsStore = defineStore('collections', {
},
async fetchFullCollections() {
try {
const response = await axios.get(`${this.siteUrl}/wp-json/tainacan/v2/collections`);
const userStore = useUserStore();
const response = await axios.get(`${userStore.userSiteUrl}/wp-json/tainacan/v2/collections`);
this.collections = response.data;
} catch (err) {
this.collections = [];
@ -36,8 +39,9 @@ const useCollectionsStore = defineStore('collections', {
async fetchItemsByCollection (collectionId :string) {
try {
const userStore = useUserStore();
this.items = [];
const response = await axios.get(`${this.siteUrl}/wp-json/tainacan/v2/collection/${collectionId}/items?perpage=12&orderby=modified&fetch_only=id,title,thumbnail`);
const response = await axios.get(`${userStore.userSiteUrl}/wp-json/tainacan/v2/collection/${collectionId}/items?perpage=12&orderby=modified&fetch_only=id,title,thumbnail`);
this.items = response.data.items;
} catch (err) {
this.items = [];
@ -48,8 +52,9 @@ const useCollectionsStore = defineStore('collections', {
async fetchItems() {
try {
const userStore = useUserStore();
this.items = [];
const response = await axios.get(`${this.siteUrl}/wp-json/tainacan/v2/items?perpage=12&orderby=modified&fetch_only=id,title,thumbnail`);
const response = await axios.get(`${userStore.userSiteUrl}/wp-json/tainacan/v2/items?perpage=12&orderby=modified&fetch_only=id,title,thumbnail`);
this.items = response.data.items;
} catch (err) {
this.items = [];
@ -60,8 +65,9 @@ const useCollectionsStore = defineStore('collections', {
async fetchFullItems() {
try {
const userStore = useUserStore();
this.items = [];
const response = await axios.get(`${this.siteUrl}/wp-json/tainacan/v2/items?perpage=20&orderby=modified&fetch_only=id,title,thumbnail`);
const response = await axios.get(`${userStore.userSiteUrl}/wp-json/tainacan/v2/items?perpage=20&orderby=modified&fetch_only=id,title,thumbnail`);
this.items = response.data.items;
} catch (err) {
this.items = [];

37
src/store/storeUser.ts Normal file
View File

@ -0,0 +1,37 @@
import { defineStore } from 'pinia';
import { Storage } from '@ionic/storage' ;
const store = new Storage();
const useUserStore = defineStore('users', {
state () {
return {
userIsLoggedIn: false,
userSiteUrl: '',
}
},
actions: {
async userLogin(userSiteUrl: string) {
try {
this.userIsLoggedIn = true;
this.userSiteUrl = userSiteUrl;
await store.set('userIsLoggedIn', true);
await store.set('userSiteUrl', userSiteUrl);
} catch (err) {
this.userIsLoggedIn = false;
await store.set('userIsLoggedIn', false);
console.error('Erro no login:', err);
return err;
}
},
async checkUserLogin() {
await store.create();
this.userIsLoggedIn = await store.get('userIsLoggedIn');
this.userSiteUrl = await store.get('userSiteUrl');
}
}
})
export {
useUserStore
}