From c76d790c42fd337517f89c943d7034d19e9ab036 Mon Sep 17 00:00:00 2001 From: Abraham Williams <4braham@gmail.com> Date: Thu, 30 Dec 2021 14:24:32 -0800 Subject: [PATCH 1/2] Update data in realtime --- firestore.indexes.json | 25 +++++++++++- firestore.rules | 12 ++++++ src/models/member.ts | 4 +- src/models/types.ts | 4 ++ src/pages/team-page.ts | 43 +++++++++------------ src/store/index.ts | 4 +- src/store/members/actions.ts | 46 ++++++++++++++++++++++ src/store/members/reducers.ts | 27 +++++++++++++ src/store/members/selectors.ts | 13 +++++++ src/store/members/state.ts | 5 +++ src/store/members/types.ts | 24 ++++++++++++ src/store/speakers/actions.ts | 45 +++++++++++++--------- src/store/teams-members/selectors.ts | 35 +++++++++++++++++ src/store/teams-members/state.ts | 5 +++ src/store/teams/actions.ts | 57 +++++++++++++--------------- src/store/teams/selectors.ts | 13 +++++++ src/store/teams/state.ts | 4 +- src/store/teams/types.ts | 4 +- src/store/tickets/actions.ts | 50 +++++++++++++++--------- src/utils/firestore.ts | 12 +++++- 20 files changed, 332 insertions(+), 100 deletions(-) create mode 100644 src/store/members/actions.ts create mode 100644 src/store/members/reducers.ts create mode 100644 src/store/members/selectors.ts create mode 100644 src/store/members/state.ts create mode 100644 src/store/members/types.ts create mode 100644 src/store/teams-members/selectors.ts create mode 100644 src/store/teams-members/state.ts create mode 100644 src/store/teams/selectors.ts diff --git a/firestore.indexes.json b/firestore.indexes.json index 415027e5dd..4683ba2af9 100644 --- a/firestore.indexes.json +++ b/firestore.indexes.json @@ -1,4 +1,27 @@ { "indexes": [], - "fieldOverrides": [] + "fieldOverrides": [ + { + "collectionGroup": "members", + "fieldPath": "name", + "indexes": [ + { + "order": "ASCENDING", + "queryScope": "COLLECTION" + }, + { + "order": "DESCENDING", + "queryScope": "COLLECTION" + }, + { + "arrayConfig": "CONTAINS", + "queryScope": "COLLECTION" + }, + { + "order": "ASCENDING", + "queryScope": "COLLECTION_GROUP" + } + ] + } + ] } diff --git a/firestore.rules b/firestore.rules index ab127c71e9..fc2bc8187a 100644 --- a/firestore.rules +++ b/firestore.rules @@ -186,6 +186,7 @@ service cloud.firestore { // Disallow writes allow write: if false; + // TODO: remove match /members/{memberId} { // Applies to single document read requests allow get; @@ -198,6 +199,17 @@ service cloud.firestore { } } + match /{path=**}/members/{memberId} { + // Applies to single document read requests + allow get; + + // Applies to queries and collection read requests + allow list; + + // Disallow writes + allow write: if false; + } + match /tickets/{ticket} { // Applies to single document read requests allow get; diff --git a/src/models/member.ts b/src/models/member.ts index 7b5197cde9..8adca1b7dc 100644 --- a/src/models/member.ts +++ b/src/models/member.ts @@ -1,5 +1,5 @@ import { Social } from './social'; -import { Id } from './types'; +import { ParentId } from './types'; export interface MemberData { name: string; @@ -10,4 +10,4 @@ export interface MemberData { title: string; } -export type Member = Id & MemberData; +export type Member = ParentId & MemberData; diff --git a/src/models/types.ts b/src/models/types.ts index 62568f255e..66e5a8ad52 100644 --- a/src/models/types.ts +++ b/src/models/types.ts @@ -1,3 +1,7 @@ export interface Id { id: string; } + +export type ParentId = Id & { + parentId: string; +}; diff --git a/src/pages/team-page.ts b/src/pages/team-page.ts index 1fa54aecbf..70168fa4e8 100644 --- a/src/pages/team-page.ts +++ b/src/pages/team-page.ts @@ -1,4 +1,4 @@ -import { Failure, Initialized, Pending } from '@abraham/remotedata'; +import { Failure, Pending } from '@abraham/remotedata'; import { computed, customElement, property } from '@polymer/decorators'; import '@polymer/iron-icon'; import '@polymer/marked-element'; @@ -7,25 +7,12 @@ import { html, PolymerElement } from '@polymer/polymer'; import 'plastic-image'; import '../elements/shared-styles'; import { ReduxMixin } from '../mixins/redux-mixin'; -import { RootState, store } from '../store'; -import { fetchTeams } from '../store/teams/actions'; -import { initialTeamsState } from '../store/teams/state'; +import { RootState } from '../store'; +import { selectTeamsAndMembers } from '../store/teams-members/selectors'; +import { initialTeamsMembersState } from '../store/teams-members/state'; @customElement('team-page') export class TeamPage extends ReduxMixin(PolymerElement) { - @property({ type: Object }) - teams = initialTeamsState; - - @computed('teams') - get pending() { - return this.teams instanceof Pending; - } - - @computed('teams') - get failure() { - return this.teams instanceof Failure; - } - static get template() { return html`