@ -19,12 +19,12 @@
< / span >
< / span >
< div class = "m-2" >
< div class = "m-2" >
< span v-if ="currentIdeaIndex < IDEAS.length " >
< span v-if ="currentCategory === CATEGORY_IDEAS " >
< p class = "text-center text-lg font-bold" >
< p class = "text-center text-lg font-bold" >
{ { IDEAS [ currentIdeaIndex ] } }
{ { IDEAS [ currentIdeaIndex ] } }
< / p >
< / p >
< / span >
< / span >
< div v-if ="currentIdeaIndex == IDEAS.length + 0 " >
< div v-if ="currentCategory === CATEGORY_CONTACTS " >
< p class = "text-center" >
< p class = "text-center" >
< span
< span
v - if = "currentContact == null"
v - if = "currentContact == null"
@ -61,7 +61,7 @@
< / span >
< / span >
< button
< button
class = "block w-full text-center text-md uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md mt-4"
class = "block w-full text-center text-md uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md mt-4"
@ click = "cancel "
@ click = "proceed "
>
>
That ' s it !
That ' s it !
< / button >
< / button >
@ -71,150 +71,168 @@
< script lang = "ts" >
< script lang = "ts" >
import { Vue , Component } from "vue-facing-decorator" ;
import { Vue , Component } from "vue-facing-decorator" ;
import { Router } from "vue-router" ;
import { AppString , NotificationIface } from "@/constants/app" ;
import { AppString , NotificationIface } from "@/constants/app" ;
import { db } from "@/db/index" ;
import { db } from "@/db/index" ;
import { Contact } from "@/db/tables/contacts" ;
import { Contact } from "@/db/tables/contacts" ;
import { GiverReceiverInputInfo } from "@/libs/util" ;
@ Component
@ Component
export default class GivenPrompts extends Vue {
export default class GivenPrompts extends Vue {
$notify ! : ( notification : NotificationIface , timeout ? : number ) => void ;
$notify ! : ( notification : NotificationIface , timeout ? : number ) => void ;
CATEGORY_CONTACTS = 1 ;
CATEGORY_IDEAS = 0 ;
IDEAS = [
IDEAS = [
"Did anyone fix food for you?" ,
"What food did someone fix for you?" ,
"Did a family member do something for you?" ,
"What did a family member do for you?" ,
"Did anyone give you a compliment ?" ,
"What compliment did someone give you ?" ,
"Who is someone you can always rely on, and how did they demonstrate that?" ,
"Who is someone you can always rely on, and how did they demonstrate that?" ,
"Did you see any one give to someone else?" ,
"What did you see some one give to someone else?" ,
"Is there someone who you have never met who has helped you somehow ?" ,
"What is a way that someone helped you even though you have never met ?" ,
"How did an artist or musician or author inspire you?" ,
"How did a musician or author or artist inspire you?" ,
"What inspiration did you get from someone who handled tragedy well?" ,
"What inspiration did you get from someone who handled tragedy well?" ,
"Did some organization give something worth respect ?" ,
"What is something worth respect that an organization gave you ?" ,
"Who last gave you a good laugh?" ,
"Who last gave you a good laugh?" ,
"Do you recall anything that was given to you while you were young?" ,
"What do you recall someone giving you while you were young?" ,
"Did someone forgive you or overlook a mistake?" ,
"Who forgave you or overlooked a mistake?" ,
"Do you know of a way an ancestor contributed to your life?" ,
"What is a way an ancestor contributed to your life?" ,
"Did anyone give you help at work ?" ,
"What kind of help did someone at work give you ?" ,
"How did a teacher or mentor or great example help you?" ,
"How did a teacher or mentor or great example help you?" ,
] ;
] ;
OTHER_PROMPTS = 1 ;
CONTACT_PROMPT_INDEX = this . IDEAS . length ; / / e x p e c t e d a f t e r o t h e r p r o m p t s
callbackOnFullGiftInfo ? : (
contactInfo ? : GiverReceiverInputInfo ,
description ? : string ,
) => void ;
currentCategory = this . CATEGORY_IDEAS ; / / 0 = I D E A S , 1 = C O N T A C T S
currentContact : Contact | undefined = undefined ;
currentContact : Contact | undefined = undefined ;
currentIdeaIndex = 0 ;
currentIdeaIndex = 0 ;
numContacts = 0 ;
numContacts = 0 ;
shownContactDbIndices : number [ ] = [ ] ;
shownContactDbIndices : Array < boolean > = [ ] ;
visible = false ;
visible = false ;
AppString = AppString ;
AppString = AppString ;
async open ( ) {
async open (
callbackOnFullGiftInfo : (
contactInfo : GiverReceiverInputInfo ,
description : string ,
) => void ,
) {
this . visible = true ;
this . visible = true ;
this . callbackOnFullGiftInfo = callbackOnFullGiftInfo ;
await db . open ( ) ;
await db . open ( ) ;
this . numContacts = await db . contacts . count ( ) ;
this . numContacts = await db . contacts . count ( ) ;
this . shownContactDbIndices = new Array < boolean > ( this . numContacts ) ; / / a l l u n d e f i n e d t o s t a r t
}
}
close ( ) {
cancel ( ) {
/ / c l o s e t h e d i a l o g b u t d o n ' t c h a n g e v a l u e s ( j u s t i n c a s e s o m e a c t i o n s a r e a d d e d l a t e r )
this . currentCategory = this . CATEGORY_IDEAS ;
this . currentContact = undefined ;
this . currentIdeaIndex = 0 ;
this . numContacts = 0 ;
this . shownContactDbIndices = [ ] ;
this . visible = false ;
this . visible = false ;
}
}
proceed ( ) {
/ / p r o c e e d w i t h l o g i c b u t d o n ' t c h a n g e v a l u e s ( j u s t i n c a s e s o m e a c t i o n s a r e a d d e d l a t e r )
this . visible = false ;
if ( this . currentCategory === this . CATEGORY_IDEAS ) {
( this . $router as Router ) . push ( {
name : "contact-gift" ,
query : {
prompt : this . IDEAS [ this . currentIdeaIndex ] ,
} ,
} ) ;
} else {
/ / m u s t b e t h i s . C A T E G O R Y _ C O N T A C T S
this . callbackOnFullGiftInfo ? . (
this . currentContact as GiverReceiverInputInfo ,
) ;
}
}
/ * *
/ * *
* Get the next idea .
* Get the next idea .
* If it is a contact prompt , loop through .
* If it is a contact prompt , loop through .
* /
* /
async nextIdea ( ) {
async nextIdea ( ) {
/ / i f w e ' r e i n c r e m e n t i n g t o t h e c o n t a c t p r o m p t
/ / c h e c k i f t h e n e x t o n e i s a n i d e a o r a c o n t a c t
/ / o r i f w e ' r e a t t h e c o n t a c t p r o m p t a n d t h e r e w a s a p r e v i o u s c o n t a c t . . .
if ( this . currentCategory === this . CATEGORY_IDEAS ) {
if (
this . currentIdeaIndex ++ ;
this . currentIdeaIndex == this . CONTACT_PROMPT_INDEX - 1 ||
if ( this . currentIdeaIndex === this . IDEAS . length ) {
( this . currentIdeaIndex == this . CONTACT_PROMPT_INDEX &&
/ / m u s t h a v e j u s t f i n i s h e d i d e a s s o m o v e t o c o n t a c t s
this . shownContactDbIndices . length < this . numContacts )
this . findNextUnshownContact ( ) ;
) {
}
this . currentIdeaIndex = this . CONTACT_PROMPT_INDEX ;
this . findNextUnshownContact ( ) ;
} else {
} else {
/ / w e ' r e n o t a t t h e c o n t a c t p r o m p t ( o r w e r a n o u t ) , s o i n c r e m e n t t h e i d e a i n d e x
/ / m u s t b e t h i s . C A T E G O R Y _ C O N T A C T S
this . currentIdeaIndex =
this . findNextUnshownContact ( ) ;
( this . currentIdeaIndex + 1 ) % ( this . IDEAS . length + this . OTHER_PROMPTS ) ;
/ / w h e n t h a t ' s f i n i s h e d , i t ' l l r e s e t t o i d e a s
/ / . . . a n d c l e a r o u t a n y o t h e r p r o m p t i n f o
this . currentContact = undefined ;
this . shownContactDbIndices = [ ] ;
}
}
}
}
prevIdea ( ) {
/ * *
if (
* Get the previous idea .
this . currentIdeaIndex ==
* If it is a contact prompt , loop through .
( this . CONTACT_PROMPT_INDEX + 1 ) %
* /
( this . IDEAS . length + this . OTHER_PROMPTS ) ||
async prevIdea ( ) {
( this . currentIdeaIndex == this . CONTACT_PROMPT_INDEX &&
/ / c h e c k i f t h e n e x t o n e i s a n i d e a o r a c o n t a c t
this . shownContactDbIndices . length < this . numContacts )
if ( this . currentCategory === this . CATEGORY_IDEAS ) {
) {
this . currentIdeaIndex = this . CONTACT_PROMPT_INDEX ;
this . findNextUnshownContact ( ) ;
} else {
/ / w e ' r e n o t a t t h e c o n t a c t p r o m p t ( o r w e r a n o u t ) , s o i n c r e m e n t t h e i d e a i n d e x
this . currentIdeaIndex -- ;
this . currentIdeaIndex -- ;
if ( this . currentIdeaIndex < 0 ) {
if ( this . currentIdeaIndex < 0 ) {
this . currentIdeaIndex = this . IDEAS . length - 1 + this . OTHER_PROMPTS ;
/ / m u s t h a v e j u s t f i n i s h e d i d e a s s o m o v e t o c o n t a c t s
this . findNextUnshownContact ( ) ;
}
}
/ / . . . a n d c l e a r o u t a n y o t h e r p r o m p t i n f o
} else {
this . currentContact = undefined ;
/ / m u s t b e t h i s . C A T E G O R Y _ C O N T A C T S
this . shownContactDbIndices = [ ] ;
this . findNextUnshownContact ( ) ;
/ / w h e n t h a t ' s f i n i s h e d , i t ' l l r e s e t t o i d e a s
}
}
}
}
nextIdeaPastContacts ( ) {
nextIdeaPastContacts ( ) {
this . currentIdeaIndex = 0 ;
this . currentContact = undefined ;
this . currentContact = undefined ;
this . shownContactDbIndices = [ ] ;
this . shownContactDbIndices = new Array < boolean > ( this . numContacts ) ;
this . currentCategory = this . CATEGORY_IDEAS ;
/ / l o o k a t t h e p r e v i o u s i d e a a n d s w i t c h t o t h e o t h e r s i d e o f t h e l i s t
this . currentIdeaIndex =
this . currentIdeaIndex >= this . IDEAS . length ? 0 : this . IDEAS . length - 1 ;
}
}
async findNextUnshownContact ( ) {
async findNextUnshownContact ( ) {
/ / g e t a r a n d o m c o n t a c t
if ( this . currentCategory === this . CATEGORY_IDEAS ) {
if ( this . shownContactDbIndices . length === this . numContacts ) {
/ / w e ' r e n o t i n t h e c o n t a c t p r o m p t s , s o r e s e t i n d e x a r r a y
/ / n o m o r e c o n t a c t s t o s h o w
this . shownContactDbIndices = new Array < boolean > ( this . numContacts ) ;
this . currentContact = undefined ;
}
} else {
this . currentCategory = this . CATEGORY_CONTACTS ;
/ / g e t a r a n d o m c o n t a c t t h a t h a s n ' t b e e n s h o w n y e t
let someContactDbIndex = Math . floor ( Math . random ( ) * this . numContacts ) ;
/ / a n d g u a r a n t e e t h a t o n e i s f o u n d b y w a l k i n g p a s t s h o w n c o n t a c t s
let shownContactIndex =
this . shownContactDbIndices . indexOf ( someContactDbIndex ) ;
while ( shownContactIndex !== - 1 ) {
/ / i n c r e m e n t b o t h i n d i c e s u n t i l w e f i n d a s p o t w h e r e " s h o w n " s k i p s a s p o t
shownContactIndex = ( shownContactIndex + 1 ) % this . numContacts ;
someContactDbIndex = ( someContactDbIndex + 1 ) % this . numContacts ;
if (
this . shownContactDbIndices [ shownContactIndex ] !== someContactDbIndex
) {
/ / w e f o u n d a c o n t a c t t h a t h a s n ' t b e e n s h o w n y e t
break ;
}
/ / c o n t i n u e
/ / . . . a n d t h e r e m u s t b e a t l e a s t o n e b e c a u s e s h o w n C o n t a c t D b I n d i c e s l e n g t h < n u m C o n t a c t s
}
this . shownContactDbIndices . push ( someContactDbIndex ) ;
this . shownContactDbIndices . sort ( ) ;
let someContactDbIndex = Math . floor ( Math . random ( ) * this . numContacts ) ;
let count = 0 ;
/ / a s l o n g a s t h e i n d e x h a s a n e n t r y , l o o p
while (
this . shownContactDbIndices [ someContactDbIndex ] != null &&
count ++ < this . numContacts
) {
someContactDbIndex = ( someContactDbIndex + 1 ) % this . numContacts ;
}
if ( count >= this . numContacts ) {
/ / a l l c o n t a c t s h a v e b e e n s h o w n
this . nextIdeaPastContacts ( ) ;
} else {
/ / g e t t h e c o n t a c t a t t h a t o f f s e t
/ / g e t t h e c o n t a c t a t t h a t o f f s e t
await db . open ( ) ;
await db . open ( ) ;
this . currentContact = await db . contacts
this . currentContact = await db . contacts
. offset ( someContactDbIndex )
. offset ( someContactDbIndex )
. first ( ) ;
. first ( ) ;
this . shownContactDbIndices [ someContactDbIndex ] = true ;
}
}
}
}
cancel ( ) {
this . currentContact = undefined ;
this . currentIdeaIndex = 0 ;
this . numContacts = 0 ;
this . shownContactDbIndices = [ ] ;
this . close ( ) ;
}
}
}
< / script >
< / script >