Skip to content

Commit

Permalink
app events, key error
Browse files Browse the repository at this point in the history
  • Loading branch information
ceddybi committed Feb 5, 2024
1 parent 2f68168 commit 476d7d1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/app/dashboard/applications.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { Application, BEState } from "../../utils/state";
import { List, ListItem, Metric, Title } from "@tremor/react";
import React, { useEffect, useLayoutEffect } from "react";
import { RenderQuestion, UseQuestions, useQuestions } from "../questions/list";

import { isEmpty } from "lodash";
import { isEmpty, uniqBy } from "lodash";

interface RenderEditQuestionProps extends UseQuestions {
question: QuestionAnswer;
Expand Down Expand Up @@ -59,7 +58,7 @@ export const ApplicationsViews = (props: ApplicationsViewProps) => {
const [selectedApp, setSelectedApp] = React.useState<Application>(null);
const { completedApps = [], skippedApps = [] } = state;

const apps = skipped ? skippedApps : completedApps;
const apps = uniqBy(skipped ? skippedApps : completedApps, "job.id");

const reApply = async (app: Application) => {
const job = app.job;
Expand Down
31 changes: 23 additions & 8 deletions src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import axios from "axios";
import { getBrowser } from "./browser";

const appEvents = AppEvents.Instance;
appEvents.setMaxListeners(0);

const emitApi = (response: any) => {
// console.log("emitApi response", response);
Expand Down Expand Up @@ -54,12 +55,14 @@ export const gotoMainPage = async (url: string) => {

return await new Promise((resolve, reject) => {


appEvents.on(APPEVENTS.LIST_STOP, () => {
// console.log("list stop");
const listStop = () => {
appEvents.removeListener(APPEVENTS.LIST_STOP, listStop);
page.close();
resolve(true);
});
}

appEvents.on(APPEVENTS.LIST_STOP, listStop);

const funcFunc = new Function(mainFunc);
funcFunc.call(null).call(null, ctx, resolve, reject);
});
Expand Down Expand Up @@ -117,18 +120,30 @@ export const gotoAppPage = async (job: AppJob) => {

// console.log("mainFunc", mainFunc);

return await new Promise((resolve, reject) => {

appEvents.on(APPEVENTS.APP_STOP, (jobId: string) => {
// console.log("app stop", jobId);
return await new Promise((resolve, reject) => {

// Define the event listener function
const onAppStop = (jobId: string) => {
if (jobId === job.id) {
// Clean up the event listener to avoid memory leaks
appEvents.removeListener(APPEVENTS.APP_STOP, onAppStop);

// Close the page and resolve the promise
page.close();
resolve(true);
}
});
};

// Attach the event listener to the APP_STOP event
appEvents.on(APPEVENTS.APP_STOP, onAppStop);


const funcFunc = new Function(mainFunc);
funcFunc.call(null).call(null, ctx, resolve, reject);



});

}
Expand Down

0 comments on commit 476d7d1

Please sign in to comment.