Skip to content

Commit

Permalink
feat: status icons
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaucau committed Apr 15, 2024
1 parent 4c126c2 commit 8637991
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 38 deletions.
16 changes: 4 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"format": "wp-scripts format"
},
"dependencies": {
"@wordpress/icons": "^9.46.0",
"@wordpress/scripts": "^27.6.0",
"ts-dom-utils": "^2.2.0"
},
Expand Down
4 changes: 3 additions & 1 deletion src/components/BulkGenerateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export default function BulkGenerateModal({
.then((alt) => {
setAltGenerationMap(
(prevMap) =>
new Map(prevMap.set(id, { ...details, alt, status: "done" })),
new Map(
prevMap.set(id, { ...details, alt, status: "generated" }),
),
);
})
.catch((error) => {
Expand Down
61 changes: 37 additions & 24 deletions src/components/BulkGenerationStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,54 @@
import { _x, sprintf } from "@wordpress/i18n";
import { Flex, Spinner } from "@wordpress/components";
import { Flex, Icon, Spinner } from "@wordpress/components";
import { check, next, warning } from "@wordpress/icons";
import type { AltGenerationDetails } from "../types";

export default function BulkGenerationStatus({
details,
}: BulkGenerationStatusProps) {
const { status, message } = details;

switch (status) {
case "generating":
return (
<Flex justify="start">
{/*@ts-ignore - wrong Spinner prop types*/}
return (
<Flex justify="start">
{status === "generating" ? (
<>
{/* @ts-ignore - wrong Spinner prop types */}
<Spinner />
{_x(
"Generating...",
"Generation status",
"alt-text-generator-gpt-vision",
)}
</Flex>
);
case "done":
return _x("Done", "Generation status", "alt-text-generator-gpt-vision");
case "skipped":
return _x(
"Skipped",
"Generation status",
"alt-text-generator-gpt-vision",
);
case "error":
return sprintf(
_x("Error: %s", "Generation status", "alt-text-generator-gpt-vision"),
message,
);
default:
return "";
}
</>
) : status === "generated" ? (
<>
<Icon icon={check} />
{_x(
"Generated",
"Generation status",
"alt-text-generator-gpt-vision",
)}
</>
) : status === "skipped" ? (
<>
<Icon icon={next} />
{_x("Skipped", "Generation status", "alt-text-generator-gpt-vision")}
</>
) : status === "error" ? (
<>
<Icon icon={warning} />
{sprintf(
_x(
"Error: %s",
"Generation status",
"alt-text-generator-gpt-vision",
),
message,
)}
</>
) : null}
</Flex>
);
}

export type BulkGenerationStatusProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Attachment } from "@wordpress/core-data";

export interface AltGenerationDetails {
status: "" | "generating" | "done" | "skipped" | "error";
status: "" | "generating" | "generated" | "skipped" | "error";
message?: string;
alt: Attachment<"view">["alt_text"];
title?: Attachment<"view">["title"]["rendered"];
Expand Down

0 comments on commit 8637991

Please sign in to comment.