Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
fix: system badge deprecation warning added
Browse files Browse the repository at this point in the history
  • Loading branch information
villetakanen committed Dec 6, 2021
1 parent 8fb7322 commit 548fc23
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
19 changes: 11 additions & 8 deletions src/state/Storable.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { DocumentData, Timestamp, serverTimestamp } from '@firebase/firestore'

/**
* A class that can be stored in Firestore. We expect each document to have a createdAt and updatedAt field.
*/
export interface StorableDoc {
id: string
created?: Timestamp
updated?: Timestamp
createdAt?: Timestamp
updatedAt?: Timestamp
}

/**
* A helper superclass for entities storable to Firestone
* A helper superclass for business entities storable to Firestore as docs.
*/
export class Storable implements StorableDoc {
private _id: string
Expand All @@ -28,11 +31,11 @@ export class Storable implements StorableDoc {
return this._id
}

get created (): Timestamp|undefined {
get createdAt (): Timestamp|undefined {
return this._created
}

get updated (): Timestamp|undefined {
get updatedAt (): Timestamp|undefined {
return this._updated
}

Expand All @@ -51,9 +54,9 @@ export class Storable implements StorableDoc {
}

compareChangeTime (other:Storable): number {
if (!other.updated) return 1 // other site has no lastUpdate, this is more recent
if (!this.updated) return -1 // this site has no lastUpdate, other is more recent
if (other.updated.toMillis() > this.updated.toMillis()) {
if (!other.updatedAt) return 1 // other site has no lastUpdate, this is more recent
if (!this.updatedAt) return -1 // this site has no lastUpdate, other is more recent
if (other.updatedAt.toMillis() > this.updatedAt.toMillis()) {
return -1
}
return 1
Expand Down
32 changes: 26 additions & 6 deletions src/state/site/Site.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { logDebug, logError } from '@/utils/eventLogger'
import { DocumentData } from '@firebase/firestore'
import { Storable, StorableDoc } from '../Storable'

/**
* Site specific extra fields we want to store in Firestore, with types.
*/
export interface SiteDoc extends StorableDoc {
name?: string
description?: string
Expand All @@ -13,21 +17,25 @@ export interface SiteDoc extends StorableDoc {
theme?: string
}

/**
* A Mekanismi Site object, as a Firestore document.
*
* Helper methods are provided for reactive attributes and for converting to/from Firestore DocumentData.
*/
export class Site extends Storable {
name = ''
description = ''
owners: string[] = []
players: string[] = []
usePlayers = false
hidden = true
usePlayers = false // By default, the Keeper functionality is hidden
hidden = true // By default, this site is not visible in public listings and search
system = ''
systemBadge = ''
private _systemBadge = '' // Deprecated, use system, and theme instead
theme = ''

constructor (site: string|SiteDoc = '', data?: SiteDoc) {
super(site as StorableDoc, data)
const d:SiteDoc = typeof site !== 'string' ? site : data ? { ...data } : { id: site }

this.docData = d
}

Expand All @@ -51,15 +59,27 @@ export class Site extends Storable {
this.owners = doc.owners || []
this.players = doc.players || []
this.usePlayers = doc.usePlayers || false
this.hidden = doc.hidden || false
this.hidden = doc.hidden || true

// Backwards compatibility, remove in future when all sites have the system field set
const s = doc?.system || doc?.systemBadge || ''
this.system = s
this.systemBadge = s
this._systemBadge = s
this.theme = s
}

get systemBadge (): string {
logDebug('Site.systemBadge is deprecated, use Site.system and Site.theme instead')
return this._systemBadge
}

set systemBadge (s:string) {
logDebug('Site.systemBadge is deprecated, use Site.system and Site.theme instead')
this._systemBadge = s
this.theme = s
this.system = s
}

hasOwner (uid:string): boolean {
return this.owners && this.owners.includes(uid)
}
Expand Down

0 comments on commit 548fc23

Please sign in to comment.