-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3096] Content-Create-Item: Added an identifier when user inputs meta… #3110
base: dev
Are you sure you want to change the base?
Conversation
… discription manualy
…eate-Item-Updated' into fix/3096-Content-Create-Item-Updated
@@ -46,7 +46,12 @@ export default memo(function Editor({ | |||
const dispatch = useDispatch(); | |||
const isNewItem = itemZUID.slice(0, 3) === "new"; | |||
const { data: fields } = useGetContentModelFieldsQuery(modelZUID); | |||
const { data, web } = useSelector( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The item is already in scope e.g the item prop. Don't see the reason for this selector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I totally missed it. Updated this already
@@ -355,6 +361,32 @@ export default memo(function Editor({ | |||
} | |||
}, [isNewItem, setIsLoaded, applyDefaultValuesToItemData]); | |||
|
|||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is really hard to follow. I would expect this logic to exist within the call stack of the change handler. But will let @finnar-bin weigh in as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I kind of agree with what @agalin920 commented.
Correct me if I'm wrong but wouldn't it be easier to just have 3 states (metaDescription, og_description and tc_description) that holds a boolean value, then set the state to true if the user has done a manual input on those fields (the field names are static so it should be easy to find out through the onChange handler if any of those fields have been manually updated). Then on these lines do not do the dispatch if the state is true since that would mean the user has performed a manual update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@finnar-bin , this would be the case if "description" and "metaDescription" consistently matched after the page load (without persisting any data). I had a similar thought initially, but things get more complex when the user refreshes the page or navigates to a different one. In such scenarios, metaDescription retains its previous value even if the meta component hasn’t fully loaded in the view, causing it to mistakenly assume that metaDescription has changed. That said, I might have missed something, so a walkthrough would be helpful to clarify.
useEffect(() => { | ||
if (!isNewItem) return; | ||
const isMetaDescriptionInitState = metaDescription === web?.metaDescription; | ||
const isDescriptionChanged = data?.description !== web?.metaDescription; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful here, this is incorrect. Data key is the set fields on a model. Therefore data.description is not a guaranteed field nor is the set logic looking for this field. Fields are defined by the user e.g myDescription, someDescription, mySecondTextField etc...
@@ -355,6 +361,32 @@ export default memo(function Editor({ | |||
} | |||
}, [isNewItem, setIsLoaded, applyDefaultValuesToItemData]); | |||
|
|||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I kind of agree with what @agalin920 commented.
Correct me if I'm wrong but wouldn't it be easier to just have 3 states (metaDescription, og_description and tc_description) that holds a boolean value, then set the state to true if the user has done a manual input on those fields (the field names are static so it should be easy to find out through the onChange handler if any of those fields have been manually updated). Then on these lines do not do the dispatch if the state is true since that would mean the user has performed a manual update.
…eate-Item-Updated' into fix/3096-Content-Create-Item-Updated
bf309c8
to
b0f7cc5
Compare
…eate-Item-Updated' into fix/3096-Content-Create-Item-Updated
… discription manualy