Closed zanami closed 1 year ago
Hey 👋 Is it supposed to be something like this?
Did a fix on MetaTitle, but wanted to be sure this is the correct approach. If I get the green light from one of the maintainers I can open a PR.
The solution will be to check in each component: MetaTitle, MetaDescription and MetaImage if we have value on the field. This can be achieved by using a useState and an useEffect that updates this value based on the generate* function response:
const [fieldVisible, setFieldVisible] = useState(false);
const { generateTitle } = pluginConfig;
if (typeof generateTitle === "function") {
setFieldVisible(!!(await generateTitle({ doc: { ...fields }, locale })));
}
}, []);
After that we only add the "if statement" in JSX to disable the Auto-generate button:
{fieldVisible && (
<>
—
<button
onClick={regenerateTitle}
type="button"
style={{
padding: 0,
background: "none",
border: "none",
backgroundColor: "transparent",
cursor: "pointer",
textDecoration: "underline",
color: "currentcolor",
}}
>
Auto-generate
</button>
</>
)}
However since this logic will be repeated, maybe it can be extracted in a small custom hook?
@dragos199993 that's pretty much it but to make this much simpler just add that condition directly to the JSX and don't use state, like this:
{typeof generateTitle === 'function' && (
<>
—
<button
onClick={regenerateTitle}
type="button"
style={{
padding: 0,
background: "none",
border: "none",
backgroundColor: "transparent",
cursor: "pointer",
textDecoration: "underline",
color: "currentcolor",
}}
>
Auto-generate
</button>
</>
)}
I'd happily merge a PR if you wanted to give this a shot!
Am on 1.0.10 and it's still showing 👀 My config:
seo({
collections: [
'pages',
],
uploadsCollection: 'media',
},
),
Hey @edtorba looks like this PR was merged in but not released. I'll cut a new release for this as soon as possible.
@edtorba this was just released in 1.0.11
🎉
Clicking on 'Auto-generate' does nothing in this case. Just a minor UI issue I guess.