Skip to content

Commit

Permalink
active job, stop, skip, complete
Browse files Browse the repository at this point in the history
  • Loading branch information
ceddybi committed Feb 5, 2024
1 parent 476d7d1 commit 3afcf15
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 18 deletions.
87 changes: 69 additions & 18 deletions src/app/dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Bold, Button, Card, Flex, Grid, Metric, Text } from "@tremor/react";
import { Bold, Button, Card, Flex, Grid, Metric, Text, Title } from "@tremor/react";
import {
CheckCircleIcon,
CheckIcon,
ForwardIcon,
QuestionMarkCircleIcon,
StopIcon,
} from "@heroicons/react/20/solid";
Expand All @@ -13,6 +15,7 @@ import {
TabPanels,
} from "@tremor/react";

import { AppJob } from "../../utils/state";
import ApplicationsViews from "./applications.view";
import { LayoutPageProps } from "../layout";
import QuestionsError from "./questions.error";
Expand All @@ -21,6 +24,7 @@ import { useQuestions } from "../questions/list";

export const Dashboard = ({ state }: LayoutPageProps) => {
const {
activeJob,
apps = [],
completedApps = [],
skippedApps = [],
Expand Down Expand Up @@ -55,6 +59,23 @@ export const Dashboard = ({ state }: LayoutPageProps) => {
await (window as any).api.invoke(eventName, args);
};

const skipJob = async (job: AppJob) => {
const app = (apps || []).find((ap) => ap.job.id === job.id) || {
job,
questions: [] as any,
};

await (window as any).api.invoke("app:skip", app);
};

const moveToCompleted = async (job: AppJob) => {
const app = (apps || []).find((ap) => ap.job.id === job.id) || {
job,
questions: [] as any,
};
await (window as any).api.invoke("app:complete", app);
};

const allEvents = [
// { title: "Main", name: "list", isRunning: isListRunning, args: searchUrl },
{
Expand Down Expand Up @@ -120,28 +141,58 @@ export const Dashboard = ({ state }: LayoutPageProps) => {
</div>
</div>

<div className="flex justify-center">
<Button
onClick={() => invokeEvent("app:start", searchUrl)}
disabled={isAppRunning}
loading={isAppRunning}
>
{" "}
{!isAppRunning ? "Apply with AI" : "AI Applying ..."}{" "}
</Button>
{activeJob && (
<div className="flex items-center flex-col p-3 w-full overflow-hidden">
<div className="truncate">
<Title>
{activeJob.title} - {activeJob.company}
</Title>
</div>

<div className="ml-2">
{isAppRunning && (
<div className="flex justify-end gap-3">
<Button
color="red"
loading={true}
className="bg-red-500 hover:bg-red-700 text-white py-1 px-2 rounded"
></Button>

<button
onClick={() => invokeEvent("app:stop", searchUrl)}
className="flex items-center bg-red-500 hover:bg-red-700 text-white py-1 px-2 rounded"
>
{" "}
Stop AI{" "}
</Button>
)}
<StopIcon className="h-5 w-5 text-white-400" /> Stop
</button>

<button
onClick={() => skipJob(activeJob)}
className="flex items-center bg-blue-500 hover:bg-blue-700 text-white py-1 px-2 rounded"
>
<ForwardIcon className="h-5 w-5 text-white-400" />
Skip
</button>

<button
onClick={() => moveToCompleted(activeJob)}
className="flex items-center bg-green-500 hover:bg-green-700 text-white py-1 px-2 rounded"
>
<CheckIcon className="h-5 w-5 text-white-400" />
Mark as completed
</button>
</div>
</div>
</div>
)}

{!activeJob && (
<div className="flex justify-center">
<Button
onClick={() => invokeEvent("app:start", searchUrl)}
disabled={isAppRunning}
loading={isAppRunning}
>
{" "}
{!isAppRunning ? "Apply with AI" : "AI Applying ..."}{" "}
</Button>
</div>
)}
</div>
</Grid>

Expand Down
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,23 @@ async function runApplying(ondemandJob?: AppJob): Promise<any> {
}
}

ipcMain.handle('app:skip', async (event, app: Application) => {
const newState = await getState();

if (newState.skippedApps) {
if (newState.skippedApps.some((a) => a.job?.id === app.job?.id)) {
return;
}
newState.skippedApps.push(app);
} else {
newState.skippedApps = [app];
}
newState.activeJob = null;

await setState(newState);
return newState;
});

ipcMain.handle('app:complete', async (event, app: Application) => {
const newState = await addApplied(app.job);
newState.skippedApps = (newState.skippedApps || []).filter((a) => a.job?.id !== app.job?.id);
Expand Down

0 comments on commit 3afcf15

Please sign in to comment.