hiyaryan / the-cdj

The Cognitive Distortion Journal (CDJ) is a smart journaling tool that helps remedy distorted thinking. It can feel impossible to follow the CBT technique of labeling distorted thinking and finding alternative modes of thought (i.e. reframing) while cognitive distortions are occurring. The CDJ does that work for you. -- The CDJ is in beta testing!!
https://thecdj.app
2 stars 0 forks source link

Add ability to update an entry title. #126

Closed hiyaryan closed 4 months ago

hiyaryan commented 5 months ago

Entry titles may now be updated by clicking on the title, entering data in the TextField that appears, then pressing enter or clicking away (or hitting escape) to submit or exit. It uses the same logic and components as update entry content. To do this, updates to the backend's updateEntry controller were made so that it could be reused. This was done by checking the req body and uses conditionals to update the title or entry content, whichever is in the req body. Since updateEntry can have a req body without entry content, content requirement from joi entrySchema validation had to be removed.

Note that this is a the quick solution. It simply copies existing code that provides the functionality. This provides a refactoring opportunity. To reduce duplication, the edit functionality in the Analysis component can be abstracted using callbacks. This will remove much of the duplication, but be mindful of state that is affected only by changes made to the title or the entry content such as, the conditionals for LinearProgress components and the key down functionalities.

Additionally, the updateEntry controller can also be improved by simply passing the req body to the update method that can parse it and update all fields after being validated. This will be a little more involved because anytime the content of an entry is updated the associated analysis_content is also updated. It might be worth looking into mongoose middleware for the chosen update method that can be triggered and run the request for a new analysis.

closes #122