-
-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Automatically refresh the jobs page when there are no jobs - Celebrate 🎊
- Loading branch information
Showing
10 changed files
with
154 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
apps/webapp/app/routes/resources.projects.$projectId.jobs.stream.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { LoaderArgs } from "@remix-run/server-runtime"; | ||
import { z } from "zod"; | ||
import { prisma } from "~/db.server"; | ||
import { requireUserId } from "~/services/session.server"; | ||
import { sse } from "~/utils/sse"; | ||
|
||
export async function loader({ request, params }: LoaderArgs) { | ||
await requireUserId(request); | ||
|
||
const { projectId } = z.object({ projectId: z.string() }).parse(params); | ||
|
||
const project = await projectForUpdates(projectId); | ||
|
||
if (!project) { | ||
return new Response("Not found", { status: 404 }); | ||
} | ||
|
||
let lastSignals = calculateChangeSignals(project); | ||
|
||
return sse({ | ||
request, | ||
run: async (send, stop) => { | ||
const result = await projectForUpdates(projectId); | ||
if (!result) { | ||
return stop(); | ||
} | ||
|
||
const newSignals = calculateChangeSignals(result); | ||
|
||
if (lastSignals.jobCount !== newSignals.jobCount) { | ||
send({ data: JSON.stringify(newSignals) }); | ||
} | ||
|
||
lastSignals = newSignals; | ||
}, | ||
}); | ||
} | ||
|
||
function projectForUpdates(id: string) { | ||
return prisma.project.findUnique({ | ||
where: { | ||
id, | ||
}, | ||
include: { | ||
_count: { | ||
select: { jobs: true }, | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
function calculateChangeSignals( | ||
project: NonNullable<Awaited<ReturnType<typeof projectForUpdates>>> | ||
) { | ||
const jobCount = project._count?.jobs ?? 0; | ||
|
||
return { | ||
jobCount, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { ExternalScriptsFunction } from "remix-utils"; | ||
import { BreadcrumbItem } from "~/components/navigation/Breadcrumb"; | ||
|
||
export type Handle = { | ||
breadcrumb?: BreadcrumbItem; | ||
expandSidebar?: boolean; | ||
scripts?: ExternalScriptsFunction; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.