/
rostislav1
/
ReqMaster
Обзор
Документация
Войти
/
rostislav1
/
ReqMaster
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/utils/renderQuickMessage.js
76 строк
2 KB
Wenn911
fix
25 мар 2025, 09:34
25 мар 2025, 09:34
b7529f3
Код
Авторство
О чём код?
import { runPrompt } from "../api/api"; import { showError, showResponse } from "./showContent"; const quickMessagesContainer = document.querySelector('.quickMessage'); const inputPrompt = document.body.querySelector('#input-prompt'); const QUICK_MESSAGES = { initial: { user: 'Сравнение требований по шаблону', bot: 'Отправь ссылку Confluence на шаблон требований' }, templateSent: { bot: 'А теперь отправь ссылку на страницу Confluence с требованиями' } }; // Состояние диалога let dialogState = { waitingForTemplate: false, waitingForRequirements: false }; export const renderQuickMessages = () => { quickMessagesContainer.addEventListener('click', async (event) => { const messageElement = event.target.closest('.quickMessage'); messageElement.style.opacity = '0'; quickMessagesContainer.style.opacity = '0'; quickMessagesContainer.style.transform = 'translateY(10px)'; setTimeout(async () => { messageElement.remove(); if (!dialogState.waitingForTemplate && !dialogState.waitingForRequirements) { showResponse('user', QUICK_MESSAGES.initial.user); showResponse('bot', QUICK_MESSAGES.initial.bot); dialogState.waitingForTemplate = true; try { inputPrompt.value = ''; await runPrompt(QUICK_MESSAGES.initial.user, ''); } catch (e) { showError(e); } } }, 300); }); } export const checkUserInput = async (message, tabUrl) => { if (dialogState.waitingForTemplate) { showResponse('user', message); showResponse('bot', QUICK_MESSAGES.templateSent.bot); dialogState.waitingForTemplate = false; dialogState.waitingForRequirements = true; try { inputPrompt.value = ''; await runPrompt(message, ''); return true; } catch (e) { showError(e); } } else if (dialogState.waitingForRequirements) { // showResponse('user', message); dialogState.waitingForRequirements = false; // const comparisonResult = await runPrompt( // `Сравнить требования:\nШаблон: ${templateUrl}\nТребования: ${message}`, // tabUrl // ); // showResponse('bot', comparisonResult.content); return false; } };