Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions frontend/src/i18n/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
},
Expand Down
28 changes: 21 additions & 7 deletions frontend/src/ui/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {{
Expand Down Expand Up @@ -138,6 +140,8 @@ export const createEntry = ({ onSubmit, onCancel, onRetry }) => {
let startedAt = 0;
/** @type {ReturnType<typeof setTimeout> | null} */
let slowTimer = null;
/** @type {ReturnType<typeof setTimeout> | null} */
let longWaitTimer = null;
/** Último estado do enlace recebido, para o aviso de lentidão. */
let lastProgress = { link: "idle", attempt: 0 };

Expand Down Expand Up @@ -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). */
Expand Down Expand Up @@ -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 });
}
};
Expand All @@ -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) => {
Expand Down
Loading