Skip to content

Commit

Permalink
fixing workingaround to suport optional links in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
martinheidegger committed Oct 18, 2024
1 parent de297a9 commit e39bd98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 11 additions & 0 deletions 2024/src/components/OptionalLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { forwardRef } from 'react'
import { Link, GatsbyLinkProps } from "gatsby";

export type OptionalLinkProps<TState> = Omit<GatsbyLinkProps<TState>, 'to' | 'align'>
& Partial<Pick<GatsbyLinkProps<TState>, 'to'>>
export const OptionalLink = forwardRef<HTMLAnchorElement, OptionalLinkProps<any>>((props, ref) => {
const {to, ...rest} = props
return to
? <Link ref={ref as any} to={to} {...rest} />
:<a ref={ref as any} {...rest} />
})
5 changes: 2 additions & 3 deletions 2024/src/pages/schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useLayoutEffect } from "react"
import styled from "styled-components"
import { useTranslation } from "react-i18next"
import { useStaticQuery, graphql } from "gatsby"
import { Link as _Link } from "gatsby-link"
import flatten from "lodash/flatten"

import { Layout } from "../components/Layout"
Expand All @@ -20,6 +19,7 @@ import { Dates, times, Rooms, rooms } from "../util/misc"
import { useEnOrJa } from "../util/languages"
import { rgba } from "../util/rgba"
import { Tags } from "../components/Tags"
import { OptionalLink } from "../components/OptionalLink"

const dummyTrack = String.fromCharCode(
rooms[rooms.length - 1].charCodeAt(0) + 1,
Expand Down Expand Up @@ -52,7 +52,7 @@ const Grid = styled.div<{
flex-direction: column;
}
`
const Area = styled(_Link)<{
const Area = styled(OptionalLink)<{
track: Rooms
["starts-at"]: string
["ends-at"]: string
Expand Down Expand Up @@ -296,7 +296,6 @@ export default function SchedulePage() {

return (
<Area
// @ts-expect-error
to={hasDescription ? `/talk/${s.uuid}` : null}
onClick={e => {
if (!hasDescription) {
Expand Down

0 comments on commit e39bd98

Please sign in to comment.