I have the next problem.
In the platform I am building there are users that you can follow or unfollow. Also, if you are looking at your own profile, you can edit it (instead of following it).
Currently I have one state /profile/:id that renders the user profile with angularjs
I have one template _profile.html and a controller profileCrtl. The controller is responsible to check if the profile is authenticated and therefore to set different variables to show different html tags. For example if the user is seeing his own profile, we are not going to show the follow button. Instead, he/she will see an edit button to allow the user to edit his/her profile.
The problem with this approach is that porfileCtrl and _profile.html are responsible to manage the public profile user view and the private profile view and I think it is not a good design pattern.
I am considering three solutions to improve my code:
-
To use two templates, _publicProfile and _privateProfile and keep only one controller profileCtrl. We will have two states.
-
To use two templates, _publicProfile and _privateProfile and to have two controllers. profilePublicCtrl and profilePrivateCtrl. (I feel this may be the best solution). We will have two states.
-
To have only one state and change templateUrl dinamically if user is the authenticated user or a public user.
What do you think is the best solution? Do you have any alternative to the ones considered above? When and where in the code should I check if the profile the user is viewing is a public profile or the user’s profile?
I have already looked up a lot of answers online and there seems to be a lot of opinions and I find difficult to know what is the best design pattern. I appreciate your input. Thank you.
Aucun commentaire:
Enregistrer un commentaire