Retained tab state using location hash (#161)

This commit is contained in:
Kieran
2024-04-03 11:05:49 -07:00
committed by GitHub
parent 79c61bca4f
commit 3b1c1692fb
4 changed files with 27 additions and 3 deletions
@@ -14,7 +14,8 @@ defmodule PinchflatWeb.CustomComponents.TabComponents do
def tabbed_layout(assigns) do
~H"""
<div
x-data="{ openTab: 0, activeClasses: 'text-meta-5 border-meta-5', inactiveClasses: 'border-transparent' }"
x-data="{ openTab: getTabIndex(0), activeClasses: 'text-meta-5 border-meta-5', inactiveClasses: 'border-transparent' }"
@hashchange.window="openTab = getTabIndex(openTab)"
class="w-full"
>
<header class="flex flex-col md:flex-row md:justify-between border-b border-strokedark">
@@ -22,7 +23,7 @@ defmodule PinchflatWeb.CustomComponents.TabComponents do
<a
:for={{tab, idx} <- Enum.with_index(@tab)}
href="#"
@click.prevent={"openTab = #{idx}"}
@click.prevent={"openTab = setTabIndex(#{idx})"}
x-bind:class={"openTab === #{idx} ? activeClasses : inactiveClasses"}
class="border-b-2 py-4 w-full sm:w-fit text-sm font-medium hover:text-meta-5 md:text-base"
>
@@ -52,7 +52,9 @@
<:tab title="Sources">
<.table rows={@media_profile.sources} table_class="text-black dark:text-white">
<:col :let={source} label="Name">
<%= source.custom_name || source.collection_name %>
<.subtle_link href={~p"/sources/#{source.id}"}>
<%= source.custom_name || source.collection_name %>
</.subtle_link>
</:col>
<:col :let={source} label="Type"><%= source.collection_type %></:col>
<:col :let={source} label="Should Download?">