From 0f3d2bf01a2a605ed7b10e8b90daf9ad057bb3f0 Mon Sep 17 00:00:00 2001 From: eamedina Date: Mon, 20 May 2024 15:49:44 -0400 Subject: [PATCH] Add loading state --- src/link/sections.js | 12 +++++++++++- src/link/style.scss | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/link/sections.js b/src/link/sections.js index 7a82ee4..cd18f03 100644 --- a/src/link/sections.js +++ b/src/link/sections.js @@ -14,6 +14,7 @@ export const Sections = ( { const [ sections, setSections ] = useState( null ); const [ hoveredIndex, setHoverIndex ] = useState( -1 ); const [ selectedSection, setSelectedSection ] = useState( null ); + const [ loading, setLoading ] = useState( true ); const sectionsPrefix = 'wikipediapreview-edit-sections'; const isItemSelected = ( item ) => { @@ -62,6 +63,7 @@ export const Sections = ( { if ( ! sections && title && lang ) { wikipediaPreview.getSections( lang, title, ( info ) => { setSections( info.sections ); + setLoading( false ); } ); } }, [] ); @@ -91,7 +93,7 @@ export const Sections = ( { role="presentation" > - { sections && sections.length ? ( + { ! loading && sections && sections.length ? (
{ sections.map( ( item, index ) => { return ( @@ -126,6 +128,14 @@ export const Sections = ( { } ) }
) : null } + { loading && ( +
+
+ + { __( 'Loading sections…', 'wikipedia-preview' ) } + +
+ ) }