mitgliederverwaltung/lib/mv_web/live/member_live/index/cookie.ex
Simon 77fc11a0b0 refactor(member-live): modularize the overview and drop the superseded in-memory paths
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.
2026-07-06 11:00:29 +02:00

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