Skip to content
Closed
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
2 changes: 2 additions & 0 deletions apps/desktop/src/lib/trpc/routers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { router } from "..";
import { createExternalRouter } from "./external";
import { createNotificationsRouter } from "./notifications";
import { createProjectsRouter } from "./projects";
import { createTabsRouter } from "./tabs";
import { createTerminalRouter } from "./terminal";
import { createWindowRouter } from "./window";
import { createWorkspacesRouter } from "./workspaces";
Expand All @@ -16,6 +17,7 @@ export const createAppRouter = (window: BrowserWindow) => {
window: createWindowRouter(window),
projects: createProjectsRouter(window),
workspaces: createWorkspacesRouter(),
tabs: createTabsRouter(),
terminal: createTerminalRouter(),
notifications: createNotificationsRouter(),
external: createExternalRouter(),
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/lib/trpc/routers/notifications/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type { NotificationsRouter } from "./notifications";
export { createNotificationsRouter } from "./notifications";
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ export const createNotificationsRouter = () => {
}),
});
};

export type NotificationsRouter = ReturnType<typeof createNotificationsRouter>;
7 changes: 7 additions & 0 deletions apps/desktop/src/lib/trpc/routers/projects/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { z } from "zod";
import { publicProcedure, router } from "../..";
import { getGitRoot } from "../workspaces/utils/git";
import { assignRandomColor } from "./utils/colors";
import { getAllWithWorkspaces } from "./utils";

export const createProjectsRouter = (window: BrowserWindow) => {
return router({
Expand Down Expand Up @@ -111,7 +112,13 @@ export const createProjectsRouter = (window: BrowserWindow) => {

return { success: true };
}),

getAllWithWorkspaces: publicProcedure.query(() => {
return getAllWithWorkspaces(db.data.projects, db.data.workspaces);
}),
});
};

export type ProjectsRouter = ReturnType<typeof createProjectsRouter>;

export type ProjectWithWorkspaces = ReturnType<typeof getAllWithWorkspaces>[number];
1 change: 1 addition & 0 deletions apps/desktop/src/lib/trpc/routers/projects/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./utils";
24 changes: 24 additions & 0 deletions apps/desktop/src/lib/trpc/routers/projects/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Project, Workspace } from "main/lib/db/schemas";

/**
* Returns projects with their workspaces, ordered by project.tabOrder then workspace.tabOrder
*/
export function getAllWithWorkspaces(
allProjects: Project[],
allWorkspaces: Workspace[],
) {
const activeProjects = allProjects
.filter((p) => p.tabOrder !== null)
.sort((a, b) => a.tabOrder! - b.tabOrder!);

return activeProjects.map((project) => {
const projectWorkspaces = allWorkspaces
.filter((w) => w.projectId === project.id)
.sort((a, b) => a.tabOrder - b.tabOrder);

return {
...project,
workspaces: projectWorkspaces,
};
});
}
2 changes: 2 additions & 0 deletions apps/desktop/src/lib/trpc/routers/tabs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type { TabsRouter, Tab } from "./tabs";
export { createTabsRouter } from "./tabs";
Loading
Loading