crea nueva lista
This commit is contained in:
@@ -14,7 +14,8 @@
|
|||||||
<q-btn color="secondary" label="Menú">
|
<q-btn color="secondary" label="Menú">
|
||||||
<q-menu>
|
<q-menu>
|
||||||
<q-list style="min-width: 100px">
|
<q-list style="min-width: 100px">
|
||||||
<q-item clickable v-close-popup @click="newLista" v-if="router.currentRoute.value.path">
|
<q-item clickable v-close-popup @click="openDialogNewList"
|
||||||
|
v-if="router.currentRoute.value.path == '/'">
|
||||||
<q-item-section>Nueva Lista</q-item-section>
|
<q-item-section>Nueva Lista</q-item-section>
|
||||||
</q-item>
|
</q-item>
|
||||||
<q-separator />
|
<q-separator />
|
||||||
@@ -34,16 +35,38 @@
|
|||||||
<router-view />
|
<router-view />
|
||||||
</q-page-container>
|
</q-page-container>
|
||||||
</q-layout>
|
</q-layout>
|
||||||
|
<q-dialog v-model="dialogNewList" persistent>
|
||||||
|
<q-card style="min-width: 350px">
|
||||||
|
<q-card-section>
|
||||||
|
<div class="text-h6">Nombre de la lista</div>
|
||||||
|
</q-card-section>
|
||||||
|
|
||||||
|
<q-card-section class="q-pt-none">
|
||||||
|
<q-input dense v-model="nameList" autofocus @keyup.enter="dialogNewList = false" />
|
||||||
|
</q-card-section>
|
||||||
|
|
||||||
|
<q-card-actions align="right" class="text-primary">
|
||||||
|
<q-btn flat label="Cancel" v-close-popup />
|
||||||
|
<q-btn flat label="Crear" v-close-popup @click="newLista" :disable="nameList.length < 4" />
|
||||||
|
</q-card-actions>
|
||||||
|
</q-card>
|
||||||
|
</q-dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { ref } from 'vue'
|
||||||
import { supabaseStore } from '../stores/supabaseStore'
|
import { supabaseStore } from '../stores/supabaseStore'
|
||||||
import useSupabase from '../boot/supabase'
|
import useSupabase from '../boot/supabase'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
|
import { useQuasar } from 'quasar'
|
||||||
|
|
||||||
const store = supabaseStore()
|
const store = supabaseStore()
|
||||||
const { supabase } = useSupabase()
|
const { supabase } = useSupabase()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const $q = useQuasar()
|
||||||
|
|
||||||
|
const dialogNewList = ref(false)
|
||||||
|
const nameList = ref('')
|
||||||
|
|
||||||
const logout = async () => {
|
const logout = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -59,7 +82,28 @@ const logout = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const newLista = () => {
|
const newLista = async () => {
|
||||||
console.log(router.currentRoute.value.path)
|
try {
|
||||||
|
const { data, error } = await supabase
|
||||||
|
.from('listas')
|
||||||
|
.insert([
|
||||||
|
{ nombre: nameList.value }
|
||||||
|
])
|
||||||
|
.select()
|
||||||
|
if (error) throw error
|
||||||
|
store.listas.push(data[0])
|
||||||
|
nameList.value = ''
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
$q.notify({
|
||||||
|
type: 'negative',
|
||||||
|
message: error.message
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const openDialogNewList = () => {
|
||||||
|
dialogNewList.value = true
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,23 +1,22 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="full-height window-width row justify-center items-center">
|
<div class="full-height window-width row justify-center items-center">
|
||||||
<q-infinite-scroll @load="onLoad" :offset="250">
|
<q-infinite-scroll @load="onLoad" :offset="250">
|
||||||
<div v-for="(lista, index) in arraylistas" :key="index" class="caption">
|
<div v-for="(lista, index) in store.listas" :key="index" class="caption">
|
||||||
<div class="q-pa-md row items-start q-gutter-md">
|
<div class="q-pa-md row items-start q-gutter-md">
|
||||||
<q-card class="my-card text-white"
|
<q-card class="my-card text-white"
|
||||||
:class="store.user?.email === lista.email_owner ? 'bg-secondary' : 'bg-green-7'">
|
:class="store.user?.email === lista.email_owner ? 'bg-secondary' : 'bg-green-7'">
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<q-badge color="orange" class="text-subtitle2" floating trasparent>{{ lista.items.filter(i =>
|
<q-badge color="orange" class="text-subtitle2" floating trasparent>
|
||||||
!i.is_done).length
|
{{ lista.items ? lista.items.filter(i => !i.is_done).length : '0' }}/{{ lista.items ?
|
||||||
}}/{{
|
lista.items?.length : '0' }}
|
||||||
lista.items.length
|
</q-badge>
|
||||||
}}</q-badge>
|
|
||||||
<div class="text-h5">{{ lista.nombre }}</div>
|
<div class="text-h5">{{ lista.nombre }}</div>
|
||||||
<div class="text-subtitle1">{{ lista.email_owner }}</div>
|
<div class="text-subtitle1">{{ lista.email_owner }}</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
Compartido con:
|
Compartido con:
|
||||||
<span v-if="lista.profiles.length === 0">Nadie</span>
|
<span v-if="!lista.profiles || lista.profiles.length === 0">Nadie</span>
|
||||||
<span v-for="(profile, index) in lista.profiles" :key="index">
|
<span v-for="(profile, index) in lista.profiles" :key="index">
|
||||||
{{ profile.email }}
|
{{ profile.email }}
|
||||||
</span>
|
</span>
|
||||||
@@ -51,7 +50,6 @@ const { supabase } = useSupabase()
|
|||||||
const $q = useQuasar()
|
const $q = useQuasar()
|
||||||
const store = supabaseStore()
|
const store = supabaseStore()
|
||||||
|
|
||||||
let arraylistas = []
|
|
||||||
|
|
||||||
const getListas = async () => {
|
const getListas = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -60,7 +58,7 @@ const getListas = async () => {
|
|||||||
.select(`*, profiles(*),items(is_done)`)
|
.select(`*, profiles(*),items(is_done)`)
|
||||||
if (error) throw error
|
if (error) throw error
|
||||||
console.log('listas', listas)
|
console.log('listas', listas)
|
||||||
arraylistas = listas
|
store.listas = listas
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
$q.notify({
|
$q.notify({
|
||||||
@@ -73,7 +71,7 @@ const getListas = async () => {
|
|||||||
|
|
||||||
const onLoad = (index, done) => {
|
const onLoad = (index, done) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
arraylistas.push()
|
store.listas.push()
|
||||||
done()
|
done()
|
||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ export const supabaseStore = defineStore('supabaseStore', {
|
|||||||
// counter: 0
|
// counter: 0
|
||||||
prueba: 'prueba',
|
prueba: 'prueba',
|
||||||
user: null,
|
user: null,
|
||||||
session: null
|
session: null,
|
||||||
|
listas: [],
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
|
|||||||
Reference in New Issue
Block a user