-
Notifications
You must be signed in to change notification settings - Fork 9
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
Users Can Manage Resources #7
Comments
Hi @SophieDeBenedetto, after chatt, I had been reflecting about this name what we use. Maybe it isn't a good name though, because many libraries and the entire industry use or reference "resource" as a term by part of some domain in some context, very generic, and after my researching maybe we should change |
I agree with @herminiotorres! To be honest, I was a little bit confused because Phoenix already use the name "resource" with a different meaning. I think that "content" could makes things clearer and more explicit for us! |
Thanks for sharing your thoughts @cristineguadelupe and @herminiotorres! I agree |
I like it, we definitely need to go forward and use it |
We have made some great progress on this issue with this PR #18. Let's work on the following steps next:
First, we'll get each of these pages working as their own separate live view. Once that's done, I'll walk you guys through adding some modal functionality so that a user can edit a post without getting redirected to a different live view. Instead a modal will pop up with the edit form. That's for next time though 😄 |
Create New Post FeatureDesired BehaviorAs a user
|
Docs on live actions https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.Router.html |
New Post Form Submission FeatureWe will do three things to get this working:
Making the current user available to the form component
# this will run when "user_token" is present in the session map, which will happen if there is a logged-in user
def mount(_params, %{"user_token" => token}, socket) do
# ...
end
# I think you will want to assign current_user to `nil` here so that you can still refer to `@current_user` assignment in the template to check its value. If there is no such key in socket assigns at all, the template will through an error. You can double check me on this though.
def mount(_params, _session, socket) do
{:ok, assign(socket, :current_user, nil)}
end In the def mount(_params, %{"user_token" => token}, socket) do
current_user = Accounts.get_user_by_session_token(token)
{:ok, assign(socket, :current_user, current_user)}
end
Once that is done, you're ready to pass the current user into the When you call the
Now, recalls that def update(assigns, socket)
# ...
end The def update(assigns, socket)
{:ok,
socket
|> assign(assigns)
# ...
}
end You are making sure that the key/value pairs you call the component with get added to the component's socket assigns so that you can look them up later. This way, when you handle the form event to create a new post, you have access to That's it! With this code, you have ensured that the Submitting the New Post FormUse the docs here to guide you https://hexdocs.pm/phoenix_live_view/form-bindings.html#form-events.
def handle_event("save", %{"post" => post_params}, socket) do
end
Handling Successful Post Creation
|
Users can delete postsAs a user Implementation
|
Also, I am thinking how we can do a better shape to our app architecture. What do you say it about my suggestion to refactoring what we have until now? |
Next Steps@herminiotorres will open up a new issue that describes the user story here 😄 |
User Story
As a user
When I visit
/resources
(or whatever we decide to call this route)Then I can create a new resource,
View all resources,
View a single resource with all of its details,
Edit an existing resource, or
Delete a resource
Implementation Details
This page should be supported by a live view that uses LiveView live_actions to control what the user sees and how they can interact with the page.
Let's start by delivering:
/resources
and see a list of all of the resources.This should mount a live view with the
live_action
set to:index
and display a list of all resources. For more info on routing with live_actions, see the docs here https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.Router.html#live/4-actions-and-live-navigation.The text was updated successfully, but these errors were encountered: