Skip to content

Commit

Permalink
stop jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
ceddybi committed Feb 5, 2024
1 parent 3afcf15 commit f6ebbaa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
42 changes: 30 additions & 12 deletions src/app/dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Bold, Button, Card, Flex, Grid, Metric, Text, Title } from "@tremor/react";
import {
Bold,
Button,
Card,
Flex,
Grid,
Metric,
Text,
Title,
} from "@tremor/react";
import {
CheckCircleIcon,
CheckIcon,
Expand All @@ -24,7 +33,7 @@ import { useQuestions } from "../questions/list";

export const Dashboard = ({ state }: LayoutPageProps) => {
const {
activeJob,
// activeJob,
apps = [],
completedApps = [],
skippedApps = [],
Expand All @@ -33,6 +42,7 @@ export const Dashboard = ({ state }: LayoutPageProps) => {
jobs = [],
applied = [],
questions = [],
activeJob,
} = state;

const useQuestionState = useQuestions();
Expand All @@ -59,6 +69,15 @@ export const Dashboard = ({ state }: LayoutPageProps) => {
await (window as any).api.invoke(eventName, args);
};

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

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

const skipJob = async (job: AppJob) => {
const app = (apps || []).find((ap) => ap.job.id === job.id) || {
job,
Expand Down Expand Up @@ -136,27 +155,26 @@ export const Dashboard = ({ state }: LayoutPageProps) => {
<div className="flex flex-col items-center w-full justify-center">
<div className="flex items-center">
<Bold>Applications</Bold>
<div className="p-3">
<div className="p-2">
<Metric> {applied.length} </Metric>
</div>
</div>

{activeJob && (
<div className="flex items-center flex-col p-3 w-full overflow-hidden">
<div className="truncate">
<Title>
{activeJob.title} - {activeJob.company}
</Title>
{(activeJob || isAppRunning) && (
<div className="flex items-center flex-col px-3 w-full overflow-hidden">
<div className="truncate border-t-4 border-l-4 border-r-4 w-full text-center">
<Text>{activeJob?.title}</Text>
<Bold>{activeJob?.company}</Bold>
</div>

<div className="flex justify-end gap-3">
<div className="w-full flex justify-center gap-3 border-b-4 border-l-4 border-r-4 pb-3">
<Button
loading={true}
className="bg-red-500 hover:bg-red-700 text-white py-1 px-2 rounded"
></Button>

<button
onClick={() => invokeEvent("app:stop", searchUrl)}
onClick={() => appStop(activeJob)}
className="flex items-center bg-red-500 hover:bg-red-700 text-white py-1 px-2 rounded"
>
<StopIcon className="h-5 w-5 text-white-400" /> Stop
Expand All @@ -181,7 +199,7 @@ export const Dashboard = ({ state }: LayoutPageProps) => {
</div>
)}

{!activeJob && (
{!activeJob && !isAppRunning && (
<div className="flex justify-center">
<Button
onClick={() => invokeEvent("app:start", searchUrl)}
Expand Down
17 changes: 15 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BrowserWindow, app, dialog, ipcMain, session, shell } from 'electron';
import { baseURL, getAuthApi, isDev } from './api';
import { gotoAppPage, gotoMainPage } from './config/app';

import _get from 'lodash/get';
import packageJson from '../package.json';
import path from 'node:path';
import { updateElectronApp } from "update-electron-app";
Expand Down Expand Up @@ -229,6 +230,8 @@ async function runApplying(ondemandJob?: AppJob): Promise<any> {
}

ipcMain.handle('app:skip', async (event, app: Application) => {
if (!app) return;

const newState = await getState();

if (newState.skippedApps) {
Expand All @@ -242,16 +245,25 @@ ipcMain.handle('app:skip', async (event, app: Application) => {
newState.activeJob = null;

await setState(newState);

const jobId = _get(app, "job.id", "");
appEvents.emit(APPEVENTS.APP_STOP, jobId);

return newState;
});

ipcMain.handle('app:complete', async (event, app: Application) => {
if (!app) return;
const newState = await addApplied(app.job);
newState.skippedApps = (newState.skippedApps || []).filter((a) => a.job?.id !== app.job?.id);
if (!(newState.completedApps || []).includes(app)) {
newState.completedApps = [...(newState.completedApps || []), app];
}
await setState(newState);

const jobId = _get(app, "job.id", "");
appEvents.emit(APPEVENTS.APP_STOP, jobId);

return newState;
});

Expand All @@ -269,10 +281,11 @@ ipcMain.handle('app:start', async (event) => {
return true;
});

ipcMain.handle('app:stop', async (event) => {
ipcMain.handle('app:stop', async (event, app: Application) => {
// console.log("app:stop");
const jobId = _get(app, "job.id", "");
await setAppStartStop(false);
appEvents.emit(APPEVENTS.APP_STOP);
appEvents.emit(APPEVENTS.APP_STOP, jobId);
return true;
});

Expand Down

0 comments on commit f6ebbaa

Please sign in to comment.