Skip to content

migrate to query key factory #847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions apps/desktop/src/queryKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
export const sessionKeys = {
all: ["sessions"] as const,
lists: () => [...sessionKeys.all] as const,
list: (filters?: Record<string, unknown>) => [...sessionKeys.lists(), { filters }] as const,
details: () => [...sessionKeys.all, "detail"] as const,
detail: (id: string) => [...sessionKeys.details(), id] as const,
participants: (sessionId: string) => ["participants", sessionId] as const,
event: (sessionId: string) => ["event", sessionId] as const,
search: (query: string) => ["search-sessions", query] as const,
byHuman: (humanId: string) => [...sessionKeys.lists(), "human", humanId] as const,
byOrganization: (organizationId: string) => [...sessionKeys.lists(), "organization", organizationId] as const,
byCalendarEvent: (eventId: string) => ["event-session", eventId] as const,
};

export const eventKeys = {
all: ["events"] as const,
upcoming: (entityId: string) => [...eventKeys.all, "upcoming", entityId] as const,
upcomingByOrganization: (organizationId: string) =>
[...eventKeys.all, "upcoming", "organization", organizationId] as const,
withoutSession: (userId: string, sessionId: string) =>
["events-in-past-without-assigned-session", userId, sessionId] as const,
bySession: (sessionId: string) => [...eventKeys.all, sessionId] as const,
};

export const humanKeys = {
all: ["humans"] as const,
details: () => [...humanKeys.all, "detail"] as const,
detail: (id: string) => ["human", id] as const,
search: (query: string) => ["search-participants", query] as const,
};

export const organizationKeys = {
all: ["organizations"] as const,
lists: () => [...organizationKeys.all] as const,
list: (searchTerm?: string) => [...organizationKeys.lists(), searchTerm] as const,
details: () => [...organizationKeys.all, "detail"] as const,
detail: (id: string | null) => ["org", id] as const,
members: (organizationId: string) => ["org", organizationId, "members"] as const,
};

export const calendarKeys = {
all: ["calendars"] as const,
lists: () => [...calendarKeys.all] as const,
detail: (id: string) => ["calendar", id] as const,
accessStatus: () => ["settings", "calendarAccess"] as const,
contactsAccessStatus: () => ["settings", "contactsAccess"] as const,
};

export const flagKeys = {
all: ["flags"] as const,
feature: (featureName: string) => [...flagKeys.all, featureName] as const,
};

export const configKeys = {
all: ["config"] as const,
general: () => [...configKeys.all, "general"] as const,
profile: (userId: string) => [...configKeys.all, "profile", userId] as const,
};

export const sttKeys = {
all: ["local-stt"] as const,
currentModel: () => [...sttKeys.all, "current-model"] as const,
supportedModels: () => [...sttKeys.all, "supported-models"] as const,
modelDownloaded: () => ["check-stt-model-downloaded"] as const,
modelDownloading: () => ["stt-model-downloading"] as const,
};

export const llmKeys = {
all: ["llm"] as const,
connection: () => ["custom-llm-connection"] as const,
availableModels: () => ["available-llm-models"] as const,
currentModel: () => ["custom-llm-model"] as const,
enabled: () => ["custom-llm-enabled"] as const,
};

export const appKeys = {
version: () => ["appVersion"] as const,
osType: () => ["osType"] as const,
inApplicationsFolder: () => ["app-in-applications-folder"] as const,
checkForUpdate: () => ["check-for-update"] as const,
};

export const notificationKeys = {
all: ["notification"] as const,
event: () => [...notificationKeys.all, "event"] as const,
detect: () => [...notificationKeys.all, "detect"] as const,
};

export const audioKeys = {
micMuted: () => ["mic-muted"] as const,
speakerMuted: () => ["speaker-muted"] as const,
micPermission: () => ["micPermission"] as const,
systemAudioPermission: () => ["systemAudioPermission"] as const,
};

export const modelKeys = {
all: ["models"] as const,
currentSttModel: () => ["current-stt-model"] as const,
checkModelDownloaded: () => ["check-model-downloaded"] as const,
llmModelDownloading: () => ["llm-model-downloading"] as const,
};

export const devKeys = {
showDevtools: () => ["showDevtools"] as const,
};

export const authKeys = {
userId: () => ["auth-user-id"] as const,
onboardingSessionId: () => ["onboarding"] as const,
};
8 changes: 4 additions & 4 deletions apps/desktop/src/utils/broadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ export function broadcastQueryClient(queryClient: QueryClient) {
const keys = event.payload.queryKey as string[];

if (keys.some((key) => key?.includes("extension"))) {
queryClient.refetchQueries({
queryClient.invalidateQueries({
predicate: (query) => query.queryKey.some((key) => typeof key === "string" && key.includes("extension")),
});
}

if (keys.some((key) => key?.includes("flags"))) {
queryClient.refetchQueries({
queryClient.invalidateQueries({
predicate: (query) => query.queryKey.some((key) => typeof key === "string" && key.includes("flags")),
});
}

if (keys.some((key) => key?.includes("profile"))) {
queryClient.refetchQueries({
queryClient.invalidateQueries({
predicate: (query) =>
query.queryKey.some((key) =>
typeof key === "string" && (key.includes("participant") || key.includes("human") || key.includes("org"))
Expand All @@ -63,7 +63,7 @@ export function broadcastQueryClient(queryClient: QueryClient) {
}

if (keys[0] === "human") {
queryClient.refetchQueries({
queryClient.invalidateQueries({
queryKey: ["human", keys[1]],
predicate: (query) =>
query.queryKey.some((key) => typeof key === "string" && key.includes("grouped-participants")),
Expand Down
Loading