Improve pending state with clearer messages
This commit is contained in:
parent
eb28499dfd
commit
6e2e403873
2 changed files with 42 additions and 9 deletions
|
|
@ -8,9 +8,10 @@
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
test: Test;
|
test: Test;
|
||||||
|
fetching?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { test, nbfetch, nextfetch }: Props = $props();
|
let { test, nbfetch, nextfetch, fetching = false }: Props = $props();
|
||||||
|
|
||||||
let lastForcedCheck = $state(Date.now() - 12345);
|
let lastForcedCheck = $state(Date.now() - 12345);
|
||||||
function forceCheck() {
|
function forceCheck() {
|
||||||
|
|
@ -36,17 +37,23 @@
|
||||||
|
|
||||||
<div class="alert alert-info mb-4" role="alert">
|
<div class="alert alert-info mb-4" role="alert">
|
||||||
<i class="bi bi-lightbulb me-2"></i>
|
<i class="bi bi-lightbulb me-2"></i>
|
||||||
|
{#if nbfetch > 4}
|
||||||
|
<strong>Tip:</strong> Check your mail is not stuck in the sending box.
|
||||||
|
{:else}
|
||||||
<strong>Tip:</strong> Send an email that represents your actual use case (newsletters,
|
<strong>Tip:</strong> Send an email that represents your actual use case (newsletters,
|
||||||
transactional emails, etc.) for the most accurate results.
|
transactional emails, etc.) for the most accurate results.
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="d-flex align-items-center justify-content-center gap-2 text-muted">
|
<div class="d-flex align-items-center justify-content-center gap-2 text-muted">
|
||||||
<div class="spinner-border spinner-border-sm" role="status"></div>
|
<div class="spinner-border spinner-border-sm" role="status"></div>
|
||||||
{#if nextfetch}
|
{#if fetching || nextfetch === 0}
|
||||||
|
<small>Looking for new email...</small>
|
||||||
|
{:else if nextfetch}
|
||||||
<div>
|
<div>
|
||||||
<small
|
<small>
|
||||||
>Next inbox check in {nextfetch} second{#if nextfetch > 1}s{/if}...</small
|
Next inbox check in {nextfetch} second{#if nextfetch > 1}s{/if}...
|
||||||
>
|
</small>
|
||||||
{#if nbfetch > 0}
|
{#if nbfetch > 0}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
let nextfetch = $state(23);
|
let nextfetch = $state(23);
|
||||||
let nbfetch = $state(0);
|
let nbfetch = $state(0);
|
||||||
let menuOpen = $state(false);
|
let menuOpen = $state(false);
|
||||||
|
let fetching = $state(false);
|
||||||
|
|
||||||
async function fetchTest() {
|
async function fetchTest() {
|
||||||
if (nbfetch > 0) {
|
if (nbfetch > 0) {
|
||||||
|
|
@ -32,6 +33,10 @@
|
||||||
}
|
}
|
||||||
nbfetch += 1;
|
nbfetch += 1;
|
||||||
|
|
||||||
|
// Set fetching state and ensure minimum 500ms display time
|
||||||
|
fetching = true;
|
||||||
|
const startTime = Date.now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const testResponse = await getTest({ path: { id: testId } });
|
const testResponse = await getTest({ path: { id: testId } });
|
||||||
if (testResponse.data) {
|
if (testResponse.data) {
|
||||||
|
|
@ -50,6 +55,16 @@
|
||||||
error = err instanceof Error ? err.message : "Failed to fetch test";
|
error = err instanceof Error ? err.message : "Failed to fetch test";
|
||||||
loading = false;
|
loading = false;
|
||||||
stopPolling();
|
stopPolling();
|
||||||
|
} finally {
|
||||||
|
// Ensure fetching state is displayed for at least 500ms
|
||||||
|
const elapsed = Date.now() - startTime;
|
||||||
|
if (elapsed < 500) {
|
||||||
|
setTimeout(() => {
|
||||||
|
fetching = false;
|
||||||
|
}, 500 - elapsed);
|
||||||
|
} else {
|
||||||
|
fetching = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -151,7 +166,13 @@
|
||||||
</div>
|
</div>
|
||||||
{:else if test && test.status !== "analyzed"}
|
{:else if test && test.status !== "analyzed"}
|
||||||
<!-- Pending State -->
|
<!-- Pending State -->
|
||||||
<PendingState {nextfetch} {nbfetch} {test} on:force-inbox-check={() => fetchTest()} />
|
<PendingState
|
||||||
|
{nextfetch}
|
||||||
|
{nbfetch}
|
||||||
|
{test}
|
||||||
|
{fetching}
|
||||||
|
on:force-inbox-check={() => fetchTest()}
|
||||||
|
/>
|
||||||
{:else if report}
|
{:else if report}
|
||||||
<!-- Results State -->
|
<!-- Results State -->
|
||||||
<div class="fade-in">
|
<div class="fade-in">
|
||||||
|
|
@ -198,7 +219,12 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ScoreCard grade={report.grade} score={report.score} summary={report.summary} {reanalyzing} />
|
<ScoreCard
|
||||||
|
grade={report.grade}
|
||||||
|
score={report.score}
|
||||||
|
summary={report.summary}
|
||||||
|
{reanalyzing}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue