Create button with changed state and saving text input

Hi, I have a button underneath a text field. I want it to start with the state variant “Not Saved” and then OnClick switch state to the “Saved” variant while a second interaction updates the rows on a linked supabase table. Once the button has been clicked, the data updated and the state variant changed to “Saved”, if the person starts to type something else I would like the state variant to change back to the “Not Saved” state.

Currently, I have managed to create the OnClick event to update the data in the table on supabase. Also, I have managed to create the state variant to change from “Not Saved” to “Saved” but do not know how to have it change back to “Not Saved” once typing continues in the text field. Does this make sense? Does anyone have any suggestions?

Thank you in advance