Skip to content

Commit

Permalink
show first tab's content when any tab is deleted
Browse files Browse the repository at this point in the history
Signed-off-by: Natasha Tikhonova <[email protected]>
  • Loading branch information
natashatikhonova committed Aug 21, 2023
1 parent 70a8468 commit 046fb2e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions next-tavla/src/Admin/scenarios/TilesOverview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TTile } from 'types/tile'
import React from 'react'
import React, { useEffect, useState } from 'react'
import { TileSettings } from 'Admin/scenarios/TileSettings'
import { Tab, TabList, TabPanel, TabPanels, Tabs } from '@entur/tab'
import Image from 'next/image'
Expand All @@ -8,6 +8,12 @@ import classes from './styles.module.css'
import { Heading2, LeadParagraph } from '@entur/typography'

function TilesOverview({ tiles }: { tiles: TTile[] }) {
const [activeTab, setActiveTab] = useState(0)

useEffect(() => {
setActiveTab(0)
}, [tiles.length])

if (tiles.length === 0)
return (
<div className={classes.info}>
Expand All @@ -23,7 +29,11 @@ function TilesOverview({ tiles }: { tiles: TTile[] }) {
)

return (
<Tabs className={classes.tabs}>
<Tabs
className={classes.tabs}
index={activeTab}
onChange={(newIndex) => setActiveTab(newIndex)}
>
<TabList data-cy="tiles">
{tiles.map((tile) => (
<Tab key={tile.uuid}>{tile.name ?? tile.placeId}</Tab>
Expand Down

0 comments on commit 046fb2e

Please sign in to comment.