-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
159 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { useState } from "@wordpress/element"; | ||
import { | ||
Button, | ||
Flex, | ||
FlexItem, | ||
Modal, | ||
TextControl, | ||
ToggleControl, | ||
} from "@wordpress/components"; | ||
import { __, _n, _x, sprintf } from "@wordpress/i18n"; | ||
|
||
export default function BulkGenerateModal({ | ||
attachment_ids, | ||
onClose, | ||
}: BulkGenerateModalProps) { | ||
const [overwriteExisting, setOverwriteExisting] = useState(false); | ||
const [customPrompt, setCustomPrompt] = useState(""); | ||
const [isGenerating, setIsGenerating] = useState(false); | ||
|
||
const handleStart = () => { | ||
setIsGenerating(true); | ||
// start generating alt texts | ||
}; | ||
|
||
return ( | ||
<Modal | ||
title={__("Generate Alternative Texts", "alt-text-generator-gpt-vision")} | ||
onRequestClose={onClose} | ||
shouldCloseOnClickOutside={false} | ||
shouldCloseOnEsc={!isGenerating} | ||
> | ||
<ToggleControl | ||
label={__( | ||
"Overwrite existing alternative texts", | ||
"alt-text-generator-gpt-vision", | ||
)} | ||
help={ | ||
overwriteExisting | ||
? __( | ||
"The existing alternative texts will be overwritten with the new ones.", | ||
"alt-text-generator-gpt-vision", | ||
) | ||
: __( | ||
"The existing alternative texts will be preserved.", | ||
"alt-text-generator-gpt-vision", | ||
) | ||
} | ||
checked={overwriteExisting} | ||
onChange={setOverwriteExisting} | ||
/> | ||
<TextControl | ||
label={__( | ||
"Additional prompt (optional)", | ||
"alt-text-generator-gpt-vision", | ||
)} | ||
help={__( | ||
"Provide additional instructions for AI to tailor the alt text generation, such as including specific keywords for SEO.", | ||
"alt-text-generator-gpt-vision", | ||
)} | ||
placeholder={_x( | ||
'e.g. Include terms like "AI", "robotics"', | ||
"Additional prompt placeholder", | ||
"alt-text-generator-gpt-vision", | ||
)} | ||
value={customPrompt} | ||
onChange={setCustomPrompt} | ||
/> | ||
|
||
<Flex> | ||
<p> | ||
{sprintf( | ||
_n( | ||
"%d image selected", | ||
"%d images selected", | ||
attachment_ids.length, | ||
"alt-text-generator-gpt-vision", | ||
), | ||
attachment_ids.length, | ||
)} | ||
</p> | ||
|
||
<FlexItem> | ||
<Flex justify="end"> | ||
<Button onClick={onClose} isDestructive> | ||
{__("Cancel", "alt-text-generator-gpt-vision")} | ||
</Button> | ||
|
||
<Button | ||
variant="primary" | ||
disabled={isGenerating} | ||
isBusy={isGenerating} | ||
onClick={handleStart} | ||
> | ||
{__("Start", "alt-text-generator-gpt-vision")} | ||
</Button> | ||
</Flex> | ||
</FlexItem> | ||
</Flex> | ||
</Modal> | ||
); | ||
} | ||
|
||
export type BulkGenerateModalProps = { | ||
attachment_ids: number[]; | ||
onClose: () => void; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { createRoot, useEffect, useState } from "@wordpress/element"; | ||
import { qs } from "ts-dom-utils"; | ||
import BulkGenerateModal from "./components/BulkGenerateModal"; | ||
import { BULK_ACTION_OPTION_VALUE } from "../constants"; | ||
|
||
const reactRoot = document.createElement("div"); | ||
reactRoot.id = "acpl-bulk-generate-alts-app"; | ||
document.body.appendChild(reactRoot); | ||
|
||
const App = () => { | ||
const [isModalOpen, setIsModalOpen] = useState(true); | ||
const [selectedMediaIds, setSelectedMediaIds] = useState<number[]>([]); | ||
|
||
useEffect(() => { | ||
const form = qs<HTMLFormElement>("form#posts-filter"); | ||
if (!form) return; | ||
|
||
const listener = (e: SubmitEvent) => { | ||
e.preventDefault(); | ||
const formData = new FormData(form); | ||
const action = formData.get("action"); | ||
|
||
if (action !== BULK_ACTION_OPTION_VALUE) return; | ||
|
||
const mediaIds = formData.getAll("media[]").map((id) => Number(id)); | ||
setSelectedMediaIds(mediaIds); | ||
|
||
setIsModalOpen(true); | ||
}; | ||
|
||
form.addEventListener("submit", listener); | ||
|
||
return () => { | ||
form.removeEventListener("submit", listener); | ||
}; | ||
}, []); | ||
|
||
return isModalOpen ? ( | ||
<BulkGenerateModal | ||
attachment_ids={selectedMediaIds} | ||
onClose={() => setIsModalOpen(false)} | ||
/> | ||
) : null; | ||
}; | ||
|
||
createRoot(reactRoot).render(<App />); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters