From 558f1dd270bef327173bd5664443ad66d17d7fd2 Mon Sep 17 00:00:00 2001 From: Tomasz Rewak Date: Wed, 17 May 2023 10:58:55 +0200 Subject: [PATCH] Make status flicker. --- components/response.js | 12 +++++++++--- main.py | 31 +++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/components/response.js b/components/response.js index a473ec9..ba24cbd 100644 --- a/components/response.js +++ b/components/response.js @@ -39,13 +39,19 @@ function getStatusColor(status) { } export default function Response(props) { - const { status } = props; + const { status, question_id, answer_id } = props; const text = getStatusText(status); const color = getStatusColor(status); - return React.createElement('div', { className: 'response', style: { color: color, borderColor: color } }, + return React.createElement('div', { className: `response ${question_id !== answer_id ? 'flicker' : ''}`, style: { color: color, borderColor: color } }, [ React.createElement('div', { className: 'inner' }, [text]) ]); -} \ No newline at end of file +} + +Response.defaultProps = { + status: 'info', + question_id: 0, + answer_id: 0 +}; \ No newline at end of file diff --git a/main.py b/main.py index fb7519f..34cea94 100644 --- a/main.py +++ b/main.py @@ -162,25 +162,36 @@ def wise_man_answer(question: dict, personality: str, key: str): @callback( Output({'type': 'wise-man', 'name': MATCH}, 'question_id'), Input('question', 'data')) -def question_id(question: dict): +def wise_man_question_id(question: dict): + return question['id'] + + +@callback( + Output('response', 'question_id'), + Input('question', 'data')) +def response_question_id(question: dict): return question['id'] @callback( Output('response', 'status'), + Output('response', 'answer_id'), Input({'type': 'wise-man', 'name': ALL}, 'answer'), prevent_initial_call=True) def response_status(answers: list): + answer_id = min([answer['id'] for answer in answers]) + status = 'info' + if any([answer['status'] == 'error' for answer in answers]): - return 'error' - if any([answer['status'] == 'no' for answer in answers]): - return 'no' - if any([answer['status'] == 'conditional' for answer in answers]): - return 'conditional' - if all([answer['status'] == 'yes' for answer in answers]): - return 'yes' - - return 'info' + status = 'error' + elif any([answer['status'] == 'no' for answer in answers]): + status = 'no' + elif any([answer['status'] == 'conditional' for answer in answers]): + status = 'conditional' + elif all([answer['status'] == 'yes' for answer in answers]): + status = 'yes' + + return status, answer_id @callback(