fix Saldo when press refuse coins.

fix Risolvere problema del ritardo quando si fa il primo login...
This commit is contained in:
Paolo Arena
2022-09-16 17:39:28 +02:00
parent a194acfc69
commit 78a79e1ad5
53 changed files with 3779 additions and 3498 deletions

View File

@@ -0,0 +1,36 @@
.list {
max-width: 400px;
}
.item > img.item-primary:not(.thumbnail) {
border-radius: 10px !important;
}
.item > img.item-primary {
width: 48px;
height: 46px;
}
.item > .item-secondary {
width: 57px;
font-size: 13px;
}
.unread {
}
.unread-date {
color: royalblue;
font-weight: 600;
}
.read {
color: grey;
}
.my-custom-toggle {
border: 1px solid #027be3;
}

View File

@@ -0,0 +1,193 @@
import { computed, defineComponent, onMounted, ref, watch } from 'vue'
import {
IChat,
IMessage, IMsgUsers, INotif,
} from '@model'
import { date } from 'quasar'
import { tools } from '@src/store/Modules/tools'
import { useRouter } from 'vue-router'
import MixinUsers from '../../../mixins/mixin-users'
import { useNotifStore } from '@store/NotifStore'
import { useUserStore } from '@store/UserStore'
import { CTitleBanner } from '@/components/CTitleBanner'
import { CMyFieldRec } from '@/components/CMyFieldRec'
import { CMyFieldDb } from '@/components/CMyFieldDb'
import { CMyCircuits } from '@/components/CMyCircuits'
import { CFinder } from '@/components/CFinder'
import { shared_consts } from '@/common/shared_vuejs'
import { useI18n } from '@/boot/i18n'
import { useQuasar } from 'quasar'
import { costanti } from '@costanti'
import { toolsext } from '@store/Modules/toolsext'
import { useGlobalStore } from '@store/globalStore'
export default defineComponent({
name: 'coinsPopover',
components: { CTitleBanner, CMyFieldRec, CMyFieldDb, CMyCircuits, CFinder },
emits: ['update:modelValue'],
props: {
modelValue: {
required: true,
type: [String, Number, Boolean],
}
},
setup(props, { emit }) {
const $router = useRouter()
const userStore = useUserStore()
const notifStore = useNotifStore()
const globalStore = useGlobalStore()
const { t } = useI18n()
const q = useQuasar()
const loading = ref(false)
const myuser = ref({})
const filter = ref(costanti.MY_CIRCUITS)
const show_all = ref(true)
const username = computed(() => userStore.my.username)
const getlasts_coins = computed(() => notifStore.getlasts_coins().filter((rec) => show_all.value ? true : !rec.read))
const num_notifs_unread = computed(() => notifStore.getnumCoinsUnread())
const notifsel = ref(<INotif>{
dest: '',
datenotif: new Date()
})
const open = computed({
get() {
return props.modelValue
},
set(value) {
return emit('update:modelValue', value)
}
})
const { getNumNotifUnread, getNumNotif, getUsernameChatByNotif, getImgByNotif, getNotifText, getTypeDirNotif, getTypeIdNotif } = MixinUsers()
// function getlasts_coins (state: IUserState) => IMessage[] {
//
// }
watch(() => userStore.my.username, async (to: any, from: any) => {
if (userStore.my.username) {
await refreshdata(userStore.my.username)
}
})
watch(() => notifStore.updateNotification, async (to: any, from: any) => {
if (notifStore.updateNotification) {
await refreshdata(userStore.my.username)
}
})
function clickNotif(notif: INotif) {
if (notif.openUrl) {
let mylink = tools.updateQueryStringParameter(notif.openUrl, 'idnotif', notif._id)
console.log('mylink', mylink, notif._id)
if (mylink) {
$router.replace(mylink)
}
}
}
function getlastnotif(username: string): any {
// Get msg for this chat
if (notifStore.last_notifs)
return notifStore.last_notifs.find((rec: INotif) => rec.dest === username)
// return users_msg_saved[username]
}
function getlastdataread(username: string): any {
// Get msg for this
let myrec = getlastnotif(username)
const lastdata: any = (myrec && myrec.lastdataread) ? myrec.lastdataread : tools.getLastDateReadReset()
let mydate = ''
if (!tools.isIsoDate(lastdata))
mydate = lastdata.toISOString()
else
return lastdata
// console.log('getlastdataread', mydate)
return mydate
}
async function refreshdata(username: string) {
try {
if (!!username) {
notifsel.value.dest = ''
console.log('refreshdata')
loading.value = true
return notifStore.updateNotifDataFromServer({
username,
lastdataread: getlastdataread(username)
}).then((ris) => {
notifStore.updateNotification = false
notifsel.value.dest = username
loading.value = false
const element = document.getElementById('last')
tools.scrollToElement(element)
// changemsgs('', '')
}).catch((err) => {
console.error(' refreshdata', err)
loading.value = false
})
}
} catch (e) {
console.error(' refreshdata', e)
loading.value = false
}
}
async function mounted() {
myuser.value = userStore.my
await refreshdata(userStore.my.username)
}
onMounted(mounted)
return {
getlasts_coins,
num_notifs_unread,
clickNotif,
getNumNotifUnread,
getNumNotif,
getUsernameChatByNotif,
getImgByNotif,
getNotifText,
getTypeDirNotif,
getTypeIdNotif,
tools,
shared_consts,
myuser,
costanti,
toolsext,
open,
notifStore,
show_all,
t,
username,
userStore,
q,
filter,
}
},
})

