2022-06-07 13:30:48 +09:00
|
|
|
import { useRouter } from 'next/router';
|
2020-08-31 08:41:53 +09:00
|
|
|
import Tooltip from 'rc-tooltip';
|
|
|
|
import React from 'react';
|
|
|
|
import { Helmet } from 'react-helmet';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { IoIosFlash, IoIosRocket } from 'react-icons/io';
|
2022-06-07 13:30:48 +09:00
|
|
|
import styled from '@emotion/styled';
|
|
|
|
import Cards from '../../components/cards';
|
2020-07-30 13:47:28 +09:00
|
|
|
import {
|
|
|
|
AvailableIcon,
|
|
|
|
COLORS as ResultColor,
|
|
|
|
ResultIcon,
|
|
|
|
ResultItem,
|
|
|
|
ResultName,
|
2022-06-07 13:30:48 +09:00
|
|
|
} from '../../components/cards/core';
|
|
|
|
import Form from '../../components/Form';
|
|
|
|
import { useStoreState } from '../../store';
|
|
|
|
import { Content, Header } from '../../src/theme';
|
|
|
|
import { mobile } from '../../src/util/css';
|
|
|
|
import { sanitize } from '../../src/util/text';
|
2020-07-30 13:47:28 +09:00
|
|
|
|
|
|
|
export default function Search() {
|
2022-06-07 13:30:48 +09:00
|
|
|
const router = useRouter();
|
|
|
|
const { query } = router.query;
|
|
|
|
const currentQuery = sanitize((query as string) ?? '');
|
2020-08-31 08:41:53 +09:00
|
|
|
const { t } = useTranslation();
|
2020-07-30 13:47:28 +09:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Helmet>
|
|
|
|
<title>Search for "{currentQuery}" — namae</title>
|
|
|
|
</Helmet>
|
|
|
|
<Header>
|
|
|
|
<Form initialValue={currentQuery} />
|
|
|
|
</Header>
|
|
|
|
<Content>
|
|
|
|
<Legend>
|
|
|
|
<Stat />
|
|
|
|
<ResultItem color={ResultColor.available}>
|
|
|
|
<ResultIcon>
|
|
|
|
<IoIosRocket />
|
|
|
|
</ResultIcon>
|
|
|
|
<ResultName>{t('available')}</ResultName>
|
|
|
|
<AvailableIcon>
|
|
|
|
<IoIosFlash />
|
|
|
|
</AvailableIcon>
|
|
|
|
</ResultItem>
|
|
|
|
<ResultItem color={ResultColor.unavailable}>
|
|
|
|
<ResultIcon>
|
|
|
|
<IoIosRocket />
|
|
|
|
</ResultIcon>
|
|
|
|
<ResultName>{t('unavailable')}</ResultName>
|
|
|
|
</ResultItem>
|
|
|
|
</Legend>
|
|
|
|
<Cards query={currentQuery} />
|
|
|
|
</Content>
|
|
|
|
</>
|
2020-08-31 08:41:53 +09:00
|
|
|
);
|
2020-07-30 13:47:28 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function Stat() {
|
2020-08-31 08:41:53 +09:00
|
|
|
const totalCount = useStoreState((state) => state.stats.totalCount);
|
|
|
|
const availableCount = useStoreState((state) => state.stats.availableCount);
|
|
|
|
const { t } = useTranslation();
|
2020-07-30 13:47:28 +09:00
|
|
|
|
2020-08-31 08:41:53 +09:00
|
|
|
const uniqueness = availableCount !== 0 ? availableCount / totalCount : 0.0;
|
2020-07-30 13:47:28 +09:00
|
|
|
const uniquenessText = ((n) => {
|
|
|
|
if (n > 0.7 && n <= 1.0) {
|
2020-08-31 08:41:53 +09:00
|
|
|
return t('uniqueness.high');
|
2020-07-30 13:47:28 +09:00
|
|
|
} else if (n > 0.4 && n <= 0.7) {
|
2020-08-31 08:41:53 +09:00
|
|
|
return t('uniqueness.moderate');
|
2020-07-30 13:47:28 +09:00
|
|
|
} else {
|
2020-08-31 08:41:53 +09:00
|
|
|
return t('uniqueness.low');
|
2020-07-30 13:47:28 +09:00
|
|
|
}
|
2020-08-31 08:41:53 +09:00
|
|
|
})(uniqueness);
|
2020-07-30 13:47:28 +09:00
|
|
|
|
|
|
|
return (
|
|
|
|
<UniquenessIndicator>
|
|
|
|
<Tooltip
|
|
|
|
overlay={t('uniqueness.description')}
|
|
|
|
placement="top"
|
|
|
|
trigger={['hover']}
|
|
|
|
>
|
|
|
|
<span>
|
|
|
|
{uniquenessText} ({(uniqueness * 100).toFixed(1)} UNIQ)
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
|
|
|
</UniquenessIndicator>
|
2020-08-31 08:41:53 +09:00
|
|
|
);
|
2020-07-30 13:47:28 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
export const Legend = styled.div`
|
|
|
|
margin-top: -100px;
|
|
|
|
padding: 100px 0 30px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: center;
|
|
|
|
user-select: none;
|
|
|
|
cursor: default;
|
|
|
|
background-color: #f6f6fa;
|
|
|
|
|
|
|
|
${mobile} {
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
margin-top: -80px;
|
|
|
|
padding: 70px 0 30px;
|
|
|
|
background-color: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
> * {
|
|
|
|
margin: 0 10px 0;
|
|
|
|
}
|
2020-08-31 08:41:53 +09:00
|
|
|
`;
|
2020-07-30 13:47:28 +09:00
|
|
|
|
|
|
|
export const UniquenessIndicator = styled.div`
|
|
|
|
color: #7b7b7b;
|
2020-08-31 08:41:53 +09:00
|
|
|
`;
|