Skip to content

Commit

Permalink
job exist, props, select quest
Browse files Browse the repository at this point in the history
  • Loading branch information
ceddybi committed Feb 13, 2024
1 parent b28e5b3 commit 5d955eb
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app/questions/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Question {
question: string;
inputId: string;
inputType: "input" | "text" | "radio" | "checkbox" | "select" | "textarea" | "fieldset";
inputOptions?: InputOption;
inputOptions?: InputOption[];
inputTypeValue?: string;
answers?: Answer[];
}
Expand Down
44 changes: 42 additions & 2 deletions src/app/questions/list.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Answer, QuestionAnswer } from "./interfaces";
import { Answer, InputOption, QuestionAnswer } from "./interfaces";
import {
Badge,
Card,
Expand All @@ -7,6 +7,12 @@ import {
List,
ListItem,
Metric,
MultiSelect,
MultiSelectItem,
SearchSelect,
SearchSelectItem,
Select,
SelectItem,
Textarea,
Title,
} from "@tremor/react";
Expand Down Expand Up @@ -116,6 +122,41 @@ export const RenderQuestion = ({
</List>
</div>
);

case "select":
const questionInputOptions: InputOption[] =
question?.question?.inputOptions || [];

console.log("questionInputOptions", questionInputOptions);

return (
<div>
<div>
{questionAnswerError && (
<div className="text-red-500">Please select an answer</div>
)}
</div>
<SearchSelect
value={questionAnswerText}
onChange={(e: any) => {
const value = e;
const answer = {
inputId: question.question.inputId,
inputType: question.question.inputType,
answerText: value,
};
handleChangeAnswer(answer);
}}
>
{questionInputOptions.map((option) => (
<SearchSelectItem key={option?.value} value={option.value}>
{option.label || (option as any).text}
</SearchSelectItem>
))}
</SearchSelect>
</div>
);

default:
case "text":
return (
Expand Down Expand Up @@ -217,7 +258,6 @@ export const useQuestions = (): UseQuestions => {
selectedQuestion: question,
});
}

};

const setSelectedQuestion = async (question: QuestionAnswer) => {
Expand Down
2 changes: 2 additions & 0 deletions src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const gotoMainPage = async (url: string) => {
const page = await browser.newPage();

const ctx = {
getState,
setState,
speedApply,
speedJobs,
emitApi,
Expand Down
27 changes: 26 additions & 1 deletion src/utils/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,29 @@ export const addApplied = async (job: AppJob) => {

export const addJob = async (job: AppJob | AppJob[]): Promise<boolean> => {


try {
const state = await getState();

const jobsExist = () => {

const currentJobs = Array.isArray(job) ? job : [job];
const currentJobsIds = currentJobs.map(j => j.id);

const applied = state.applied || [];
const jobs = state.jobs || [];
const completedApps = state.completedApps || [];
const skippedApps = state.skippedApps || [];

const allJobs = [...applied, ...jobs, ...(completedApps.map(c => c.job)), ...(skippedApps).map(c => c.job)];

return allJobs.some((j) => currentJobsIds.includes(j.id));
};

if (jobsExist()) {
return false;
}

const newJobs = uniqBy([...(state.jobs || []), ...(Array.isArray(job) ? job : [job])], "id")
const newState = { ...state, jobs: newJobs };
await setState(newState);
Expand Down Expand Up @@ -150,7 +171,11 @@ export async function saveQuestion(questionAnswer: QuestionAnswer): Promise<bool
const appDataDirPath = getAppDataPath();
const questionDirPath = path.join(appDataDirPath, "questions");

const questionFile = `${getReadableId(questionAnswer.question.question)}.json`;
const questionReadableId = getReadableId(questionAnswer.question.question);

// console.log("saveQuestion", questionReadableId);

const questionFile = `${questionReadableId}.json`;
// Create appDataDir if not exist
if (!fs.existsSync(questionDirPath)) {
fs.mkdirSync(questionDirPath, { recursive: true });
Expand Down

0 comments on commit 5d955eb

Please sign in to comment.