View File

@@ -0,0 +1,196 @@
<template>
<div>
<q-btn flat round dense icon="fas fa-coins" class="q-mx-xs" @click="open = !open">
<q-badge v-if="num_notifs_unread > 0" floating color="red">{{ num_notifs_unread }}</q-badge>
</q-btn>
<q-btn v-if="false" flat round dense icon="fas fa-coins">
<q-badge v-if="num_notifs_unread > 0" floating color="red">{{ num_notifs_unread }}</q-badge>
</q-btn>
<q-drawer v-model="open" side="right" elevated class="text-black"
:overlay="true"
:breakpoint="1200"
:width="q.screen.lt.sm ? tools.getwidth($q) : 450"
>
<q-bar class="bg-primary text-white">
{{ $t('notifs.coins') }}
<q-space/>
<q-btn round dense icon="fas fa-pencil-alt" class="q-mx-xs">
<q-menu style="min-width: 200px">
<q-list style="">
<q-item clickable v-close-popup to="/notifs">
<q-item-section side>
<q-icon name="fas fa-cog"/>
</q-item-section>
<q-item-section>{{ $t('notifs.settings') }}</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="notifStore.setAllRead(username, shared_consts.QualiNotifs.CIRCUITS)">
<q-item-section side>
<q-icon name="fas fa-check"/>
</q-item-section>
<q-item-section>{{ $t('notifs.setallread') }}</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="notifStore.deleteAll(username, shared_consts.QualiNotifs.CIRCUITS)">
<q-item-section side>
<q-icon name="fas fa-trash-alt"/>
</q-item-section>
<q-item-section>{{ $t('notifs.deleteall') }}</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
<q-btn flat round color="white" icon="close" @click="open = false"></q-btn>
</q-bar>
<CMyCircuits
v-model="filter"
:finder="true"
:showfinder="true"
>
<CFinder
:table="toolsext.TABCIRCUITS"
:noButtAdd="true"
:showFilterPersonal="false"
/>
</CMyCircuits>
<div class="row justify-center margin_buttons q-gutter-lg">
<q-btn-toggle
v-model="show_all"
class="my-custom-toggle"
no-caps
rounded
dense
unelevated
toggle-color="primary"
color="white"
text-color="primary"
:options="[
{label: t('notifs.all'), value: true},
{label: t('notifs.notread'), value: false}
]"
/>
</div>
<div class="clBorderSperator"></div>
<div class="q-ma-xs">
<q-list bordered class="rounded-borders">
<div v-if="num_notifs_unread === 0">
<q-item>
<q-item-label lines="1">{{ $t('notifs.nocoins') }}</q-item-label>
</q-item>
</div>
<q-item clickable v-for="(notif, index) in getlasts_coins" :key="index">
<!--<q-item-section avatar>
<q-avatar>
<q-item-label lines="1">{{ getTypeDirNotif(notif) }}</q-item-label>
</q-avatar>
</q-item-section>-->
<q-item-section avatar>
<q-avatar>
<img :src="notif.myimgsender" :alt="notif.sender">
</q-avatar>
</q-item-section>
<q-item-section v-ripple>
<q-item-label lines="5" :class="(!notif.read) ? 'unread' : 'read'" @click="clickNotif(notif)">
<div v-html="getNotifText($t, notif, false)"></div>
</q-item-label>
<q-item-label caption lines="2"
v-if="notif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS && notif.status === 0 && notif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER"
v-ripple>
<div class="row no-wrap justify-evenly" v-if="tools.iAmAdminCircuit(notif.extrafield)">
<q-btn
dense
rounded
size="sm"
icon="fas fa-user-plus"
color="positive" :label="$t('circuit.accept')"
@click="tools.addToMyCircuits(q, notif.sender, notif.extrafield)"
/>
<q-btn
dense
rounded
size="sm"
icon="fas fa-user-minus"
color="negative" :label="$t('shared.refuse_ask')"
@click="tools.refuseReqCircuit(q, notif.sender, notif.extrafield)"
/>
</div>
</q-item-label>
<q-item-label caption lines="2"
v-if="notif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS && notif.status === 0 && notif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ" v-ripple>
<div class="row no-wrap justify-evenly">
<q-btn
dense
rounded
size="sm"
icon="fas fa-user-plus"
color="positive" :label="$t('circuit.accept_coins')"
@click="tools.acceptCoins(q, notif.sender, notif)"
/>
<q-btn
dense
rounded
size="sm"
icon="fas fa-user-minus"
color="negative" :label="$t('circuit.refuse_coins')"
@click="tools.refuseCoins(q, notif.sender, notif)"
/>
</div>
</q-item-label>
<q-item-label caption lines="1" :class="(!notif.read) ? 'unread-date' : 'read-date'" @click="clickNotif(notif)">
{{ tools.timeAgo(notif.datenotif) }}
<!--{{ // getUsernameChatByNotif(notif) }}-->
</q-item-label>
</q-item-section>
<q-item-section side>
<q-item-label>
<q-btn dense rounded icon="fas fa-ellipsis-h">
<q-menu>
<q-list style="min-width: 150px">
<q-item clickable v-close-popup @click="notifStore.deleteRec(username, notif._id)">
<q-item-section side>
<q-icon name="fas fa-trash-alt"/>
</q-item-section>
<q-item-section>{{ $t('notifs.delete_notif') }}</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="notifStore.deactivateRec(notif._id)">
<q-item-section side>
<q-icon name="fas fa-bell-slash"/>
</q-item-section>
<q-item-section>{{ $t('notifs.deactivate_notif') }}</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
</q-item-label>
</q-item-section>
</q-item>
<q-separator/>
</q-list>
</div>
</q-drawer>
</div>
</template>
<script lang="ts" src="./coinsPopover.ts">
</script>
<style lang="scss" scoped>
@import './coinsPopover.scss';
</style>

View File

@@ -12,6 +12,7 @@ import { tools } from '@src/store/Modules/tools'
import { useRouter } from 'vue-router'
import MixinUsers from '../../../mixins/mixin-users'
import { useNotifStore } from '@store/NotifStore'
import { useGlobalStore } from '@store/globalStore'
import { useUserStore } from '@store/UserStore'
import { CTitleBanner } from '@/components/CTitleBanner'
@@ -38,6 +39,7 @@ export default defineComponent({
const $router = useRouter()
const userStore = useUserStore()
const notifStore = useNotifStore()
const globalStore = useGlobalStore()
const { t } = useI18n()
const q = useQuasar()
@@ -51,9 +53,7 @@ export default defineComponent({
const lasts_notifs = computed(() => notifStore.getlasts_notifs().filter((rec) => show_all.value ? true : !rec.read))
const num_notifs_unread = computed(() => notifStore.getnumNotifUnread())
const usernotifs = computed(() => userStore.my.profile.notifs)
const userId = ref('')
// const usernotifs = computed(() => userStore.my.profile.notifs)
const polling = ref(<any> null)
const eseguipolling = ref(true)
@@ -89,10 +89,10 @@ export default defineComponent({
console.log('checkifpolling')
if (eseguipolling.value) {
if (!polling.value) {
console.log('esegui POLLING....')
console.log('esegui POLLING 2....')
polling.value = setInterval(() => {
checkIfArrivedSomeNotif()
}, 3000)
}, 2000)
}
}
}
@@ -103,19 +103,17 @@ export default defineComponent({
clearInterval(polling.value)
}
/*
watch(() => usernotifs.value, async (to: any, from: any) => {
if (usernotifs.value) {
console.log('usernotifs.value', usernotifs.value, to)
const ret = await userStore.setUserNotifs(usernotifs.value)
/*if (ret) {
tools.showPositiveNotif(q, t('db.recupdated'))
} else {
tools.showNegativeNotif(q, t('db.recfailed'))
}*/
}
})
*/
watch(() => userStore.my.username, async (to: any, from: any) => {
if (userStore.my.username) {
await refreshdata(userStore.my.username)
@@ -163,31 +161,38 @@ export default defineComponent({
async function refreshdata(username: string) {
console.log('refreshdata')
loading.value = true
userId.value = userStore.my._id
try {
if (globalStore.finishLoading) {
notifsel.value.dest = ''
if (!!username) {
if (!!username) {
notifsel.value.dest = ''
console.log('refreshdata')
loading.value = true
return notifStore.updateNotifDataFromServer({
username,
lastdataread: getlastdataread(username)
}).then((ris) => {
return notifStore.updateNotifDataFromServer({
username,
lastdataread: getlastdataread(username)
}).then((ris) => {
notifStore.updateNotification = false
notifsel.value.dest = username
loading.value = false
notifStore.updateNotification = false
notifsel.value.dest = username
loading.value = false
const element = document.getElementById('last')
tools.scrollToElement(element)
const element = document.getElementById('last')
tools.scrollToElement(element)
// changemsgs('', '')
// changemsgs('', '')
}).catch((err) => {
loading.value = false
})
}).catch((err) => {
console.error(' refreshdata', err)
loading.value = false
})
}
}
} catch (e) {
console.error(' refreshdata', e)
loading.value = false
}
}
@@ -211,9 +216,7 @@ export default defineComponent({
getTypeDirNotif,
getTypeIdNotif,
tools,
usernotifs,
shared_consts,
userId,
myuser,
costanti,
open,

View File

@@ -25,13 +25,13 @@
</q-item-section>
<q-item-section>{{ $t('notifs.settings') }}</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="notifStore.setAllRead(username)">
<q-item clickable v-close-popup @click="notifStore.setAllRead(username, shared_consts.QualiNotifs.OTHERS)">
<q-item-section side>
<q-icon name="fas fa-check"/>
</q-item-section>
<q-item-section>{{ $t('notifs.setallread') }}</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="notifStore.deleteAll(username)">
<q-item clickable v-close-popup @click="notifStore.deleteAll(username, shared_consts.QualiNotifs.OTHERS)">
<q-item-section side>
<q-icon name="fas fa-trash-alt"/>
</q-item-section>
@@ -135,51 +135,6 @@
/>
</div>
</q-item-label>
<q-item-label caption lines="2"
v-else-if="notif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS && notif.status === 0 && notif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER"
v-ripple>
<div class="row no-wrap justify-evenly" v-if="tools.iAmAdminCircuit(notif.extrafield)">
<q-btn
dense
rounded
size="sm"
icon="fas fa-user-plus"
color="positive" :label="$t('circuit.accept')"
@click="tools.addToMyCircuits(q, notif.sender, notif.extrafield)"
/>
<q-btn
dense
rounded
size="sm"
icon="fas fa-user-minus"
color="negative" :label="$t('shared.refuse_ask')"
@click="tools.refuseReqCircuit(q, notif.sender, notif.extrafield)"
/>
</div>
</q-item-label>
<q-item-label caption lines="2"
v-else-if="notif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS && notif.status === 0 && notif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ" v-ripple>
<div class="row no-wrap justify-evenly">
<q-btn
dense
rounded
size="sm"
icon="fas fa-user-plus"
color="positive" :label="$t('circuit.accept_coins')"
@click="tools.acceptCoins(q, notif.sender, notif)"
/>
<q-btn
dense
rounded
size="sm"
icon="fas fa-user-minus"
color="negative" :label="$t('circuit.refuse_coins')"
@click="tools.refuseCoins(q, notif.sender, notif)"
/>
</div>
</q-item-label>
<q-item-label caption lines="1" :class="(!notif.read) ? 'unread-date' : 'read-date'" @click="clickNotif(notif)">
{{ tools.timeAgo(notif.datenotif) }}