PageState Demo
Mix.install([
{:page_state, path: __DIR__}
])
Section
defmodule DashboardLive do
use PageState
params do
param :query, :string do
key("q")
end
param(:include_count, :boolean, default: false)
param(:category, {:one_of, [:a, :b, :c]}, default: :a)
nested :task_section do
key("t")
param(:page_number, :integer, default: 1)
param(:page_size, :integer, default: 10)
param(:sort_dir, {:one_of, [:asc, :desc]}, default: :asc)
end
end
end
raw_params = %{
"q" => "some search",
"include_count" => "true",
"t" => %{
"page_number" => "2",
"page_size" => "20"
}
}
state = DashboardLive.State.decode(raw_params)
DashboardLive.State.encode(%DashboardLive.State{
query: "some search",
include_count: true,
category: :b,
task_section: %DashboardLive.State.TaskSection{
page_number: 2,
page_size: 20,
sort_dir: :desc
}
})