Skip to content

Commit

Permalink
Add loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
medied committed May 20, 2024
1 parent 8a04ae1 commit 0f3d2bf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/link/sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) => {
Expand Down Expand Up @@ -62,6 +63,7 @@ export const Sections = ( {
if ( ! sections && title && lang ) {
wikipediaPreview.getSections( lang, title, ( info ) => {
setSections( info.sections );
setLoading( false );
} );
}
}, [] );

Check warning on line 69 in src/link/sections.js

View workflow job for this annotation

GitHub Actions / build

React Hook useEffect has missing dependencies: 'activeAttributes' and 'sections'. Either include them or remove the dependency array
Expand Down Expand Up @@ -91,7 +93,7 @@ export const Sections = ( {
role="presentation"
></div>
</div>
{ sections && sections.length ? (
{ ! loading && sections && sections.length ? (
<div className={ `${ sectionsPrefix }-list` }>
{ sections.map( ( item, index ) => {
return (
Expand Down Expand Up @@ -126,6 +128,14 @@ export const Sections = ( {
} ) }
</div>
) : null }
{ loading && (
<div className={ `${ sectionsPrefix }-loading` }>
<div className={ `${ sectionsPrefix }-loading-spinner` }></div>
<bdi className={ `${ sectionsPrefix }-loading-message` }>
{ __( 'Loading sections…', 'wikipedia-preview' ) }
</bdi>
</div>
) }
<KeyboardShortcuts
bindGlobal={ true }
shortcuts={ {
Expand Down
27 changes: 27 additions & 0 deletions src/link/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,28 @@ body {
}
}

&-loading {
display: flex;
height: 212px;
flex-direction: column;
justify-content: center;
align-items: center;

&-spinner {
border: 2px solid #f3f3f3;
border-top: 2px solid #36c;
border-radius: 50%;
width: 20px;
height: 20px;
animation: 2s linear infinite;
animation-name: wikipediapreview-edit-sections-loading-spinner;
}

&-text {
align-self: center;
}
}

@media screen and (max-width: 782px) {
width: 100%;
max-height: unset;
Expand Down Expand Up @@ -831,3 +853,8 @@ body {
transform: translateX(calc(100vw - 150px));
}
}

@keyframes wikipediapreview-edit-sections-loading-spinner {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

0 comments on commit 0f3d2bf

Please sign in to comment.