Skip to content

Commit

Permalink
refactor: separate Gallery tab into component
Browse files Browse the repository at this point in the history
This is needed so that we can use hooks in each tab,
namely `useRovingTabindex`.
  • Loading branch information
WofWca committed Dec 5, 2024
1 parent e07a08b commit 54f764e
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions packages/frontend/src/components/Gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import FullscreenMedia, {
NeighboringMediaMode,
} from './dialogs/FullscreenMedia'
import { DialogContext } from '../contexts/DialogContext'
import type { getMessageFunction } from '@deltachat-desktop/shared/localize'

const log = getLogger('renderer/Gallery')

Expand Down Expand Up @@ -237,18 +238,12 @@ export default class Gallery extends Component<
const tabId = realId as MediaTabKey
return (
<li key={tabId}>
<button
className={`tab-item ${
currentTab === tabId ? 'selected' : ''
}`}
role='tab'
aria-selected={currentTab === tabId}
id={`gallery-tab-${tabId}`}
aria-controls={`gallery-tabpanel-${tabId}`}
<GalleryTab
tabId={tabId}
onClick={() => this.onSelect(tabId)}
>
{tx(tabId)}
</button>
tx={tx}
isSelected={currentTab === tabId}
/>
</li>
)
})}
Expand Down Expand Up @@ -407,6 +402,27 @@ export default class Gallery extends Component<
}
}

function GalleryTab(props: {
tabId: MediaTabKey
isSelected: boolean
onClick: () => void
tx: getMessageFunction
}) {
const { tabId, isSelected, tx, onClick } = props
return (
<button
className={`tab-item ${isSelected ? 'selected' : ''}`}
role='tab'
aria-selected={isSelected}
id={`gallery-tab-${tabId}`}
aria-controls={`gallery-tabpanel-${tabId}`}
onClick={onClick}
>
{tx(tabId)}
</button>
)
}

Gallery.contextType = DialogContext

function FileTable({
Expand Down

0 comments on commit 54f764e

Please sign in to comment.