Skip to content

Commit

Permalink
add a loading and empty state
Browse files Browse the repository at this point in the history
  • Loading branch information
aplauche committed Oct 12, 2023
1 parent f88fd7c commit 485e9b2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions better-custom-classes-for-gutenberg.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

/**
* @version 0.2.1
* @version 0.2.2
*/
/*
Plugin Name: Better Custom Classes for Gutenberg
Description: A better interface for applying custom classes to blocks in the gutenberg editor.
Author: Anton Plauche
Version: 0.2.1
Version: 0.2.2
Author URI: https://antonplauche.com
*/

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "better-custom-classes-for-gutenberg",
"version": "0.2.1",
"version": "0.2.2",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Clicking the star icon on a class will toggle whether to include it in your clas

== Changelog ==

= 0.2.2 =
* Adds a loading state for settings screen

= 0.2.1 =
* Patch fatal bug in block editor for non-admins

Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 14 additions & 5 deletions src/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import './admin.scss'
import { useEntityProp, store as coreStore } from '@wordpress/core-data';
import { useDispatch } from '@wordpress/data';
import { render, useState } from '@wordpress/element';
import { render, useState, useEffect } from '@wordpress/element';
import { TextControl, Button } from '@wordpress/components';
import TokenList from '@wordpress/token-list';

Expand All @@ -26,6 +26,14 @@ function ClassLibraryList(){
const [ customClassInput, setCustomClassInput ] = useState( "" );
const [ hasCopied, setHasCopied ] = useState( false );
const [copiedText, copy] = useCopyToClipboard();
const [loaded, setLoaded] = useState(false)

// Check if we've loaded in the class library - this should be easier...
useEffect(() => {
if(loaded === false && Array.isArray(classLibrary)){
setLoaded(true)
}
}, [classLibrary])


// utility to convert array to tokenlist and return it
Expand Down Expand Up @@ -110,7 +118,6 @@ function ClassLibraryList(){
/>



<div className="better-custom-classes__pill-group">
{classLibrary && classLibrary.length > 0 ?
sortAlphaCaseInsensitive(classLibrary).map((item, idx) => (
Expand All @@ -131,9 +138,11 @@ function ClassLibraryList(){
</div>
)
) : (
<>

</>
!loaded ? (
<div>Loading class library...</div>
) : (
<div>No saved classes yet...</div>
)
)}
</div>

Expand Down

0 comments on commit 485e9b2

Please sign in to comment.