diff --git a/frontend/src/i18n/strings.js b/frontend/src/i18n/strings.js index 28bb5ef..f3f84d5 100644 --- a/frontend/src/i18n/strings.js +++ b/frontend/src/i18n/strings.js @@ -17,9 +17,15 @@ export const strings = { usernameDots: "Não comece nem termine com ponto, nem use dois pontos seguidos.", usernameTooShort: "Use pelo menos 3 caracteres.", usernameTooLong: "Use no máximo 20 caracteres.", - slowTitle: "Conectando ao servidor…", + slowTitle: "Verificando a conexão…", slowBody: - "Se ele estava parado, acordar pode levar até um minuto. Você entra assim que ele responder.", + "Estamos aguardando a resposta do servidor. Você entrará automaticamente quando ele estiver disponível.", + wakingTitle: "Preparando sua conexão…", + wakingBody: + "O servidor pode estar iniciando após um período de inatividade. Isso pode levar alguns instantes.", + longWaitTitle: "A conexão está demorando mais que o normal", + longWaitBody: + "Ainda estamos tentando conectar. Confira sua internet; você pode cancelar e tentar novamente.", failedTitle: "Não foi possível conectar.", failedBody: "Verifique sua internet ou tente de novo em instantes.", }, diff --git a/frontend/src/ui/entry.js b/frontend/src/ui/entry.js index 8aa190d..494255a 100644 --- a/frontend/src/ui/entry.js +++ b/frontend/src/ui/entry.js @@ -105,7 +105,9 @@ export const describeUsername = (raw, { suggested = false, touched = false } = { }; /** Depois de quanto tempo sem confirmação a espera ganha explicação. */ -const SLOW_AFTER_MS = 3000; +const SLOW_AFTER_MS = 5000; +const WAKE_AFTER_MS = 15000; +const LONG_WAIT_AFTER_MS = 45000; /** * @param {{ @@ -138,6 +140,8 @@ export const createEntry = ({ onSubmit, onCancel, onRetry }) => { let startedAt = 0; /** @type {ReturnType | null} */ let slowTimer = null; + /** @type {ReturnType | null} */ + let longWaitTimer = null; /** Último estado do enlace recebido, para o aviso de lentidão. */ let lastProgress = { link: "idle", attempt: 0 }; @@ -186,6 +190,8 @@ export const createEntry = ({ onSubmit, onCancel, onRetry }) => { const stopSlowTimer = () => { if (slowTimer !== null) clearTimeout(slowTimer); slowTimer = null; + if (longWaitTimer !== null) clearTimeout(longWaitTimer); + longWaitTimer = null; }; /** Botão no estado normal (sem carregamento). */ @@ -225,14 +231,18 @@ export const createEntry = ({ onSubmit, onCancel, onRetry }) => { }); return; } - if (link === "retrying" && attempt > 0) { + const elapsed = Date.now() - startedAt; + if (elapsed >= LONG_WAIT_AFTER_MS) { + showStatus({ title: strings.entry.longWaitTitle, body: strings.entry.longWaitBody }); + } else if (elapsed >= WAKE_AFTER_MS) { showStatus({ - title: format(strings.conn.retryingNth, { n: attempt }), - body: strings.entry.slowBody, + title: + link === "retrying" && attempt > 0 + ? format(strings.conn.retryingNth, { n: attempt }) + : strings.entry.wakingTitle, + body: strings.entry.wakingBody, }); - return; - } - if (Date.now() - startedAt >= SLOW_AFTER_MS) { + } else if (elapsed >= SLOW_AFTER_MS) { showStatus({ title: strings.entry.slowTitle, body: strings.entry.slowBody }); } }; @@ -249,6 +259,10 @@ export const createEntry = ({ onSubmit, onCancel, onRetry }) => { hideStatus(); stopSlowTimer(); slowTimer = setTimeout(paintProgress, SLOW_AFTER_MS); + longWaitTimer = setTimeout(() => { + paintProgress(); + longWaitTimer = setTimeout(paintProgress, LONG_WAIT_AFTER_MS - WAKE_AFTER_MS); + }, WAKE_AFTER_MS); }; form.addEventListener("submit", (event) => {