[APP-562] Persist 'copied' state of invite codes (#535)
* Persist 'copied' state of invite codes (close APP-562) * Dont show copied message if invite used
This commit is contained in:
parent
e1fd50d014
commit
f33a355a1a
2 changed files with 57 additions and 40 deletions
|
@ -4,6 +4,7 @@ import {RootStoreModel} from './root-store'
|
|||
import {isObj, hasProp, isStrArray} from 'lib/type-guards'
|
||||
|
||||
export class InvitedUsers {
|
||||
copiedInvites: string[] = []
|
||||
seenDids: string[] = []
|
||||
profiles: AppBskyActorDefs.ProfileViewDetailed[] = []
|
||||
|
||||
|
@ -20,13 +21,20 @@ export class InvitedUsers {
|
|||
}
|
||||
|
||||
serialize() {
|
||||
return {seenDids: this.seenDids}
|
||||
return {seenDids: this.seenDids, copiedInvites: this.copiedInvites}
|
||||
}
|
||||
|
||||
hydrate(v: unknown) {
|
||||
if (isObj(v) && hasProp(v, 'seenDids') && isStrArray(v.seenDids)) {
|
||||
this.seenDids = v.seenDids
|
||||
}
|
||||
if (
|
||||
isObj(v) &&
|
||||
hasProp(v, 'copiedInvites') &&
|
||||
isStrArray(v.copiedInvites)
|
||||
) {
|
||||
this.copiedInvites = v.copiedInvites
|
||||
}
|
||||
}
|
||||
|
||||
async fetch(invites: ComAtprotoServerDefs.InviteCode[]) {
|
||||
|
@ -63,6 +71,16 @@ export class InvitedUsers {
|
|||
}
|
||||
}
|
||||
|
||||
isInviteCopied(invite: string) {
|
||||
return this.copiedInvites.includes(invite)
|
||||
}
|
||||
|
||||
setInviteCopied(invite: string) {
|
||||
if (!this.isInviteCopied(invite)) {
|
||||
this.copiedInvites.push(invite)
|
||||
}
|
||||
}
|
||||
|
||||
markSeen(did: string) {
|
||||
this.seenDids.push(did)
|
||||
this.profiles = this.profiles.filter(profile => profile.did !== did)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue