message: Refactor PrimarySearchResult to work on non client-routing pages
diff: -import React, { PureComponent } from 'react'
  -import styled from 'styled-components'
  +import React, { useCallback } from 'react'
  +import styled, { css } from 'styled-components'
  import { Link } from 'react-router-dom'
  import Text from 'v2/components/UI/Text'
  +import A from 'v2/components/UI/Link'
  import GroupBadge from 'v2/components/UI/GroupBadge'
  import { ICON_OFFSET } from 'v2/components/UI/SearchInput'
  import BorderedLock from 'v2/components/UI/BorderedLock'
  @@ -12,6 +13,7 @@ import { mixin as boxMixin } from 'v2/components/UI/Box'
  import { PrimarySearchResult as PrimarySearchResultType } from '__generated__/PrimarySearchResult'
  import { getBreadcrumbPath } from 'v2/util/getBreadcrumbPath'
  +import useIsErrorPage from 'v2/hooks/useIsErrorPage'
  const Label = styled(Text)`
  font-weight: bold;
  @@ -20,7 +22,7 @@ const Label = styled(Text)`
  ${overflowEllipsis}
  `
  -const Container = styled(Link)`
  +const containerMixin = css`
  ${boxMixin}
  display: flex;
  text-decoration: none;
  @@ -39,6 +41,14 @@ const Container = styled(Link)`
  `}
  `
  +const ClientLink = styled(Link)`
  + ${containerMixin}
  +`
  +
  +const StandardLink = styled(A)`
  + ${containerMixin}
  +`
  +
  const PathContainer = styled.div`
  display: flex;
  flex-direction: row;
  @@ -58,7 +68,7 @@ const PathContainer = styled.div`
  }
  `
  -Container.defaultProps = {
  +const defaultProps = {
  pl: ICON_OFFSET,
  pr: 6,
  py: 6,
  @@ -67,37 +77,54 @@ Container.defaultProps = {
  borderColor: 'gray.semiLight',
  }
  +ClientLink.defaultProps = defaultProps
  +StandardLink.defaultProps = defaultProps
  +
  interface PrimarySearchResultProps {
  - result: PrimarySearchResultType
  - selected: boolean
  + result?: PrimarySearchResultType
  + selected?: boolean
  to?: string
  bg?: any
  onClick?: any
  }
  -export default class PrimarySearchResult extends PureComponent<
  - PrimarySearchResultProps
  -> {
  - static defaultProps = {
  - result: null,
  - children: null,
  - selected: false,
  - }
  +export const PrimarySearchResult: React.FC<PrimarySearchResultProps> = ({
  + result,
  + children,
  + selected = false,
  + ...rest
  +}) => {
  + const isErrorPage = useIsErrorPage()
  - preventBlur = e => {
  - e.preventDefault()
  + const Container = isErrorPage ? StandardLink : ClientLink
  +
  + const onClick = useCallback(
  + e => {
  + if (isErrorPage) {
  + return (window.location.href = result.href)
  }
  - render() {
  - const { result, children, ...rest } = this.props
  + e.preventDefault()
  + },
  + [isErrorPage, result]
  + )
  if (result) {
  - const toParams = {
  + const toParams = isErrorPage
  + ? { href: result.href }
  + : {
  + to: {
  pathname: result.href,
  state: getBreadcrumbPath(result),
  + },
  }
  return (
  - <Container to={toParams} onMouseDown={this.preventBlur} {...rest}>
  + <Container
  + onMouseDown={onClick}
  + selected={selected}
  + {...toParams}
  + {...rest}
  + >
  <PathContainer>
  {result.__typename === 'Channel' && result.owner && (
  <Label flex="1">
  @@ -138,9 +165,10 @@ export default class PrimarySearchResult extends PureComponent<
  }
  return (
  - <Container onMouseDown={this.preventBlur} {...rest}>
  + <Container onMouseDown={onClick} {...rest}>
  {children}
  </Container>
  )
  }
  -}
  +
  +export default PrimarySearchResult
  