Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat: added loading state

Elijah Potter756e557cf34e
diff --git a/src/harper/DataBlock.ts b/src/harper/DataBlock.ts
index f8efbf0b0..bb03e9ea1 100644
--- a/src/harper/DataBlock.ts
+++ b/src/harper/DataBlock.ts
@@ -30,8 +30,6 @@ export default class DataBlock {
cont.getAttribute('data-wp-block-attribute-key') ??
'content';
- console.log(this.getClientId());
-
await updateBlockAttributes(this.getClientId(), {
[attributeName]: newContent,
});
diff --git a/src/harper/LintList.tsx b/src/harper/LintList.tsx
index 95026c89c..f94082ab0 100644
--- a/src/harper/LintList.tsx
+++ b/src/harper/LintList.tsx
@@ -1,20 +1,37 @@
import React from 'react';
import { LintBox } from './Box';
import LintListItem from './LintListItem';
-import { Animate } from '@wordpress/components';
+import { Animate, Spinner } from '@wordpress/components';
-export default function LintList({ lintBoxes }: { lintBoxes: LintBox[] }) {
+export default function LintList({
+ lintBoxes,
+ loading,
+}: {
+ lintBoxes: LintBox[];
+ loading: boolean;
+}) {
if (lintBoxes.length === 0) {
return (
<div className="harper-solved-cont">
- <Animate type="slide-in">
+ <Animate type="appear" options={{ origin: 'middle' }}>
{({ className }) => (
<div className={className ?? ''}>
- <h2>LGTM πŸ‘</h2>
- <p>
- Harper could not find any problems with your
- work.
- </p>
+ {loading ? (
+ <Spinner
+ style={{
+ height: 'calc(4px * 20)',
+ width: 'calc(4px * 20)',
+ }}
+ />
+ ) : (
+ <>
+ <h2>LGTM πŸ‘</h2>
+ <p>
+ Harper could not find any problems with
+ your work.
+ </p>
+ </>
+ )}
</div>
)}
</Animate>
diff --git a/src/harper/SidebarControl.tsx b/src/harper/SidebarControl.tsx
index 426474857..6f21ae127 100644
--- a/src/harper/SidebarControl.tsx
+++ b/src/harper/SidebarControl.tsx
@@ -12,7 +12,10 @@ export default function SidebarControl() {
[]
);
- const [blocks, setBlocks] = useState<DataBlock[]>([]);
+ const [blocks, setBlocks] = useState<DataBlock[]>(
+ DataBlock.getTerminalDataBlocks()
+ );
+
const updateBlocks = useCallback(
() => setBlocks(DataBlock.getTerminalDataBlocks()),
[]
@@ -36,7 +39,7 @@ export default function SidebarControl() {
[blocks]
);
- const lintBoxes = useLintBoxes(richTexts);
+ const [lintBoxes, loadingLints] = useLintBoxes(richTexts);
const highlights =
documentContainer &&
@@ -55,7 +58,10 @@ export default function SidebarControl() {
return (
<>
{highlights}
- <SidebarTabContainer lintBoxes={lintBoxes.flat()} />
+ <SidebarTabContainer
+ lintBoxes={lintBoxes.flat()}
+ loading={loadingLints}
+ />
</>
);
}
diff --git a/src/harper/SidebarTabContainer.tsx b/src/harper/SidebarTabContainer.tsx
index 4a1c78a15..6199fefcc 100644
--- a/src/harper/SidebarTabContainer.tsx
+++ b/src/harper/SidebarTabContainer.tsx
@@ -6,8 +6,10 @@ import { LintBox } from './Box';
export default function SidebarTabContainer({
lintBoxes,
+ loading,
}: {
lintBoxes: LintBox[];
+ loading: boolean;
}) {
return (
<TabPanel
@@ -19,7 +21,9 @@ export default function SidebarTabContainer({
{(tab) => {
switch (tab.name) {
case 'errors':
- return <LintList lintBoxes={lintBoxes} />;
+ return (
+ <LintList lintBoxes={lintBoxes} loading={loading} />
+ );
case 'settings':
return <LintSettingList />;
}
diff --git a/src/harper/useLintBoxes.ts b/src/harper/useLintBoxes.ts
index 382220349..9b1dccdea 100644
--- a/src/harper/useLintBoxes.ts
+++ b/src/harper/useLintBoxes.ts
@@ -6,14 +6,18 @@ import { useLinter, useLinterConfig } from './HarperContext';
/**
* Lint given elements and return the resulting error targets.
+ * Provides a loading state as well.
* @param richTexts
*/
-export default function useLintBoxes(richTexts: RichText[]): LintBox[][] {
+export default function useLintBoxes(
+ richTexts: RichText[]
+): [LintBox[][], boolean] {
const linter = useLinter();
const [config] = useLinterConfig();
const [targetBoxes, setTargetBoxes] = useState<LintBox[][]>([]);
const [lints, setLints] = useState<Lint[][]>([]);
+ const [loading, setLoading] = useState(true);
const updateLints = useCallback(async () => {
// We assume that a given index always refers to the same rich text field.
@@ -24,6 +28,7 @@ export default function useLintBoxes(richTexts: RichText[]): LintBox[][] {
})
);
+ setLoading(false);
setLints(newLints);
}, [richTexts, linter, config]);
@@ -75,5 +80,5 @@ export default function useLintBoxes(richTexts: RichText[]): LintBox[][] {
};
});
- return targetBoxes;
+ return [targetBoxes, loading];
}