Focal point not exposed in REST API #4082
Replies: 4 comments 7 replies
-
Hey @RickGeersing this is not a bug, currently the focal point data is only used to tell sharp how to crop the photo so we use it on the request and do not store it. I can see how it might be useful to store on the top level media though. I think this is more of a feature request than a bug so I am going to move this to a discussion. |
Beta Was this translation helpful? Give feedback.
-
After some digging is sawed that the focal point is exposed in the express request object. You can store this info via this hook on to a field: import { CollectionAfterChangeHook } from "payload/types"
export const storeFocalPointInfo: CollectionAfterChangeHook = async ({
doc,
req,
}) => {
// Check if change is with an uploadEdit
if (!req?.query?.uploadEdits) return doc
type FocalPoint = {
x: string,
y: string,
}
const focalPoint: FocalPoint = req?.query?.uploadEdits['focalPoint']
doc.focalPoint = {
x: Math.round(new Number(focalPoint.x).valueOf() * 100) / 100,
y: Math.round(new Number(focalPoint.y).valueOf() * 100) / 100,
}
return doc
} The Problem I'm facing now is that the focal point selector cant read the value back. payload/packages/payload/src/admin/components/elements/EditUpload/index.tsx Lines 252 to 261 in 4cfe473 Cant find any hook to push the stored value into the modal or trigger JavaScript to write data to the input fields. |
Beta Was this translation helpful? Give feedback.
-
@JarrodMFlesch, any chance you guys are thinking of moving this onto the roadmap? Appreciate you guys are busy with the move to Next.js, but this is a really important feature for our use case. If you're open to accepting a PR, i'd be happy to work on this if someone could point me in the right direction. Thanks! |
Beta Was this translation helpful? Give feedback.
-
This feature has been released in https://github.com/payloadcms/payload/releases/tag/v2.18.0 via #6364.
|
Beta Was this translation helpful? Give feedback.
-
Link to reproduction
No response
Describe the Bug
When I change the focal point of an media item I want to have that focal point in my frontend. As of now there is no focal point data in the response of that media item. Or am I doing something wrong with the focal point settings?
To Reproduce
focalPoint
totrue
on theupload
section of that collection.edit image
Payload Version
2.1.0
Adapters and Plugins
No response
Beta Was this translation helpful? Give feedback.
All reactions