new Item
This commit is contained in:
@@ -19,6 +19,10 @@
|
|||||||
v-if="router.currentRoute.value.path == '/'">
|
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-item clickable v-close-popup @click="newItem"
|
||||||
|
v-if="router.currentRoute.value.path == `/items/${router.currentRoute.value.params.id}`">
|
||||||
|
<q-item-section>Nuevo Item</q-item-section>
|
||||||
|
</q-item>
|
||||||
<q-separator />
|
<q-separator />
|
||||||
<q-item clickable v-close-popup @click="logout">
|
<q-item clickable v-close-popup @click="logout">
|
||||||
<q-item-section>Logout</q-item-section>
|
<q-item-section>Logout</q-item-section>
|
||||||
@@ -108,4 +112,55 @@ const newLista = async () => {
|
|||||||
const openDialogNewList = () => {
|
const openDialogNewList = () => {
|
||||||
dialogNewList.value = true
|
dialogNewList.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const newItem = () => {
|
||||||
|
const lista = router.currentRoute.value.params.id
|
||||||
|
$q.dialog({
|
||||||
|
title: 'Escriba',
|
||||||
|
message: 'Nuevo item',
|
||||||
|
html: true,
|
||||||
|
prompt: {
|
||||||
|
model: '',
|
||||||
|
isValid: val => val.length > 4, // << here is the magic
|
||||||
|
type: 'text'
|
||||||
|
},
|
||||||
|
ok: {
|
||||||
|
push: true,
|
||||||
|
label: 'Crear',
|
||||||
|
color: 'positive' // << here is the magic
|
||||||
|
},
|
||||||
|
cancel: {
|
||||||
|
push: true,
|
||||||
|
color: 'negative'
|
||||||
|
},
|
||||||
|
persistent: true
|
||||||
|
}).onOk(async (item) => {
|
||||||
|
if (store.items.find(i => i.nombre === item)) {
|
||||||
|
$q.notify({
|
||||||
|
type: 'negative',
|
||||||
|
message: 'Item duplicado'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
console.log(item, lista)
|
||||||
|
const { data, error } = await supabase
|
||||||
|
.from('items')
|
||||||
|
.insert([
|
||||||
|
{ nombre: item, lista_id: lista }
|
||||||
|
])
|
||||||
|
.select()
|
||||||
|
console.log(data)
|
||||||
|
if (error) throw error
|
||||||
|
store.items.push(data[0])
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
$q.notify({
|
||||||
|
type: 'negative',
|
||||||
|
message: error.message
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,23 +1,33 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="q-pa-md mx-auto">
|
<div class="full-height window-width row justify-center items-center">
|
||||||
<q-list v-for="item in store.items" :key="item.id" class="shadow-2 rounded-borders q-mx-md">
|
<q-infinite-scroll @load="onLoad" :offset="250">
|
||||||
<q-item tag="label">
|
<div v-for="(item, index) in store.items" :key="index" class="caption">
|
||||||
<q-item-section>
|
<div class="q-pa-md row items-start q-gutter-md">
|
||||||
<q-item-label class="text-bold text-h5">{{ item.nombre }}<q-btn size="12px" flat dense round
|
|
||||||
icon="edit" /></q-item-label>
|
<q-card class="my-card text-white bg-teal-9">
|
||||||
<q-item-label class="text-bold text-h6">{{ item.cantidad }}<q-btn size="12px"
|
<q-card-section>
|
||||||
class="q-mb-sm q-ml-xs" flat round icon="↑" /><q-btn size="12px" class="q-mb-sm" flat round
|
<div class="text-h6">{{ item.nombre }}
|
||||||
icon="↓" /></q-item-label>
|
<q-icon name="edit" class="cursor-pointer" />
|
||||||
</q-item-section>
|
</div>
|
||||||
<q-item-section avatar>
|
<div class="text-subtitle1">{{ item.cantidad }}</div>
|
||||||
<q-toggle color="blue" v-model="item.is_done" />
|
</q-card-section>
|
||||||
</q-item-section>
|
|
||||||
<q-item-section avatar>
|
<q-separator dark />
|
||||||
<q-btn size="12px" flat dense round icon="delete" />
|
|
||||||
</q-item-section>
|
<q-card-actions>
|
||||||
</q-item>
|
<q-btn flat class="cursor-pointer" />
|
||||||
<q-separator />
|
<q-space></q-space>
|
||||||
</q-list>
|
<q-btn class="bg-negative q-mr-md" flat>Borrar</q-btn>
|
||||||
|
</q-card-actions>
|
||||||
|
</q-card>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<template v-slot:loading>
|
||||||
|
<div class="row justify-center q-my-md">
|
||||||
|
<q-spinner-dots color="primary" size="40px" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</q-infinite-scroll>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -30,6 +40,13 @@ import useSupabase from '../boot/supabase'
|
|||||||
const { supabase } = useSupabase()
|
const { supabase } = useSupabase()
|
||||||
const store = supabaseStore()
|
const store = supabaseStore()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
|
const onLoad = (index, done) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
store.listas.push()
|
||||||
|
done()
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
const getItems = async () => {
|
const getItems = async () => {
|
||||||
console.log('getItems', route.params.id)
|
console.log('getItems', route.params.id)
|
||||||
let { data: items, error } = await supabase
|
let { data: items, error } = await supabase
|
||||||
|
|||||||
Reference in New Issue
Block a user