Skip to content

Commit

Permalink
fix: meal plan/shopping list edit collaborators without threads (#1417)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoy authored Jul 18, 2024
2 parents 94f0dd5 + 8326239 commit 79ada7a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ <h6>{{ "components.selectCollaborators.title" | translate }}</h6>
name="trash"
slot="start"
></ion-icon>
{{ threadsByUserId[userId].name || threadsByUserId[userId].email }}
{{
userProfilesById.get(userId)?.name ||
userProfilesById.get(userId)?.email ||
threadsByUserId[userId]?.name ||
threadsByUserId[userId]?.email ||
"--"
}}
</span>
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import { Component, EventEmitter, Input, Output } from "@angular/core";
import {
Component,
EventEmitter,
Input,
Output,
type AfterViewInit,
} from "@angular/core";
import { TranslateService } from "@ngx-translate/core";

import { LoadingService } from "../../services/loading.service";
import { MessagingService } from "../../services/messaging.service";
import { ToastController, ModalController } from "@ionic/angular";
import { UtilService } from "../../services/util.service";
import { UserService } from "../../services/user.service";
import { TRPCService } from "../../services/trpc.service";
import type { UserPublic } from "@recipesage/prisma";

@Component({
selector: "select-collaborators",
templateUrl: "select-collaborators.component.html",
styleUrls: ["./select-collaborators.component.scss"],
})
export class SelectCollaboratorsComponent {
export class SelectCollaboratorsComponent implements AfterViewInit {
@Input() selectedCollaboratorIds: string[] = [];
@Output() selectedCollaboratorIdsChanged = new EventEmitter<string[]>();

userProfilesById: Map<string, UserPublic> = new Map();
threadsByUserId: any = {};
existingThreads: any = [];
pendingThread = "";
Expand All @@ -31,15 +40,35 @@ export class SelectCollaboratorsComponent {
public toastCtrl: ToastController,
public modalCtrl: ModalController,
public userService: UserService,
public trpcService: TRPCService,
public utilService: UtilService,
public loadingService: LoadingService,
public messagingService: MessagingService,
public translate: TranslateService,
) {
) {}

ngAfterViewInit() {
this.loadThreads().then(
() => {},
() => {},
);

this.loadUserProfiles();
}

async loadUserProfiles() {
if (!this.selectedCollaboratorIds.length) return;

const userProfiles = await this.trpcService.handle(
this.trpcService.trpc.users.getUserProfilesById.query({
ids: this.selectedCollaboratorIds,
}),
);

if (!userProfiles) return;
this.userProfilesById = new Map(
userProfiles.map((userProfile) => [userProfile.id, userProfile]),
);
}

async loadThreads() {
Expand Down
2 changes: 2 additions & 0 deletions packages/trpc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import { getShoppingLists } from "./procedures/shoppingLists/getShoppingLists";
import { updateShoppingList } from "./procedures/shoppingLists/updateShoppingList";
import { updateShoppingListItem } from "./procedures/shoppingLists/updateShoppingListItem";
import { updateShoppingListItems } from "./procedures/shoppingLists/updateShoppingListItems";
import { getUserProfilesById } from "./procedures/users/getUserProfilesById";

const appRouter = router({
labelGroups: router({
Expand Down Expand Up @@ -121,6 +122,7 @@ const appRouter = router({
}),
users: router({
getMe,
getUserProfilesById,
updatePreferences,
getPreferences,
signInWithGoogle,
Expand Down
27 changes: 27 additions & 0 deletions packages/trpc/src/procedures/users/getUserProfilesById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { prisma } from "@recipesage/prisma";
import { publicProcedure } from "../../trpc";
import { userPublic } from "@recipesage/prisma";
import { validateTrpcSession } from "@recipesage/util/server/general";
import { z } from "zod";

export const getUserProfilesById = publicProcedure
.input(
z.object({
ids: z.array(z.string().uuid()).min(1).max(100),
}),
)
.query(async ({ ctx, input }) => {
const session = ctx.session;
validateTrpcSession(session);

const profiles = await prisma.user.findMany({
where: {
id: {
in: input.ids,
},
},
...userPublic,
});

return profiles;
});

0 comments on commit 79ada7a

Please sign in to comment.