Skip to content

Commit

Permalink
txt input, select
Browse files Browse the repository at this point in the history
  • Loading branch information
ceddybi committed Feb 13, 2024
1 parent dda50bf commit f9d83d1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/app/dashboard/applications.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const ApplicationsViews = (props: ApplicationsViewProps) => {

{selectedApp && (
<div
style={{ height: "70vh" }}
style={{ height: "70vh", width: "50%" }}
className="flex flex-col overflow-x-scroll"
>
<div style={{ marginBottom: "20px" }}>
Expand Down
69 changes: 27 additions & 42 deletions src/app/questions/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface UseQuestions {
selectedQuestion?: QuestionAnswer;
questions: QuestionAnswer[];
handleChangeAnswer: (answer: Answer) => void;
handleSaveQuestion: () => void;
handleSaveQuestion: (question: QuestionAnswer) => void;
clearSearch: () => void;
handleSearch: (search: string) => void;
setSelectedQuestion: (question: QuestionAnswer) => void;
Expand Down Expand Up @@ -77,39 +77,26 @@ export const useQuestions = (): UseQuestions => {
return sortBy(filteredQuestions, "date");
};

const readQuestion = async (question: QuestionAnswer) => {
// console.log("read question", question);

const savedRead = await (window as any).api.invoke(
"questions:read",
question
);

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

if (savedRead) {
// update FE
const allquestions = questions.map((item) => {
if (item.question.inputId === question.question.inputId) {
return { ...question, isNew: false };
const setSelectedQuestion = (question: QuestionAnswer) => {
setState({
...state,
selectedQuestion: question,
questions: questions.map((item) => {
if (item?.question?.inputId === question?.question?.inputId) {
return question;
}
return item;
});

setState({
...state,
questions: allquestions,
selectedQuestion: question,
});
}
};

const setSelectedQuestion = async (question: QuestionAnswer) => {
await readQuestion(question);
}),
});
handleSaveQuestion(question);
};

const setSelectedAnswerText = (answer: string) => {
const selQuestion = { ...selectedQuestion, chainRes: { text: answer } };
const selQuestion = {
...selectedQuestion,
chainRes: { text: answer },
isNew: false,
};
setSelectedQuestion(selQuestion);
};

Expand Down Expand Up @@ -216,11 +203,11 @@ export const useQuestions = (): UseQuestions => {
getAllQuestions();
}, []);

const handleSaveQuestion = async () => {
const handleSaveQuestion = async (selQuestion: QuestionAnswer) => {
const questToSave: QuestionAnswer = {
...selectedQuestion,
...selQuestion,
chainRes: {
...selectedQuestion.chainRes,
...selQuestion.chainRes,
error: false,
},
isNew: false,
Expand All @@ -231,14 +218,14 @@ export const useQuestions = (): UseQuestions => {
questToSave
);

const allquestions = questions.map((item) => {
if (item.question.inputId === selectedQuestion.question.inputId) {
return questToSave;
}
return item;
});
// const allquestions = questions.map((item) => {
// if (item.question.inputId === selectedQuestion.question.inputId) {
// return questToSave;
// }
// return item;
// });

setState({ ...state, questions: allquestions });
// setState({ ...state, questions: allquestions });

// await getAllQuestions();
return saveQuestion;
Expand All @@ -248,7 +235,6 @@ export const useQuestions = (): UseQuestions => {

return {
search,
readQuestion,
handleSearch,
clearSearch,
selectedQuestion,
Expand All @@ -264,7 +250,6 @@ export const useQuestions = (): UseQuestions => {
export const ListQuestions = () => {
const {
handleSaveQuestion,
readQuestion,
getFilteredQuestions,
selectedQuestion = null,
questions = [],
Expand Down Expand Up @@ -353,7 +338,7 @@ export const ListQuestions = () => {

<div className="flex justify-center mt-2">
<button
onClick={handleSaveQuestion}
onClick={() => handleSaveQuestion(selectedQuestion)}
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
>
Save
Expand Down
6 changes: 5 additions & 1 deletion src/app/questions/question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ export const RenderQuestion = ({

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

const selectQuesTextAnswer = questionAnswerText
.replace('"', "")
.replace('"', "");

return (
<div>
<div>
Expand All @@ -155,7 +159,7 @@ export const RenderQuestion = ({
</div>
<SearchSelect
className="w-full text-xl"
value={questionAnswerText}
value={selectQuesTextAnswer}
onChange={(e: any) => {
const value = e;
const answer = {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export async function saveQuestion(questionAnswer: QuestionAnswer): Promise<bool

const questionReadableId = getReadableId(questionAnswer.question.question);

console.log("saveQuestion", { questionReadableId, questionAnswer });
// console.log("saveQuestion", { questionReadableId, questionAnswer });

const questionFile = `${questionReadableId}.json`;
// Create appDataDir if not exist
Expand Down

0 comments on commit f9d83d1

Please sign in to comment.