# `PgFlowDashboard.Live.LiveHelpers`
[🔗](https://github.com/agoodway/pgflow/blob/v0.1.0/lib/pgflow_dashboard/live/live_helpers.ex#L1)

Shared hooks and utilities for PgFlowDashboard LiveViews.

Provides common functionality for configuration access and real-time subscriptions.

# `determine_view_mode`

Determines view mode based on count and threshold.

Returns `:card` for small datasets (≤ threshold) and `:list` for larger ones.
Default threshold is 12 (fits nicely in a 3-column grid).

## Examples

    iex> determine_view_mode(5)
    :card

    iex> determine_view_mode(15)
    :list

    iex> determine_view_mode(15, 20)
    :card

# `format_duration`

Formats a duration in milliseconds for display.

Formats in a compact style suitable for dashboards: "50ms", "1.5s", "2.3m", "1.2h".

# `format_relative_time`

Formats a datetime relative to now.

Returns strings like "in 5 minutes", "in 2 hours", "3 minutes ago".

# `format_timestamp`

Formats a timestamp for display in the configured time zone.

# `on_mount`

Assigns dashboard configuration for LiveViews.

This function should be called in the `on_mount` callback:

    def on_mount(:default, _params, session, socket) do
      PgFlowDashboard.Live.LiveHelpers.on_mount(session, socket)
    end

# `paginate_results`

Splits a list fetched with limit+1 into results and has_more flag.

When fetching paginated data, request `page_size + 1` items. This function
splits the result to determine if there are more items available.

## Examples

    iex> paginate_results([1, 2, 3], 2)
    {[1, 2], true}

    iex> paginate_results([1, 2], 2)
    {[1, 2], false}

# `schedule_refresh`

Schedules a refresh timer for polling updates.

# `short_id`

Returns a short form of a UUID for display.

# `status_classes`

Returns CSS classes for a status badge.

# `status_color`

Returns the color for a status in hex format (for SVG).

# `subscribe_to_run`

Subscribes to updates for a specific run.

# `subscribe_to_updates`

Subscribes to PgFlow PubSub topics for real-time updates.

# `unsubscribe_from_run`

Unsubscribes from a specific run's updates.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
