typespec form components more

This commit is contained in:
shibao 2022-02-10 23:36:31 -05:00
parent f9d9fd1075
commit 845ebc3bc6
5 changed files with 30 additions and 7 deletions

View File

@ -4,15 +4,21 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
""" """
use CanneryWeb, :live_component use CanneryWeb, :live_component
alias Cannery.{Ammo, Containers} alias Cannery.{Ammo, Accounts.User, Containers, Containers.Container}
alias Cannery.{Ammo.AmmoType, Containers.Container} alias Cannery.Ammo.{AmmoType, AmmoGroup}
alias Ecto.Changeset alias Ecto.Changeset
alias Phoenix.LiveView.Socket
@impl true @impl true
@spec update(
%{:ammo_group => AmmoGroup.t(), :current_user => User.t(), optional(any) => any},
Socket.t()
) :: {:ok, Socket.t()}
def update(%{ammo_group: _ammo_group} = assigns, socket) do def update(%{ammo_group: _ammo_group} = assigns, socket) do
socket |> assign(assigns) |> update() socket |> assign(assigns) |> update()
end end
@spec update(Socket.t()) :: {:ok, Socket.t()}
def update(%{assigns: %{ammo_group: ammo_group, current_user: current_user}} = socket) do def update(%{assigns: %{ammo_group: ammo_group, current_user: current_user}} = socket) do
changeset = Ammo.change_ammo_group(ammo_group) changeset = Ammo.change_ammo_group(ammo_group)
containers = Containers.list_containers(current_user) containers = Containers.list_containers(current_user)

View File

@ -4,10 +4,15 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do
""" """
use CanneryWeb, :live_component use CanneryWeb, :live_component
alias Cannery.Ammo alias Cannery.{Accounts.User, Ammo, Ammo.AmmoType}
alias Ecto.Changeset alias Ecto.Changeset
alias Phoenix.LiveView.Socket
@impl true @impl true
@spec update(
%{:ammo_type => AmmoType.t(), :current_user => User.t(), optional(any) => any},
Socket.t()
) :: {:ok, Socket.t()}
def update(%{ammo_type: ammo_type} = assigns, socket) do def update(%{ammo_type: ammo_type} = assigns, socket) do
{:ok, socket |> assign(assigns) |> assign(:changeset, Ammo.change_ammo_type(ammo_type))} {:ok, socket |> assign(assigns) |> assign(:changeset, Ammo.change_ammo_type(ammo_type))}
end end

View File

@ -4,11 +4,15 @@ defmodule CanneryWeb.ContainerLive.FormComponent do
""" """
use CanneryWeb, :live_component use CanneryWeb, :live_component
alias Cannery.{Accounts.User, Containers, Containers.Container}
alias Cannery.Containers
alias Ecto.Changeset alias Ecto.Changeset
alias Phoenix.LiveView.Socket
@impl true @impl true
@spec update(
%{:container => Container.t(), :current_user => User.t(), optional(any) => any},
Socket.t()
) :: {:ok, Socket.t()}
def update(%{container: container} = assigns, socket) do def update(%{container: container} = assigns, socket) do
assigns = assigns |> Map.put(:changeset, container |> Containers.change_container()) assigns = assigns |> Map.put(:changeset, container |> Containers.change_container())
{:ok, socket |> assign(assigns)} {:ok, socket |> assign(assigns)}

View File

@ -4,11 +4,15 @@ defmodule CanneryWeb.InviteLive.FormComponent do
""" """
use CanneryWeb, :live_component use CanneryWeb, :live_component
alias Cannery.{Accounts.User, Invites, Invites.Invite}
alias Cannery.Invites
alias Ecto.Changeset alias Ecto.Changeset
alias Phoenix.LiveView.Socket
@impl true @impl true
@spec update(
%{:invite => Invite.t(), :current_user => User.t(), optional(any) => any},
Socket.t()
) :: {:ok, Socket.t()}
def update(%{invite: invite} = assigns, socket) do def update(%{invite: invite} = assigns, socket) do
changeset = Invites.change_invite(invite) changeset = Invites.change_invite(invite)

View File

@ -5,9 +5,13 @@ defmodule CanneryWeb.TagLive.FormComponent do
use CanneryWeb, :live_component use CanneryWeb, :live_component
alias Cannery.Tags alias Cannery.Tags
alias Cannery.{Accounts.User, Tags.Tag}
alias Ecto.Changeset alias Ecto.Changeset
alias Phoenix.LiveView.Socket
@impl true @impl true
@spec update(%{:tag => Tag.t(), :current_user => User.t(), optional(any) => any}, Socket.t()) ::
{:ok, Socket.t()}
def update(%{tag: tag} = assigns, socket) do def update(%{tag: tag} = assigns, socket) do
{:ok, socket |> assign(assigns) |> assign(:changeset, Tags.change_tag(tag))} {:ok, socket |> assign(assigns) |> assign(:changeset, Tags.change_tag(tag))}
end end