Skip to content

Commit 2bd9daf

Browse files
committed
clean up
1 parent f4bc424 commit 2bd9daf

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

apps/web/client/src/app/project/[id]/_hooks/use-start-project.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const useStartProject = () => {
2727
const apiUtils = api.useUtils();
2828
const { data: user, isLoading: isUserLoading, error: userError } = api.user.get.useQuery();
2929
const { data: project, isLoading: isProjectLoading, error: projectError } = api.project.get.useQuery({ projectId: editorEngine.projectId });
30-
const { data: branch, isLoading: isBranchLoading, error: branchError } = api.branch.get.useQuery({ projectId: editorEngine.projectId });
30+
const { data: branch, isLoading: isBranchLoading, error: branchError } = api.branch.getByProjectId.useQuery({ projectId: editorEngine.projectId });
3131
const { data: canvasWithFrames, isLoading: isCanvasLoading, error: canvasError } = api.userCanvas.getWithFrames.useQuery({ projectId: editorEngine.projectId });
3232
const { data: conversations, isLoading: isConversationsLoading, error: conversationsError } = api.chat.conversation.getAll.useQuery({ projectId: editorEngine.projectId });
3333
const { data: creationRequest, isLoading: isCreationRequestLoading, error: creationRequestError } = api.project.createRequest.getPendingRequest.useQuery({ projectId: editorEngine.projectId });
@@ -45,6 +45,12 @@ export const useStartProject = () => {
4545
}
4646
}, [project]);
4747

48+
useEffect(() => {
49+
if (branch) {
50+
editorEngine.branches.switchToBranch(branch.id);
51+
}
52+
}, [branch]);
53+
4854
const startSandbox = async (project: Project) => {
4955
try {
5056
await editorEngine.sandbox.session.start(project.sandbox.id);

apps/web/client/src/server/api/routers/project/branch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ export const branchRouter = createTRPCRouter({
1212
}),
1313
)
1414
.query(async ({ ctx, input }) => {
15-
const dbBranch = await ctx.db.query.branches.findFirst({
15+
const dbBranches = await ctx.db.query.branches.findMany({
1616
where: eq(branches.projectId, input.projectId),
1717
});
18-
if (!dbBranch) {
18+
if (!dbBranches) {
1919
throw new TRPCError({
2020
code: 'NOT_FOUND',
2121
message: 'Branch not found',
2222
});
2323
}
24-
return fromDbBranch(dbBranch);
24+
return dbBranches.map(fromDbBranch);
2525
}),
2626
create: protectedProcedure
2727
.input(branchInsertSchema)

apps/web/client/src/server/api/routers/publish/helpers/publish.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export async function publish({ db, deployment }: { db: DrizzleDb; deployment: D
2323
const deploymentUrls = await getProjectUrls(db, projectId, type);
2424
const sandboxId = await getSandboxId(db, projectId);
2525

26-
const updateDeploymentResult1 = await updateDeployment(db, deploymentId, {
26+
const updateDeploymentResult1 = await updateDeployment(db, {
27+
id: deploymentId,
2728
status: DeploymentStatus.IN_PROGRESS,
2829
message: 'Creating build environment...',
2930
progress: 10,
@@ -42,7 +43,8 @@ export async function publish({ db, deployment }: { db: DrizzleDb; deployment: D
4243
);
4344

4445
try {
45-
const updateDeploymentResult2 = await updateDeployment(db, deploymentId, {
46+
const updateDeploymentResult2 = await updateDeployment(db, {
47+
id: deploymentId,
4648
status: DeploymentStatus.IN_PROGRESS,
4749
message: 'Creating optimized build...',
4850
progress: 20,
@@ -60,10 +62,11 @@ export async function publish({ db, deployment }: { db: DrizzleDb; deployment: D
6062
skipBadge: type === DeploymentType.CUSTOM,
6163
buildScript: buildScript ?? DefaultSettings.COMMANDS.build,
6264
buildFlags: buildFlags ?? DefaultSettings.EDITOR_SETTINGS.buildFlags,
63-
updateDeployment: (deployment) => updateDeployment(db, deploymentId, deployment),
65+
updateDeployment: (deployment) => updateDeployment(db, deployment),
6466
});
6567

66-
const updateDeploymentResult3 = await updateDeployment(db, deploymentId, {
68+
const updateDeploymentResult3 = await updateDeployment(db, {
69+
id: deploymentId,
6770
status: DeploymentStatus.IN_PROGRESS,
6871
message: 'Deploying build...',
6972
progress: 80,
@@ -89,7 +92,8 @@ export async function publish({ db, deployment }: { db: DrizzleDb; deployment: D
8992
}
9093
} catch (error) {
9194
console.error(error);
92-
await updateDeployment(db, deploymentId, {
95+
await updateDeployment(db, {
96+
id: deploymentId,
9397
status: DeploymentStatus.FAILED,
9498
error: error instanceof Error ? error.message : 'Unknown error',
9599
progress: 100,

apps/web/client/src/server/api/routers/publish/helpers/unpublish.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export const unpublish = async (db: DrizzleDb, deployment: Deployment, urls: str
1414
message: 'Deployment not found',
1515
});
1616
}
17-
updateDeployment(db, deployment.id, {
17+
updateDeployment(db, {
18+
id: deployment.id,
1819
status: DeploymentStatus.IN_PROGRESS,
1920
message: 'Unpublishing project...',
2021
progress: 20,
@@ -27,13 +28,15 @@ export const unpublish = async (db: DrizzleDb, deployment: Deployment, urls: str
2728
envVars: {},
2829
});
2930

30-
updateDeployment(db, deployment.id, {
31+
updateDeployment(db, {
32+
id: deployment.id,
3133
status: DeploymentStatus.COMPLETED,
3234
message: 'Project unpublished!',
3335
progress: 100,
3436
});
3537
} catch (error) {
36-
updateDeployment(db, deployment.id, {
38+
updateDeployment(db, {
39+
id: deployment.id,
3740
status: DeploymentStatus.FAILED,
3841
error: error instanceof Error ? error.message : 'Unknown error',
3942
progress: 100,

0 commit comments

Comments
 (0)