dappsnation / akita-ng-fire

Akita ❤️ Angular 🔥 Firebase
MIT License
131 stars 27 forks source link

Sub-sub-collection based on another state #210

Open jaytonic opened 3 years ago

jaytonic commented 3 years ago

Hi,

I'm doing a free "scrum planning" tool, mostly to learn about akita, firebase and angular while still doing something usefull, in order to check if this is the framework I want to push at my work for our next angular app.

I will have the following structure on firebase:

/rooms/{roomId}/
               /activeStoryId
               /stories/{storyId}/
                                 /storyDescription
                                 /votes/{voteId}/
                                                /value
                                                /voter
                                 /storyStats

So, currently, I've a RoomsStore. I've an ActiveRoomGuard that sync the active room when I navigate to "https://hostname/rooms/{id}".

I'm currently creating a parallel StoriesStore( based on your subcollection here: https://github.com/dappsnation/akita-ng-fire/blob/v6/src/app/subcollection/stakeholder.guard.ts ), for which I should also do an ActiveStoryGuard. But I'm not sure how to implement this. Is it possible to use the RoomsQuery to get the activeStoryId of the active room? How?

I don't want to have the Id of the story in the URL because I don't want users to be able to navigate between the stories(there will be another vue to have an overview of the past estimations) and I want to have everybody that is on the same room with the same view.

Here is my current status:

@Injectable({ providedIn: 'root' })
@CollectionGuardConfig({ awaitSync: true })
export class ActiveStoryGuard extends CollectionGuard<StoriesState> {
  constructor(service: StoriesService) {
    super(service);
  }

  // Sync and set active
  sync(next: ActivatedRouteSnapshot) {
    const { id } = next.params;
    //How to retrieve the story ID?
    return this.service.syncActive(
      { id: storyId },
      { params: { roomId: id } }
    );
  }
}

Thank you very much for your valued support.

randallmeeker commented 2 years ago

You can use RoomsQuery inside this, same as any service. I think the question that is un answered is where you activeStoryId is being held.