Extract the cookie parser, export-payload builder and fee-status helper into their own modules and remove the filter/sort/load helpers the database pushdown made dead, so the overview LiveView stays a thin coordinator over focused units.
28 lines
987 B
Elixir
28 lines
987 B
Elixir
defmodule MvWeb.MemberLive.Index.Cookie do
|
|
@moduledoc """
|
|
Shared cookie-header parsing for the member-overview persistence chain.
|
|
|
|
Both `MvWeb.MemberLive.Index.ViewSettings` and
|
|
`MvWeb.MemberLive.Index.FieldSelection` read their persisted value from the
|
|
raw request `Cookie:` header on the disconnected mount, so the parsing lives
|
|
here once.
|
|
"""
|
|
|
|
@doc """
|
|
Parses a raw `Cookie:` request-header string into a `%{name => value}` map,
|
|
URL-decoding each value. A valueless entry (`"key"`) maps to `""`; malformed
|
|
segments are skipped.
|
|
"""
|
|
@spec parse_header(String.t()) :: %{String.t() => String.t()}
|
|
def parse_header(cookie_header) when is_binary(cookie_header) do
|
|
cookie_header
|
|
|> String.split(";")
|
|
|> Enum.map(&String.trim/1)
|
|
|> Enum.map(&String.split(&1, "=", parts: 2))
|
|
|> Enum.reduce(%{}, fn
|
|
[key, value], acc -> Map.put(acc, key, URI.decode(value))
|
|
[key], acc -> Map.put(acc, key, "")
|
|
_, acc -> acc
|
|
end)
|
|
end
|
|
end
|