Added users page and user viewing

This commit is contained in:
2026-04-02 03:28:09 -04:00
parent 0f41e86cf0
commit 580265bc51
8 changed files with 355 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
defmodule Mixer.Accounts do
use Ash.Domain, otp_app: :mixer, extensions: [AshAdmin.Domain]
use Ash.Domain, otp_app: :mixer, extensions: [AshTypescript.Rpc, AshAdmin.Domain]
admin do
show? true
@@ -10,4 +10,10 @@ defmodule Mixer.Accounts do
resource Mixer.Accounts.User
resource Mixer.Accounts.ApiKey
end
typescript_rpc do
resource Mixer.Accounts.User do
rpc_action :read_user, :read
end
end
end

View File

@@ -4,7 +4,7 @@ defmodule Mixer.Accounts.User do
domain: Mixer.Accounts,
data_layer: AshPostgres.DataLayer,
authorizers: [Ash.Policy.Authorizer],
extensions: [AshAuthentication]
extensions: [AshAuthentication, AshTypescript.Resource]
authentication do
add_ons do
@@ -66,6 +66,10 @@ defmodule Mixer.Accounts.User do
repo Mixer.Repo
end
typescript do
type_name "users"
end
actions do
defaults [:read]
@@ -282,6 +286,10 @@ defmodule Mixer.Accounts.User do
bypass AshAuthentication.Checks.AshAuthenticationInteraction do
authorize_if always()
end
policy action_type(:read) do
authorize_if always()
end
end
attributes do

View File

@@ -6,14 +6,22 @@ defmodule MixerWeb.PageController do
end
def index(conn, _params) do
render_spa(conn, nil)
render_spa(conn, %{page: "feed", tweet_id: nil, user_id: nil})
end
def show(conn, %{"tweet_id" => tweet_id}) do
render_spa(conn, tweet_id)
render_spa(conn, %{page: "tweet", tweet_id: tweet_id, user_id: nil})
end
defp render_spa(conn, tweet_id) do
def users_index(conn, _params) do
render_spa(conn, %{page: "users", tweet_id: nil, user_id: nil})
end
def user_show(conn, %{"user_id" => user_id}) do
render_spa(conn, %{page: "user-detail", tweet_id: nil, user_id: user_id})
end
defp render_spa(conn, %{page: page, tweet_id: tweet_id, user_id: user_id}) do
asset_host = Application.get_env(:waffle, :asset_host, "http://localhost:3900")
bucket = Application.get_env(:waffle, :bucket, "mixer-bucket")
@@ -22,7 +30,9 @@ defmodule MixerWeb.PageController do
|> render(:index,
current_user: conn.assigns[:current_user],
media_host: "#{asset_host}/#{bucket}",
tweet_id: tweet_id
page: page,
tweet_id: tweet_id,
user_id: user_id
)
end
end

View File

@@ -2,5 +2,7 @@
data-current-user-id={if @current_user, do: @current_user.id, else: ""}
data-current-user-email={if @current_user, do: @current_user.email, else: ""}
data-asset-host={@media_host}
data-tweet-id={@tweet_id || ""}>
data-page={@page}
data-tweet-id={@tweet_id || ""}
data-user-id={@user_id || ""}>
</div>

View File

@@ -40,6 +40,8 @@ defmodule MixerWeb.Router do
get "/", PageController, :home
get "/feed", PageController, :index
get "/feed/:tweet_id", PageController, :show
get "/users", PageController, :users_index
get "/users/:user_id", PageController, :user_show
post "/rpc/run", AshTypescriptRpcController, :run
post "/rpc/validate", AshTypescriptRpcController, :validate
post "/upload", UploadController, :create