Browse Source

fix: profile works again, smol unused stuff

pull/48/head
Inhji Y. 12 months ago
parent
commit
c875513d3b
  1. 4
      apps/tags/lib/tags/tag.ex
  2. 7
      apps/tomie_web/lib/tomie_web/controllers/profile_controller.ex
  3. 2
      apps/tomie_web/lib/tomie_web/live/tag_live/new.ex
  4. 9
      apps/tomie_web/lib/tomie_web/router.ex
  5. 2
      apps/tomie_web/lib/tomie_web/templates/layout/navigation.html.eex
  6. 1
      apps/tomie_web/lib/tomie_web/templates/profile/edit.html.eex
  7. 33
      apps/tomie_web/lib/tomie_web/templates/profile/form.html.eex
  8. 31
      apps/tomie_web/lib/tomie_web/templates/profile/show.html.eex
  9. 8
      apps/tomie_web/lib/tomie_web/views/icon_view.ex
  10. 9
      apps/tomie_web/lib/tomie_web/views/profile_view.ex

4
apps/tags/lib/tags/tag.ex

@ -14,7 +14,7 @@ defmodule Tags.Tag do
timestamps()
end
def changeset(tag \\ %Tags.Tag{}, attrs \\ %{}) do
def changeset(tag \\ %Tag{}, attrs \\ %{}) do
tag
|> cast(attrs, @attrs)
|> validate_required([:name])
@ -23,7 +23,7 @@ defmodule Tags.Tag do
|> Slug.unique_constraint()
end
def insert_changeset(tag \\ %Tags.Tag{}, attrs \\ %{}) do
def insert_changeset(tag \\ %Tag{}, attrs \\ %{}) do
tag
|> cast(attrs, @attrs)
|> validate_required([:name])

7
apps/tomie_web/lib/tomie_web/controllers/profile_controller.ex

@ -1,16 +1,21 @@
defmodule TomieWeb.ProfileController do
use TomieWeb, :controller
alias Tomie.Users
alias Tomie.Users.User
defp sync_user(conn, user), do: Pow.Plug.create(conn, user)
def show(conn, _params) do
user = Pow.Plug.current_user(conn)
IO.inspect(user)
render(conn, "show.html", user: user)
end
def edit(conn, _params) do
user = Pow.Plug.current_user(conn)
changeset = Users.User.profile_changeset(user)
changeset = User.profile_changeset(user)
render(conn, "edit.html", user: user, changeset: changeset)
end

2
apps/tomie_web/lib/tomie_web/live/tag_live/new.ex

@ -18,7 +18,7 @@ defmodule TomieWeb.TagLive.New do
{:noreply, assign(socket, changeset: changeset)}
end
def handle_event("save", %{"tag" => %{"name" => name} = params}, socket) do
def handle_event("save", %{"tag" => params}, socket) do
case Tags.create_tag(params) do
{:ok, tag} ->
{:noreply,

9
apps/tomie_web/lib/tomie_web/router.ex

@ -66,13 +66,10 @@ defmodule TomieWeb.Router do
live "/listens/artist/:id", ArtistLive.Show
live "/listens/album/:id", AlbumLive.Show
live "/profile", ProfileLive.Show
live "/profile/edit", ProfileLive.Edit
get "/r/:id/:slug", LinkController, :redirect
# resources "/profile", ProfileController,
# only: [:show, :edit, :update],
# singleton: true
resources "/profile", ProfileController,
only: [:show, :edit, :update],
singleton: true
end
end

2
apps/tomie_web/lib/tomie_web/templates/layout/navigation.html.eex

@ -56,7 +56,7 @@
<li><%= active_link @conn, "Sign in", to: Routes.pow_session_path(@conn, :new) %></li>
<% else %>
<li>
<%= active_link @conn, to: Routes.live_path(@conn, TomieWeb.ProfileLive.Show) do %>
<%= active_link @conn, to: Routes.profile_path(@conn, :show) do %>
<span class="icon">
<%= IconView.icon(:user) %>
</span>

1
apps/tomie_web/lib/tomie_web/templates/profile/edit.html.eex

@ -0,0 +1 @@
<%= render "form.html", Map.put(assigns, :action, Routes.profile_path(@conn, :update)) %>

33
apps/tomie_web/lib/tomie_web/templates/profile/form.html.eex

@ -0,0 +1,33 @@
<%= form_for @changeset, @action, fn f -> %>
<fieldset>
<%= label f, :name %>
<%= text_input f, :name%>
<%= error_tag f, :name %>
</fieldset>
<fieldset>
<%= label f, :username %>
<%= text_input f, :username %>
<%= error_tag f, :username %>
</fieldset>
<fieldset>
<%= label f, :theme, "Frontend Theme" %>
<%= select f, :theme, ["light", "dark"] %>
<%= error_tag f, :theme %>
</fieldset>
<fieldset>
<%= label f, :token, "API Token" %>
<%= text_input f, :token, readonly: true %>
<%= error_tag f, :token %>
</fieldset>
<fieldset>
<%= label f, :reset_token, "Reset API Token" %>
<%= checkbox f, :reset_token %>
<%= error_tag f, :reset_token %>
</fieldset>
<%= submit "submit", class: "button" %>
<% end %>

31
apps/tomie_web/lib/tomie_web/templates/profile/show.html.eex

@ -0,0 +1,31 @@
<nav>
<ul>
<li>
<%= link "Edit Profile", to: Routes.profile_path(@conn, :edit) %>
</li>
<li>
<%= link "Edit User", to: Routes.pow_registration_path(@conn, :edit) %>
</li>
<li>
<%= link "Sign out",
to: Routes.pow_session_path(@conn, :delete),
method: :delete, class: "flex-auto" %>
</li>
</ul>
</nav>
<div class="card">
<div class="content">
<h1><%= @user.name %></h1>
<ul>
<li>Username: <%= @user.username %></li>
<li>Email: <%= @user.email %></li>
<li>Token: <%= @user.token %></li>
<li>Theme: <%= @user.theme %></li>
</ul>
</div>
</div>
<a href="<%= bookmarklet(@conn) %>" class="button">Bookmarklet</a>

8
apps/tomie_web/lib/tomie_web/views/icon_view.ex

@ -132,14 +132,6 @@ defmodule TomieWeb.IconView do
"""
end
defp svg_icon(:bookmark) do
~E"""
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
<path d="M2 2c0-1.1.9-2 2-2h12a2 2 0 0 1 2 2v18l-8-4-8 4V2z"/>
</svg>
"""
end
defp svg_icon(:music) do
~E"""
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">

9
apps/tomie_web/lib/tomie_web/views/profile_view.ex

@ -1,12 +1,9 @@
defmodule TomieWeb.ProfileView do
use TomieWeb, :view
alias TomieWeb.ProfileLive
def bookmarklet(current_user) do
# url = Routes.live_url(TomieWeb.Endpoint, TomieWeb.BookmarkLive.New)
# user = Pow.Plug.current_user(conn)
url = "test"
user = current_user
def bookmarklet(conn) do
url = Routes.live_url(TomieWeb.Endpoint, TomieWeb.BookmarkLive.New)
user = Pow.Plug.current_user(conn)
"""
javascript:(function() {

Loading…
Cancel
Save