Skip to content

Commit

Permalink
reApply, markAsCompleted
Browse files Browse the repository at this point in the history
  • Loading branch information
ceddybi committed Feb 4, 2024
1 parent 3f0fb2a commit f5e59a2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
17 changes: 13 additions & 4 deletions src/app/dashboard/applications.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export const RenderEditQuestion = (props: RenderEditQuestionProps) => {
const question = selectedQuestion;

useEffect(() => {
console.log("savedQuestions.length", savedQuestions.length);
// console.log("savedQuestions.length", savedQuestions.length);
const selectedSavedQuestion = savedQuestions.find(
(q) => q?.question?.question === props?.question?.question?.question
);

if (!question && selectedSavedQuestion) {
console.log("selectedSavedQuestion", selectedSavedQuestion);
// console.log("selectedSavedQuestion", selectedSavedQuestion);
setSelectedQuestion(selectedSavedQuestion);
}
}, [props?.question, savedQuestions]);
Expand Down Expand Up @@ -61,6 +61,15 @@ export const ApplicationsViews = (props: ApplicationsViewProps) => {

const apps = skipped ? skippedApps : completedApps;

const reApply = async (app: Application) => {
const job = app.job;
await (window as any).api.invoke("app:start:ondemand", job);
};

const moveToCompleted = async (app: Application) => {
await (window as any).api.invoke("app:complete", app);
};

return (
<>
{apps.length > 0 && (
Expand Down Expand Up @@ -115,14 +124,14 @@ export const ApplicationsViews = (props: ApplicationsViewProps) => {
{skipped && (
<div className="flex justify-end gap-3">
<button
// onClick={() => setSelectedApp(null)}
onClick={() => reApply(selectedApp)}
className="bg-blue-500 hover:bg-blue-700 text-white py-1 px-2 rounded"
>
Re-Apply
</button>

<button
// onClick={() => setSelectedApp(null)}
onClick={() => moveToCompleted(selectedApp)}
className="bg-blue-500 hover:bg-blue-700 text-white py-1 px-2 rounded"
>
Mark as completed
Expand Down
30 changes: 24 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APPEVENTS, AppEvents } from './events';
import { AppJob, BEState, addApplied, getAllQuestion, getResume, getState, readQuestion, saveQuestion, saveResume, setState } from "./utils/state";
import { AppJob, Application, BEState, addApplied, getAllQuestion, getResume, getState, readQuestion, saveQuestion, saveResume, setState } from "./utils/state";
import { BrowserWindow, app, dialog, ipcMain, session, shell } from 'electron';
import { baseURL, getAuthApi, isDev } from './api';
import { gotoAppPage, gotoMainPage } from './config/app';
Expand Down Expand Up @@ -176,10 +176,10 @@ const setAppStartStop = async (isStart: boolean) => {

appEvents.on(APPEVENTS.APP_START, async (job: AppJob) => {
// console.log("appEvents.on(APPEVENTS.APP_STOP", job);
await runApplying();
await runApplying(job);
});

async function runApplying(): Promise<any> {
async function runApplying(ondemandJob?: AppJob): Promise<any> {
let jobs: AppJob[] = [];
let state: any = {};
let activeJob: AppJob = null;
Expand All @@ -192,12 +192,13 @@ async function runApplying(): Promise<any> {
cantRun = !!activeJob || !state.isAppRunning;

if (cantRun) {
// console.log("activeJob", { activeJob, isAppRunning: state.isAppRunning });
return null;
if (!ondemandJob) {
return null;
}
}

// console.log("startApplying", jobs.length);
const firstJob = jobs[0];
const firstJob = ondemandJob ? ondemandJob : jobs[0];

if (firstJob) {
await setState({ ...state, activeJob: firstJob });
Expand Down Expand Up @@ -227,6 +228,23 @@ async function runApplying(): Promise<any> {
}
}

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);
if (!(newState.completedApps || []).includes(app)) {
newState.completedApps = [...(newState.completedApps || []), app];
}
await setState(newState);
return newState;
});

ipcMain.handle('app:start:ondemand', async (event, job) => {
// console.log("app:start");
// await setAppStartStop(true);
appEvents.emit(APPEVENTS.APP_START, job);
return true;
});

ipcMain.handle('app:start', async (event) => {
// console.log("app:start");
await setAppStartStop(true);
Expand Down

0 comments on commit f5e59a2

Please sign in to comment.