mirror of
https://github.com/uetchy/namae.git
synced 2025-12-01 02:47:43 +09:00
fix: support new vercel style
This commit is contained in:
17
src/App.test.tsx
Normal file
17
src/App.test.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import React, {Suspense} from 'react';
|
||||
import {render} from '@testing-library/react';
|
||||
import {BrowserRouter as Router} from 'react-router-dom';
|
||||
import App from './App';
|
||||
import 'mutationobserver-shim';
|
||||
|
||||
it('renders welcome message', async () => {
|
||||
const {findByText} = render(
|
||||
<Suspense fallback={<div>loading</div>}>
|
||||
<Router>
|
||||
<App />
|
||||
</Router>
|
||||
</Suspense>,
|
||||
);
|
||||
const text = await findByText('Grab a slick name for your new app');
|
||||
expect(text).toBeTruthy();
|
||||
});
|
||||
199
src/App.tsx
Normal file
199
src/App.tsx
Normal file
@@ -0,0 +1,199 @@
|
||||
import React from 'react';
|
||||
import styled, {createGlobalStyle} from 'styled-components';
|
||||
import {Helmet} from 'react-helmet';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {Switch, Route, useParams, Redirect} from 'react-router-dom';
|
||||
import {IoIosRocket, IoIosFlash} from 'react-icons/io';
|
||||
|
||||
import Welcome from './components/Welcome';
|
||||
import Form from './components/Form';
|
||||
import Cards from './components/cards';
|
||||
import Footer from './components/Footer';
|
||||
import {
|
||||
ResultItem,
|
||||
ResultIcon,
|
||||
ResultName,
|
||||
COLORS as ResultColor,
|
||||
AvailableIcon,
|
||||
} from './components/cards/core';
|
||||
import {mobile} from './util/css';
|
||||
import {isStandalone} from './util/pwa';
|
||||
import {sanitize} from './util/text';
|
||||
import {useStoreState} from './store';
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<>
|
||||
<GlobalStyle />
|
||||
<Helmet>
|
||||
<link
|
||||
rel="search"
|
||||
type="application/opensearchdescription+xml"
|
||||
title="namae"
|
||||
href="/opensearch.xml"
|
||||
/>
|
||||
</Helmet>
|
||||
<Switch>
|
||||
<Route exact path="/">
|
||||
<Home />
|
||||
</Route>
|
||||
<Route path="/s/:query">
|
||||
<Search />
|
||||
</Route>
|
||||
<Route path="*">
|
||||
<Redirect to="/" />
|
||||
</Route>
|
||||
</Switch>
|
||||
{!isStandalone() && <Footer />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Home() {
|
||||
const {t} = useTranslation();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Helmet>
|
||||
<title>namae — {t('title')}</title>
|
||||
</Helmet>
|
||||
<Header>
|
||||
<Form />
|
||||
</Header>
|
||||
<Content>
|
||||
<Welcome />
|
||||
</Content>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Search() {
|
||||
const {query} = useParams<{query: string}>();
|
||||
const currentQuery = sanitize(query);
|
||||
const {t} = useTranslation();
|
||||
|
||||
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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Stat() {
|
||||
const totalCount = useStoreState((state) => state.stats.totalCount);
|
||||
const availableCount = useStoreState((state) => state.stats.availableCount);
|
||||
const {t} = useTranslation();
|
||||
|
||||
const uniqueness = availableCount / totalCount;
|
||||
const uniquenessText = ((n) => {
|
||||
if (n > 0.7 && n <= 1.0) {
|
||||
return t('uniqueness.high');
|
||||
} else if (n > 0.4 && n <= 0.7) {
|
||||
return t('uniqueness.moderate');
|
||||
} else {
|
||||
return t('uniqueness.low');
|
||||
}
|
||||
})(uniqueness);
|
||||
|
||||
return (
|
||||
<UniquenessIndicator>
|
||||
{uniquenessText} ({uniqueness.toFixed(2)})
|
||||
</UniquenessIndicator>
|
||||
);
|
||||
}
|
||||
|
||||
const GlobalStyle = createGlobalStyle`
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
line-height: 1.625em;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
background: #ffffff;
|
||||
|
||||
${mobile} {
|
||||
background: #f5f5f5;
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const Content = styled.div`
|
||||
padding-top: 100px;
|
||||
|
||||
${mobile} {
|
||||
padding-top: 60px;
|
||||
}
|
||||
`;
|
||||
|
||||
const Header = styled.header`
|
||||
padding: 0 40px;
|
||||
background-image: linear-gradient(180deg, #bda2ff 0%, #1b24cc 99%);
|
||||
|
||||
${mobile} {
|
||||
padding: 0 20px;
|
||||
}
|
||||
`;
|
||||
|
||||
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;
|
||||
}
|
||||
`;
|
||||
|
||||
const UniquenessIndicator = styled.div`
|
||||
color: #7b7b7b;
|
||||
`;
|
||||
121
src/components/Footer.tsx
Normal file
121
src/components/Footer.tsx
Normal file
@@ -0,0 +1,121 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {FaTwitter, FaGithub, FaProductHunt} from 'react-icons/fa';
|
||||
import {OutboundLink} from 'react-ga';
|
||||
|
||||
const Footer: React.FC = () => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<LangBox>
|
||||
<a href="/?lng=en">
|
||||
<span role="img" aria-label="English">
|
||||
🇬🇧
|
||||
</span>
|
||||
</a>
|
||||
<a href="/?lng=ja">
|
||||
<span role="img" aria-label="Japanese">
|
||||
🇯🇵
|
||||
</span>
|
||||
</a>
|
||||
</LangBox>
|
||||
|
||||
<Box>
|
||||
<p>
|
||||
Made with{' '}
|
||||
<span role="img" aria-label="coffee">
|
||||
☕️
|
||||
</span>{' '}
|
||||
by{' '}
|
||||
<OutboundLink
|
||||
to="https://twitter.com/uetschy"
|
||||
eventLabel="Author Page"
|
||||
aria-label="Author page"
|
||||
target="_blank"
|
||||
>
|
||||
<Bold>Yasuaki Uechi</Bold>
|
||||
</OutboundLink>
|
||||
</p>
|
||||
</Box>
|
||||
|
||||
<ShareBox>
|
||||
<Links>
|
||||
<OutboundLink
|
||||
to={`https://twitter.com/intent/tweet?text=${encodeURIComponent(
|
||||
`namae — ${t('title')}`,
|
||||
)}&url=${encodeURIComponent('https://namae.dev')}`}
|
||||
eventLabel="Tweet"
|
||||
aria-label="Tweet this page"
|
||||
target="_blank"
|
||||
>
|
||||
<FaTwitter />
|
||||
</OutboundLink>
|
||||
<OutboundLink
|
||||
to="https://www.producthunt.com/posts/namae"
|
||||
eventLabel="ProductHunt"
|
||||
aria-label="Go to ProductHunt page"
|
||||
target="_blank"
|
||||
>
|
||||
<FaProductHunt />
|
||||
</OutboundLink>
|
||||
<OutboundLink
|
||||
to="https://github.com/uetchy/namae"
|
||||
eventLabel="GitHub Repo"
|
||||
aria-label="Go to GitHub repository"
|
||||
target="_blank"
|
||||
>
|
||||
<FaGithub />
|
||||
</OutboundLink>
|
||||
</Links>
|
||||
</ShareBox>
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
export default Footer;
|
||||
|
||||
const Container = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin: 40px 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
|
||||
Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
||||
|
||||
a {
|
||||
color: black;
|
||||
text-decoration: none;
|
||||
}
|
||||
`;
|
||||
|
||||
const Box = styled.footer`
|
||||
margin-bottom: 10px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
line-height: 1em;
|
||||
font-size: 0.8rem;
|
||||
`;
|
||||
|
||||
const LangBox = styled(Box)`
|
||||
font-size: 2rem;
|
||||
margin-bottom: 20px;
|
||||
`;
|
||||
|
||||
const ShareBox = styled(Box)`
|
||||
font-size: 1.5rem;
|
||||
`;
|
||||
|
||||
const Links = styled.div`
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
a {
|
||||
margin: 0 3px;
|
||||
}
|
||||
`;
|
||||
|
||||
const Bold = styled.span`
|
||||
font-weight: bold;
|
||||
`;
|
||||
144
src/components/Form.tsx
Normal file
144
src/components/Form.tsx
Normal file
@@ -0,0 +1,144 @@
|
||||
import React, {useState, useRef, useEffect} from 'react';
|
||||
import styled from 'styled-components';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {Link, useHistory} from 'react-router-dom';
|
||||
import {sanitize} from '../util/text';
|
||||
import {sendQueryEvent} from '../util/analytics';
|
||||
import {mobile} from '../util/css';
|
||||
import Suggestion from './Suggestion';
|
||||
import {useDeferredState} from '../util/hooks';
|
||||
|
||||
const Form: React.FC<{
|
||||
initialValue?: string;
|
||||
}> = ({initialValue = ''}) => {
|
||||
const history = useHistory();
|
||||
const [inputValue, setInputValue] = useState(initialValue);
|
||||
const [suggestionQuery, setSuggestionQuery] = useDeferredState(800, '');
|
||||
const [suggested, setSuggested] = useState(false);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const {t} = useTranslation();
|
||||
|
||||
function search(query: string) {
|
||||
sendQueryEvent(sanitize(query));
|
||||
history.push(`/s/${query}`);
|
||||
}
|
||||
|
||||
// set input value
|
||||
function onInputChange(e: React.FormEvent<HTMLInputElement>): void {
|
||||
setInputValue(e.currentTarget.value);
|
||||
}
|
||||
|
||||
// clear input form and focus on it
|
||||
function onLogoClick(): void {
|
||||
setInputValue('');
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
inputRef.current!.focus();
|
||||
}
|
||||
|
||||
// invoke when user clicked one of the suggested items
|
||||
function onSuggestionCompleted(name: string): void {
|
||||
setInputValue(name);
|
||||
search(name);
|
||||
setSuggested(true);
|
||||
}
|
||||
|
||||
function onSubmitQuery(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!inputValue || inputValue === '') {
|
||||
return;
|
||||
}
|
||||
search(inputValue);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const modifiedValue = sanitize(inputValue);
|
||||
setSuggestionQuery(modifiedValue);
|
||||
}, [inputValue, setSuggestionQuery]);
|
||||
|
||||
const queryGiven = suggestionQuery && suggestionQuery !== '';
|
||||
|
||||
return (
|
||||
<InputContainer>
|
||||
<Logo to="/" onClick={onLogoClick}>
|
||||
<LogoImage src="/logo.svg" />
|
||||
</Logo>
|
||||
<form onSubmit={onSubmitQuery} action="/s" role="search">
|
||||
<InputView
|
||||
onChange={onInputChange}
|
||||
value={inputValue}
|
||||
ref={inputRef}
|
||||
placeholder={t('placeholder')}
|
||||
aria-label="Search"
|
||||
/>
|
||||
</form>
|
||||
{queryGiven && !suggested ? (
|
||||
<Suggestion onSubmit={onSuggestionCompleted} query={suggestionQuery} />
|
||||
) : null}
|
||||
</InputContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default Form;
|
||||
const InputContainer = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 30px;
|
||||
transform: translateY(40px);
|
||||
border-radius: 50px;
|
||||
box-shadow: 0 10px 50px 0 #858efb;
|
||||
background: #ffffff;
|
||||
|
||||
${mobile} {
|
||||
padding: 20px;
|
||||
transform: translateY(20px);
|
||||
border-radius: 30px;
|
||||
}
|
||||
`;
|
||||
|
||||
const Logo = styled(Link)`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
margin-top: 5px;
|
||||
cursor: pointer;
|
||||
|
||||
${mobile} {
|
||||
font-size: 15px;
|
||||
}
|
||||
`;
|
||||
|
||||
const LogoImage = styled.img`
|
||||
width: 140px;
|
||||
|
||||
${mobile} {
|
||||
width: 90px;
|
||||
}
|
||||
`;
|
||||
|
||||
const InputView = styled.input.attrs({
|
||||
type: 'search',
|
||||
enterkeyhint: 'search',
|
||||
autocomplete: 'off',
|
||||
autocorrect: 'off',
|
||||
autocapitalize: 'off',
|
||||
spellcheck: 'false',
|
||||
})`
|
||||
width: 100%;
|
||||
border: none;
|
||||
outline: none;
|
||||
text-align: center;
|
||||
font-family: 'Montserrat', monospace;
|
||||
font-weight: 600;
|
||||
font-size: 6rem;
|
||||
appearance: none;
|
||||
|
||||
${mobile} {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
::placeholder {
|
||||
color: #c8cdda;
|
||||
}
|
||||
`;
|
||||
99
src/components/Icons.tsx
Normal file
99
src/components/Icons.tsx
Normal file
@@ -0,0 +1,99 @@
|
||||
import React from 'react';
|
||||
|
||||
export const SpectrumIcon: React.FC = () => (
|
||||
<svg
|
||||
width="1em"
|
||||
height="1em"
|
||||
viewBox="0 0 32 32"
|
||||
fill="currentColor"
|
||||
stroke="currentColor"
|
||||
strokeWidth="0"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path d="M6 14.5C6 15.3284 6.67157 16 7.5 16H9C12.866 16 16 19.134 16 23V24.5C16 25.3284 16.6716 26 17.5 26H24.5C25.3284 26 26 25.3284 26 24.5V23C26 13.6111 18.3889 6 9 6H7.5C6.67157 6 6 6.67157 6 7.5V14.5Z" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const NowIcon: React.FC = () => (
|
||||
<svg
|
||||
width="1em"
|
||||
height="1em"
|
||||
fill="currentColor"
|
||||
stroke="currentColor"
|
||||
strokeWidth="0"
|
||||
viewBox="0 0 114 100"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<g id="Black-Triangle" transform="translate(-293.000000, -150.000000)">
|
||||
<polygon id="Logotype---Black" points="350 150 407 250 293 250"></polygon>
|
||||
</g>
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const NetlifyIcon: React.FC = () => (
|
||||
<svg
|
||||
width="1em"
|
||||
height="1em"
|
||||
fill="currentColor"
|
||||
stroke="currentColor"
|
||||
strokeWidth="0"
|
||||
aria-hidden="true"
|
||||
focusable="false"
|
||||
// style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
viewBox="0 0 256 256"
|
||||
>
|
||||
<path d="M185.532 88.839l-.094-.04a.396.396 0 0 1-.154-.087a.734.734 0 0 1-.187-.621l5.167-31.553l24.229 24.209l-25.198 10.709a.555.555 0 0 1-.22.04h-.101a.694.694 0 0 1-.134-.114a11.468 11.468 0 0 0-3.308-2.543zm35.144-1.923l25.906 25.878c5.38 5.381 8.075 8.065 9.057 11.177c.147.46.267.921.361 1.395l-61.913-26.192a4.868 4.868 0 0 0-.1-.04c-.248-.1-.535-.214-.535-.467c0-.254.294-.374.541-.474l.08-.034l26.603-11.243zm34.268 46.756c-1.337 2.51-3.944 5.114-8.355 9.527l-29.209 29.17l-37.777-7.858l-.2-.04c-.335-.054-.689-.114-.689-.414a11.387 11.387 0 0 0-4.378-7.965c-.154-.154-.113-.394-.067-.615c0-.033 0-.066.014-.093l7.105-43.571l.026-.147c.04-.334.1-.721.401-.721a11.566 11.566 0 0 0 7.754-4.44c.06-.067.1-.14.18-.18c.214-.1.468 0 .689.093l64.5 27.254h.006zm-44.28 45.407l-48.031 47.978l8.22-50.475l.014-.067a.905.905 0 0 1 .04-.193c.067-.16.24-.227.408-.294l.08-.034c1.8-.767 3.392-1.95 4.646-3.451c.16-.187.354-.368.601-.401c.064-.01.13-.01.194 0l33.82 6.944l.007-.007zm-58.198 58.133l-5.414 5.408l-59.854-86.408a2.831 2.831 0 0 0-.067-.094c-.093-.127-.194-.253-.173-.4c.006-.107.073-.2.147-.28l.066-.087c.18-.268.335-.535.502-.822l.133-.233l.02-.02c.094-.16.18-.314.341-.401c.14-.067.335-.04.488-.007l66.311 13.66c.186.03.36.105.508.22c.087.088.107.181.127.288a11.735 11.735 0 0 0 6.871 7.845c.187.093.107.3.02.52a1.588 1.588 0 0 0-.1.301c-.835 5.074-8 48.726-9.926 60.51zm-11.309 11.29c-3.99 3.946-6.343 6.035-9.003 6.877a13.382 13.382 0 0 1-8.06 0c-3.115-.989-5.809-3.672-11.19-9.054l-60.108-60.042l15.7-24.323a1 1 0 0 1 .268-.314c.167-.12.408-.066.608 0a16.285 16.285 0 0 0 10.948-.554c.18-.066.361-.113.502.014c.07.064.133.135.187.213l60.148 87.19v-.007zm-94.156-68.008l-13.789-13.773l27.23-11.604a.562.562 0 0 1 .221-.047c.227 0 .361.227.481.434c.274.42.564.83.87 1.229l.086.106c.08.114.027.227-.053.334l-15.04 23.321h-.006zM27.11 160.625L9.665 143.199c-2.968-2.964-5.12-5.114-6.617-6.963l53.043 10.99l.2.033c.328.053.69.113.69.42c0 .334-.395.488-.73.614l-.153.067l-28.988 12.265zM0 127.275a13.34 13.34 0 0 1 .602-3.304c.989-3.112 3.676-5.796 9.063-11.177l22.324-22.3a14524.43 14524.43 0 0 0 30.92 44.647c.18.24.38.507.174.707c-.976 1.075-1.952 2.25-2.64 3.526c-.075.163-.19.306-.335.413c-.087.054-.18.034-.28.014h-.014L0 127.269v.007zm37.965-42.75l30.017-29.984c2.82 1.235 13.087 5.568 22.27 9.44c6.952 2.939 13.288 5.61 15.28 6.477c.2.08.381.16.468.36c.053.12.027.274 0 .401a13.363 13.363 0 0 0 3.496 12.205c.2.2 0 .487-.174.734l-.094.14l-30.478 47.157c-.08.134-.154.247-.288.334c-.16.1-.387.053-.575.007a15.215 15.215 0 0 0-3.629-.494c-1.096 0-2.286.2-3.489.42h-.007c-.133.02-.254.047-.36-.033a1.403 1.403 0 0 1-.301-.34L37.965 84.525zm36.08-36.04l38.86-38.817c5.38-5.375 8.074-8.065 11.188-9.047a13.382 13.382 0 0 1 8.061 0c3.115.982 5.808 3.672 11.189 9.047l8.422 8.413l-27.638 42.756a1.035 1.035 0 0 1-.274.32c-.167.114-.401.067-.602 0a14.028 14.028 0 0 0-12.833 2.471c-.18.187-.448.08-.675-.02c-3.61-1.569-31.682-13.42-35.699-15.122zm83.588-24.542l25.52 25.49l-6.15 38.044v.1a.9.9 0 0 1-.053.254c-.067.133-.201.16-.335.2a12.237 12.237 0 0 0-3.662 1.823a1.029 1.029 0 0 0-.134.113c-.074.08-.147.154-.267.167a.763.763 0 0 1-.288-.047l-38.887-16.504l-.073-.034c-.248-.1-.542-.22-.542-.474a14.664 14.664 0 0 0-2.072-6.109c-.187-.307-.394-.627-.234-.941l27.177-42.082zM131.352 81.4l36.454 15.423c.2.093.421.18.508.387a.707.707 0 0 1 0 .38c-.107.535-.2 1.142-.2 1.757v1.021c0 .254-.261.36-.502.46l-.073.027c-5.775 2.464-81.076 34.538-81.19 34.538c-.113 0-.234 0-.347-.113c-.2-.2 0-.48.18-.735l.094-.133l29.957-46.335l.053-.08c.174-.281.375-.595.696-.595l.3.047c.682.093 1.284.18 1.892.18c4.545 0 8.756-2.21 11.296-5.989c.06-.1.137-.19.227-.267c.18-.133.448-.066.655.027zm-41.748 61.324l82.079-34.965s.12 0 .234.114c.447.447.828.747 1.196 1.028l.18.113c.168.094.335.2.348.374c0 .067 0 .107-.013.167l-7.032 43.144l-.027.174c-.046.333-.093.714-.407.714a11.558 11.558 0 0 0-9.177 5.655l-.034.053c-.093.154-.18.3-.334.38c-.14.068-.32.041-.468.008l-65.455-13.487c-.067-.013-1.016-3.465-1.09-3.472z" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const OcamlIcon: React.FC = () => (
|
||||
<svg
|
||||
x="0px"
|
||||
y="0px"
|
||||
width="1em"
|
||||
height="1em"
|
||||
fill="currentColor"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 165.543 144.277"
|
||||
>
|
||||
<g>
|
||||
<path
|
||||
d="M82.223,134.04c-0.459-0.978-1.853-3.524-2.553-4.34c-1.52-1.779-1.875-1.913-2.322-4.159
|
||||
c-0.777-3.911-2.834-11.004-5.258-15.899c-1.252-2.526-3.334-4.648-5.24-6.48c-1.664-1.607-5.414-4.311-6.068-4.177
|
||||
c-6.125,1.223-8.025,7.23-10.906,11.989c-1.594,2.632-3.283,4.871-4.539,7.671c-1.16,2.575-1.057,5.426-3.043,7.637
|
||||
c-2.037,2.27-3.361,4.684-4.359,7.617c-0.189,0.558-0.727,6.417-1.311,7.798l9.103-0.641c8.483,0.578,6.033,3.829,19.273,3.121
|
||||
l20.906-0.647c-0.648-1.916-1.541-4.135-1.885-4.856C83.438,137.46,82.705,135.084,82.223,134.04z"
|
||||
/>
|
||||
<path
|
||||
d="M108.725,90.75c-1.607,1.16-4.748,3.95-11.58,5.005c-3.066,0.474-5.934,0.513-9.082,0.356
|
||||
c-1.541-0.074-2.994-0.153-4.539-0.173c-0.91-0.007-3.963-0.104-3.812,0.188l-0.34,0.848c0.053,0.279,0.164,0.976,0.195,1.145
|
||||
c0.125,0.685,0.16,1.23,0.186,1.86c0.047,1.295-0.107,2.645-0.041,3.952c0.137,2.711,1.143,5.182,1.27,7.917
|
||||
c0.139,3.045,1.645,6.267,3.102,8.754c0.553,0.947,1.395,1.055,1.762,2.221c0.43,1.336,0.023,2.753,0.232,4.177
|
||||
c0.82,5.521,2.41,11.292,4.896,16.275c0.018,0.042,0.037,0.087,0.059,0.125c3.07-0.516,6.146-1.62,10.135-2.21
|
||||
c7.314-1.085,17.486-0.526,24.02-1.138c16.533-1.554,25.506,6.781,40.355,3.365V20.857C165.543,9.339,156.209,0,144.688,0H20.856
|
||||
C9.339,0,0.001,9.339,0.001,20.857v45.507c2.984-1.079,7.276-7.428,8.621-8.972c2.353-2.7,2.78-6.144,3.952-8.313
|
||||
c2.669-4.94,3.128-8.337,9.195-8.337c2.828,0,3.951,0.652,5.864,3.219c1.331,1.785,3.63,5.083,4.706,7.288
|
||||
c1.242,2.544,3.266,5.986,4.156,6.681c0.659,0.516,1.313,0.903,1.923,1.132c0.984,0.369,1.798-0.308,2.456-0.832
|
||||
c0.84-0.669,1.202-2.032,1.98-3.85c1.121-2.623,2.343-5.766,3.038-6.863c1.203-1.896,1.613-4.146,2.912-5.236
|
||||
c1.916-1.607,4.416-1.72,5.104-1.856c3.849-0.76,5.599,1.855,7.495,3.546c1.241,1.108,2.937,3.34,4.141,6.331
|
||||
c0.941,2.336,2.139,4.497,2.64,5.846c0.484,1.302,1.679,3.389,2.387,5.891c0.643,2.272,2.364,4.013,3.018,5.093
|
||||
c0,0,1.001,2.804,7.088,5.367c1.32,0.556,3.988,1.46,5.58,2.039c2.645,0.961,5.207,0.836,8.469,0.445
|
||||
c2.326,0,3.586-3.368,4.643-6.065c0.625-1.594,1.224-6.162,1.632-7.459c0.395-1.262-0.529-2.238,0.258-3.344
|
||||
c0.92-1.291,1.467-1.361,1.998-3.044c1.141-3.604,7.736-3.786,11.443-3.786c3.09,0,2.697,3,7.939,1.974
|
||||
c3.002-0.589,5.895,0.387,9.082,1.231c2.684,0.712,5.207,1.523,6.719,3.293c0.978,1.146,3.406,6.888,0.932,7.133
|
||||
c0.238,0.291,0.412,0.816,0.857,1.104c-0.551,2.166-2.949,0.623-4.281,0.345c-1.795-0.372-3.062,0.056-4.818,0.833
|
||||
c-3.002,1.337-7.393,1.181-10.008,3.359c-2.219,1.846-2.215,5.967-3.25,8.276C117.871,78.832,114.998,86.227,108.725,90.75z"
|
||||
/>
|
||||
<path
|
||||
d="M39.35,101.251c-1.428-0.145-2.754-0.308-4.141-0.588c-2.59-0.522-5.42-1.031-7.971-1.642
|
||||
c-1.549-0.375-6.709-2.202-7.83-2.717c-2.629-1.212-4.375-4.505-6.43-4.166c-1.312,0.214-2.59,0.664-3.406,1.987
|
||||
c-0.666,1.079-0.892,2.934-1.353,4.178c-0.535,1.444-1.459,2.792-2.268,4.168c-1.488,2.524-4.166,4.807-5.32,7.266
|
||||
c-0.232,0.506-0.438,1.072-0.631,1.662v9.434v16.321v2.358c1.346,0.23,2.754,0.513,4.33,0.934
|
||||
c11.631,3.103,14.469,3.366,25.877,2.061l1.07-0.142c0.873-1.816,1.547-8.004,2.113-9.919c0.441-1.468,1.047-2.638,1.277-4.137
|
||||
c0.217-1.424-0.02-2.781-0.142-4.075c-0.32-3.242,2.361-4.4,3.641-7.184c1.154-2.519,1.82-5.385,2.775-7.96
|
||||
c0.916-2.471,2.346-5.963,4.785-7.207C45.43,101.538,40.631,101.379,39.35,101.251z"
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
);
|
||||
333
src/components/Suggestion.tsx
Normal file
333
src/components/Suggestion.tsx
Normal file
@@ -0,0 +1,333 @@
|
||||
import React, {useEffect, useState, useRef} from 'react';
|
||||
import styled from 'styled-components';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import fetch from 'isomorphic-unfetch';
|
||||
import {TiArrowSync} from 'react-icons/ti';
|
||||
import {motion} from 'framer-motion';
|
||||
|
||||
import {capitalize, stem, germanify, njoin, lower, upper} from '../util/text';
|
||||
import {sampleFromArray, fillArray} from '../util/array';
|
||||
import {mobile, slideUp} from '../util/css';
|
||||
import {sanitize} from '../util/text';
|
||||
import {
|
||||
sendShuffleSuggestionEvent,
|
||||
sendAcceptSuggestionEvent,
|
||||
} from '../util/analytics';
|
||||
|
||||
type Modifier = (word: string) => string;
|
||||
|
||||
const maximumCount = 3;
|
||||
const modifiers: Modifier[] = [
|
||||
(word): string => `${capitalize(germanify(word))}`,
|
||||
(word): string => `${capitalize(word)}`,
|
||||
(word): string => njoin('Air', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('All', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('Cloud', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('Co', lower(word), {elision: false}),
|
||||
(word): string => njoin('Deep', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('Easy', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('En', lower(word), {elision: false}),
|
||||
(word): string => njoin('Fast', lower(word), {elision: false}),
|
||||
(word): string => njoin('Fire', lower(word), {elision: false}),
|
||||
(word): string => njoin('Fusion', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('Git', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('Go', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('Hyper', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('In', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('Infini', lower(word)),
|
||||
(word): string => njoin('Insta', lower(word), {elision: false}),
|
||||
(word): string => njoin('i', capitalize(word)),
|
||||
(word): string => njoin('Lead', lower(word), {elision: false}),
|
||||
(word): string => njoin('Less', lower(word)),
|
||||
(word): string => njoin('lib', lower(word), {elision: false}),
|
||||
(word): string => njoin('Many', lower(word)),
|
||||
(word): string => njoin('Max', upper(word), {elision: false}),
|
||||
(word): string => njoin('Micro', lower(word), {elision: false}),
|
||||
(word): string => njoin('mini', lower(word)),
|
||||
(word): string => njoin('Mono', lower(word)),
|
||||
(word): string => njoin('Meta', lower(word)),
|
||||
(word): string => njoin('nano', lower(word), {elision: false}),
|
||||
(word): string => njoin('Native', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('Next', lower(word)),
|
||||
(word): string => njoin('No', upper(word), {elision: false}),
|
||||
(word): string => njoin('Octo', capitalize(word)),
|
||||
(word): string => njoin('Omni', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('One', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('Open', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('Pro', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('quick', lower(word), {elision: false}),
|
||||
(word): string => njoin('Semantic', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('Smart', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('Snap', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('Super', lower(word), {elision: false}),
|
||||
(word): string => njoin('Ultra', lower(word)),
|
||||
(word): string => njoin('Un', lower(word), {elision: false}),
|
||||
(word): string => njoin('Uni', lower(word)),
|
||||
(word): string => njoin('unified-', lower(word), {elision: false}),
|
||||
(word): string => njoin('Up', lower(word), {elision: false}),
|
||||
(word): string => njoin('Wunder', lower(germanify(word)), {elision: false}),
|
||||
(word): string => njoin('Zen', capitalize(word), {elision: false}),
|
||||
(word): string => njoin('Zero', capitalize(word), {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'able', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'al', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'el', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'em', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'en', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'er', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'ery', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'ia', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'ible', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'ics', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'ifier', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'ify', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'ii', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'in', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'io', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'ist', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'ity', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'ium', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'iverse', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'ory', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'um', {elision: false}),
|
||||
(word): string => njoin(capitalize(stem(word)), 'y'),
|
||||
(word): string => njoin(capitalize(word), 'AI', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'API', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'App'),
|
||||
(word): string => njoin(capitalize(word), 'base', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'book', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Bot', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'butler', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'byte', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'cast', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'CDN', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'CI', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Club', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'DB', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Express', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'en'),
|
||||
(word): string => njoin(capitalize(word), 'feed', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Finder', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'flow', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'form', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'ful'),
|
||||
(word): string => njoin(capitalize(word), 'Go', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'gram', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Hero', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Hub', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Hunt', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'IO', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'It', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Kit', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Lab', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'let'),
|
||||
(word): string => njoin(capitalize(word), 'less'),
|
||||
(word): string => njoin(capitalize(word), 'Link', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'list', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'list', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'lit', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'mind', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'ML', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'note', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Notes', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Pod', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Pro', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Scan', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'shot'),
|
||||
(word): string => njoin(capitalize(word), 'space'),
|
||||
(word): string => njoin(capitalize(word), 'Stack', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Studio', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'Sensei', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'time'),
|
||||
(word): string => njoin(capitalize(word), 'way'),
|
||||
(word): string => njoin(capitalize(word), 'x', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'check', {elision: false}),
|
||||
(word): string => njoin(capitalize(word), 'joy'),
|
||||
(word): string => njoin(lower(word), 'lint', {elision: false}),
|
||||
(word): string => njoin(lower(word), 'ly', {elision: false}),
|
||||
];
|
||||
|
||||
function modifyWord(word: string): string {
|
||||
return modifiers[Math.floor(Math.random() * modifiers.length)](word);
|
||||
}
|
||||
|
||||
async function findSynonyms(word: string): Promise<string[]> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&dt=ss&ie=UTF-8&oe=UTF-8&dj=1&q=${encodeURIComponent(
|
||||
word,
|
||||
)}`,
|
||||
);
|
||||
const json: {
|
||||
synsets: Array<{entry: Array<{synonym: string[]}>}>;
|
||||
} = await response.json();
|
||||
const synonyms = Array.from(
|
||||
new Set<string>(
|
||||
json.synsets.reduce(
|
||||
(sum, synset) => [...sum, ...synset.entry.map((e) => e.synonym[0])],
|
||||
[] as string[],
|
||||
),
|
||||
),
|
||||
)
|
||||
.filter((word) => !/[\s-]/.exec(word))
|
||||
.map((word) => sanitize(word));
|
||||
return synonyms;
|
||||
} catch (err) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
const Suggestion: React.FC<{
|
||||
query: string;
|
||||
onSubmit: (name: string) => void;
|
||||
}> = ({query, onSubmit}) => {
|
||||
const {t} = useTranslation();
|
||||
const synonymRef = useRef<string[]>([]);
|
||||
const [bestWords, setBestWords] = useState<string[]>([]);
|
||||
|
||||
function shuffle(): void {
|
||||
const best = fillArray(
|
||||
sampleFromArray(synonymRef.current, maximumCount),
|
||||
query,
|
||||
maximumCount,
|
||||
).map((word) => modifyWord(word));
|
||||
setBestWords(best);
|
||||
}
|
||||
|
||||
function applyQuery(name: string): void {
|
||||
sendAcceptSuggestionEvent();
|
||||
onSubmit(name);
|
||||
}
|
||||
|
||||
function onShuffleButtonClicked() {
|
||||
sendShuffleSuggestionEvent();
|
||||
shuffle();
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
let isEffective = true;
|
||||
const fn = async (): Promise<void> => {
|
||||
if (query && query.length > 0) {
|
||||
const synonyms = await findSynonyms(query);
|
||||
if (!isEffective) {
|
||||
return;
|
||||
}
|
||||
synonymRef.current = [query, ...synonyms];
|
||||
shuffle();
|
||||
}
|
||||
};
|
||||
fn();
|
||||
return () => {
|
||||
isEffective = false;
|
||||
};
|
||||
// eslint-disable-next-line
|
||||
}, [query]);
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Title>{t('try')}</Title>
|
||||
<Items>
|
||||
{bestWords &&
|
||||
bestWords.map((name, i) => (
|
||||
<Item
|
||||
key={name + i}
|
||||
onClick={(): void => applyQuery(name)}
|
||||
delay={i + 1}
|
||||
>
|
||||
<span>{name}</span>
|
||||
</Item>
|
||||
))}
|
||||
</Items>
|
||||
<Button onClick={onShuffleButtonClicked}>
|
||||
<TiArrowSync />
|
||||
</Button>
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
|
||||
export default Suggestion;
|
||||
|
||||
const Container = styled.div`
|
||||
margin-top: 20px;
|
||||
margin-bottom: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
|
||||
${mobile} {
|
||||
margin-top: 15px;
|
||||
}
|
||||
`;
|
||||
|
||||
const Title = styled.div`
|
||||
padding: 0 10px;
|
||||
color: gray;
|
||||
border: 1px solid gray;
|
||||
border-radius: 2em;
|
||||
text-transform: uppercase;
|
||||
font-size: 12px;
|
||||
user-select: none;
|
||||
`;
|
||||
|
||||
const Items = styled.div`
|
||||
margin: 5px 0;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
|
||||
${mobile} {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
`;
|
||||
|
||||
const Item = styled.div<{delay: number}>`
|
||||
margin: 10px 10px 0;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
font-family: inherit;
|
||||
font-size: 1.5rem;
|
||||
line-height: 1em;
|
||||
border-bottom: 1px dashed black;
|
||||
color: black;
|
||||
overflow: hidden;
|
||||
|
||||
span {
|
||||
display: block;
|
||||
animation: 0.6s cubic-bezier(0.19, 1, 0.22, 1)
|
||||
${(props) => `${props.delay * 0.1}s`} 1 normal both running ${slideUp};
|
||||
}
|
||||
|
||||
${mobile} {
|
||||
margin: 10px 0 0;
|
||||
font-size: 1.3rem;
|
||||
}
|
||||
`;
|
||||
|
||||
const Button = styled(motion.div).attrs({
|
||||
whileHover: {scale: 1.1},
|
||||
whileTap: {scale: 0.9},
|
||||
})`
|
||||
margin: 15px 0 0 0;
|
||||
padding: 8px 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-bottom: none;
|
||||
color: white;
|
||||
border-radius: 4px;
|
||||
font-size: 1.3rem;
|
||||
user-select: none;
|
||||
background: #5610ff;
|
||||
transition: background 0.1s ease-out;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: #723df3;
|
||||
}
|
||||
|
||||
&:active {
|
||||
background: #a17ff5;
|
||||
}
|
||||
`;
|
||||
242
src/components/Welcome.tsx
Normal file
242
src/components/Welcome.tsx
Normal file
@@ -0,0 +1,242 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {Link} from 'react-router-dom';
|
||||
|
||||
import {
|
||||
FaMapSigns,
|
||||
FaGithub,
|
||||
FaGitlab,
|
||||
FaNpm,
|
||||
FaPython,
|
||||
FaGem,
|
||||
FaLinux,
|
||||
FaAppStore,
|
||||
FaInstagram,
|
||||
FaTwitter,
|
||||
FaSlack,
|
||||
FaAws,
|
||||
FaJsSquare,
|
||||
FaBuilding,
|
||||
} from 'react-icons/fa';
|
||||
import {IoIosBeer} from 'react-icons/io';
|
||||
import {DiRust, DiHeroku, DiFirebase} from 'react-icons/di';
|
||||
|
||||
import {SpectrumIcon, NowIcon, NetlifyIcon, OcamlIcon} from './Icons';
|
||||
import {mobile} from '../util/css';
|
||||
import {sendGettingStartedEvent} from '../util/analytics';
|
||||
|
||||
const Welcome: React.FC = () => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Hero>
|
||||
<HeroTitle>{t('title')}</HeroTitle>
|
||||
<HeroText>{t('description')}</HeroText>
|
||||
<ButtonContainer>
|
||||
<List>
|
||||
<ListButton>
|
||||
<Link to="/s/awesome" onClick={() => sendGettingStartedEvent()}>
|
||||
{t('gettingStarted')}
|
||||
</Link>
|
||||
</ListButton>
|
||||
</List>
|
||||
</ButtonContainer>
|
||||
</Hero>
|
||||
<HighlightedList>
|
||||
<ListItem>
|
||||
<FaMapSigns /> {t('providers.domains')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FaGithub /> {t('providers.github')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FaGitlab /> {t('providers.gitlab')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FaNpm /> {t('providers.npm')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<DiRust /> {t('providers.rust')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FaPython /> {t('providers.pypi')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FaGem /> {t('providers.rubygems')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<OcamlIcon /> {t('providers.ocaml')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<IoIosBeer /> {t('providers.homebrew')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FaLinux /> {t('providers.linux')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FaTwitter /> {t('providers.twitter')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FaInstagram /> {t('providers.instagram')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<SpectrumIcon /> {t('providers.spectrum')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FaSlack /> {t('providers.slack')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<DiHeroku /> {t('providers.heroku')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<NowIcon /> {t('providers.now')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<NetlifyIcon /> {t('providers.netlify')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FaAws /> {t('providers.s3')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<DiFirebase /> {t('providers.firebase')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FaJsSquare /> {t('providers.jsorg')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FaGithub /> {t('providers.githubSearch')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FaAppStore /> {t('providers.appStore')}
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FaBuilding /> {t('providers.nta')}
|
||||
</ListItem>
|
||||
</HighlightedList>
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
export default Welcome;
|
||||
|
||||
const Container = styled.div`
|
||||
margin-top: 30px;
|
||||
padding-bottom: 40px;
|
||||
text-align: center;
|
||||
font-size: 1.5rem;
|
||||
|
||||
${mobile} {
|
||||
margin-top: 0px;
|
||||
text-align: left;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
`;
|
||||
|
||||
const HeroTitle = styled.h1`
|
||||
padding-bottom: 30px;
|
||||
line-height: 1em;
|
||||
font-size: 5rem;
|
||||
font-weight: 700;
|
||||
|
||||
${mobile} {
|
||||
font-size: 2.5em;
|
||||
}
|
||||
`;
|
||||
|
||||
const HeroText = styled.p`
|
||||
font-size: 1.2em;
|
||||
font-weight: 400;
|
||||
line-height: 1.3em;
|
||||
color: #3c3c3c;
|
||||
`;
|
||||
|
||||
const Hero = styled.div`
|
||||
margin-right: 20vw;
|
||||
margin-left: 20vw;
|
||||
|
||||
${mobile} {
|
||||
margin: inherit;
|
||||
padding-right: 20px;
|
||||
padding-left: 20px;
|
||||
}
|
||||
`;
|
||||
|
||||
const ButtonContainer = styled.div`
|
||||
margin: 10px 0 0 0;
|
||||
`;
|
||||
|
||||
const List = styled.div`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
|
||||
font-size: 1rem;
|
||||
|
||||
${mobile} {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
`;
|
||||
|
||||
const HighlightedList = styled.div`
|
||||
margin-top: 100px;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
|
||||
${mobile} {
|
||||
flex-direction: column;
|
||||
margin-top: 50px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
padding: 50px 20vw 50px 20vw;
|
||||
color: white;
|
||||
/* background-image: linear-gradient(180deg, #a57bf3 0%, #4364e1 100%); */
|
||||
background: #632bec;
|
||||
`;
|
||||
|
||||
const ListItem = styled.div`
|
||||
margin: 20px 25px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 1.5rem;
|
||||
line-height: 1em;
|
||||
|
||||
${mobile} {
|
||||
margin: 10px 0;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
svg {
|
||||
margin-right: 5px;
|
||||
}
|
||||
`;
|
||||
|
||||
const ListButton = styled.div`
|
||||
margin: 10px 5px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 1.2rem;
|
||||
line-height: 1em;
|
||||
|
||||
${mobile} {
|
||||
margin: 10px 10px 0 0;
|
||||
}
|
||||
|
||||
a {
|
||||
color: black;
|
||||
padding: 12px 25px;
|
||||
border: 1px solid black;
|
||||
border-radius: 2px;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: white;
|
||||
background: black;
|
||||
}
|
||||
}
|
||||
`;
|
||||
393
src/components/cards/core.tsx
Normal file
393
src/components/cards/core.tsx
Normal file
@@ -0,0 +1,393 @@
|
||||
import React, {useState, useEffect, Suspense} from 'react';
|
||||
import styled from 'styled-components';
|
||||
import useFetch from 'fetch-suspense';
|
||||
import Tooltip from 'rc-tooltip';
|
||||
import 'rc-tooltip/assets/bootstrap.css';
|
||||
import BarLoader from 'react-spinners/BarLoader';
|
||||
import {GoInfo} from 'react-icons/go';
|
||||
import {IoIosFlash} from 'react-icons/io';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {OutboundLink} from 'react-ga';
|
||||
|
||||
import {sendError, sendExpandEvent} from '../../util/analytics';
|
||||
import {mobile} from '../../util/css';
|
||||
import {useStoreActions} from '../../store';
|
||||
|
||||
export const COLORS = {
|
||||
available: '#6e00ff',
|
||||
unavailable: 'darkgrey',
|
||||
error: '#ff388b',
|
||||
};
|
||||
|
||||
export const Card: React.FC<{title: string}> = ({title, children}) => {
|
||||
return (
|
||||
<CardContainer>
|
||||
<CardTitle>{title}</CardTitle>
|
||||
<CardContent>
|
||||
<ErrorHandler>{children}</ErrorHandler>
|
||||
</CardContent>
|
||||
</CardContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export const Repeater: React.FC<{
|
||||
items: string[];
|
||||
moreItems?: string[];
|
||||
children: (name: string) => React.ReactNode;
|
||||
}> = ({items = [], moreItems = [], children}) => {
|
||||
const [revealAlternatives, setRevealAlternatives] = useState(false);
|
||||
const {t} = useTranslation();
|
||||
|
||||
function onClick() {
|
||||
sendExpandEvent();
|
||||
setRevealAlternatives(true);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setRevealAlternatives(false);
|
||||
}, [items, moreItems]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{items.map((name) => (
|
||||
<ErrorHandler key={name}>{children(name)}</ErrorHandler>
|
||||
))}
|
||||
|
||||
{revealAlternatives
|
||||
? moreItems.map((name) => (
|
||||
<ErrorHandler key={name}>{children(name)}</ErrorHandler>
|
||||
))
|
||||
: null}
|
||||
{moreItems.length > 0 && !revealAlternatives ? (
|
||||
<Button onClick={onClick}>{t('showMore')}</Button>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
interface Response {
|
||||
error?: string;
|
||||
availability: boolean;
|
||||
}
|
||||
|
||||
class APIError extends Error {
|
||||
constructor(message?: string) {
|
||||
super(message);
|
||||
Object.setPrototypeOf(this, APIError.prototype);
|
||||
}
|
||||
}
|
||||
class NotFoundError extends Error {
|
||||
constructor(message?: string) {
|
||||
super(message);
|
||||
Object.setPrototypeOf(this, NotFoundError.prototype);
|
||||
}
|
||||
}
|
||||
|
||||
export const DedicatedAvailability: React.FC<{
|
||||
name: string;
|
||||
query?: string;
|
||||
message?: string;
|
||||
messageIfTaken?: string;
|
||||
service: string;
|
||||
link: string;
|
||||
linkIfTaken?: string;
|
||||
prefix?: string;
|
||||
suffix?: string;
|
||||
icon: React.ReactNode;
|
||||
}> = ({
|
||||
name,
|
||||
query = undefined,
|
||||
message = '',
|
||||
messageIfTaken = undefined,
|
||||
service,
|
||||
link,
|
||||
linkIfTaken = undefined,
|
||||
prefix = '',
|
||||
suffix = '',
|
||||
icon,
|
||||
}) => {
|
||||
const increaseCounter = useStoreActions((actions) => actions.stats.add);
|
||||
const response = useFetch(
|
||||
`/api/services/${service}/${encodeURIComponent(query || name)}`,
|
||||
) as Response;
|
||||
|
||||
if (response.error) {
|
||||
throw new APIError(`${service}: ${response.error}`);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
increaseCounter(response.availability);
|
||||
// eslint-disable-next-line
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Result
|
||||
title={name}
|
||||
message={response.availability ? message : messageIfTaken || message}
|
||||
link={response.availability ? link : linkIfTaken || link}
|
||||
icon={icon}
|
||||
prefix={prefix}
|
||||
suffix={suffix}
|
||||
availability={response.availability}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export const ExistentialAvailability: React.FC<{
|
||||
name: string;
|
||||
target: string;
|
||||
message?: string;
|
||||
messageIfTaken?: string;
|
||||
link: string;
|
||||
linkIfTaken?: string;
|
||||
prefix?: string;
|
||||
suffix?: string;
|
||||
icon: React.ReactNode;
|
||||
}> = ({
|
||||
name,
|
||||
message = '',
|
||||
messageIfTaken = undefined,
|
||||
target,
|
||||
link,
|
||||
linkIfTaken = undefined,
|
||||
prefix = '',
|
||||
suffix = '',
|
||||
icon,
|
||||
}) => {
|
||||
const increaseCounter = useStoreActions((actions) => actions.stats.add);
|
||||
const response = useFetch(target, undefined, {metadata: true});
|
||||
|
||||
if (response.status !== 404 && response.status !== 200) {
|
||||
throw new NotFoundError(`${name}: ${response.status}`);
|
||||
}
|
||||
|
||||
const availability = response.status === 404;
|
||||
|
||||
useEffect(() => {
|
||||
increaseCounter(availability);
|
||||
// eslint-disable-next-line
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Result
|
||||
title={name}
|
||||
message={availability ? message : messageIfTaken || message}
|
||||
link={availability ? link : linkIfTaken || link}
|
||||
icon={icon}
|
||||
prefix={prefix}
|
||||
suffix={suffix}
|
||||
availability={availability}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export const Result: React.FC<{
|
||||
title: string;
|
||||
message?: string;
|
||||
link?: string;
|
||||
icon: React.ReactNode;
|
||||
prefix?: string;
|
||||
suffix?: string;
|
||||
availability?: boolean;
|
||||
}> = ({
|
||||
title,
|
||||
message = '',
|
||||
link,
|
||||
icon,
|
||||
prefix = '',
|
||||
suffix = '',
|
||||
availability,
|
||||
}) => {
|
||||
const content = (
|
||||
<>
|
||||
{prefix}
|
||||
{title}
|
||||
{suffix}
|
||||
</>
|
||||
);
|
||||
const itemColor =
|
||||
availability === undefined
|
||||
? 'inherit'
|
||||
: availability
|
||||
? COLORS.available
|
||||
: COLORS.unavailable;
|
||||
return (
|
||||
<ResultContainer>
|
||||
<Tooltip overlay={message} placement="top" trigger={['hover']}>
|
||||
<ResultItem color={itemColor}>
|
||||
<ResultIcon>{icon}</ResultIcon>
|
||||
<ResultName>
|
||||
{link ? (
|
||||
<OutboundLink
|
||||
to={link}
|
||||
eventLabel={link.split('/')[2]}
|
||||
target="_blank"
|
||||
>
|
||||
{content}
|
||||
</OutboundLink>
|
||||
) : (
|
||||
content
|
||||
)}
|
||||
</ResultName>
|
||||
{availability === true ? (
|
||||
<AvailableIcon>
|
||||
<IoIosFlash />{' '}
|
||||
</AvailableIcon>
|
||||
) : null}
|
||||
</ResultItem>
|
||||
</Tooltip>
|
||||
</ResultContainer>
|
||||
);
|
||||
};
|
||||
|
||||
// 1. getDerivedStateFromError
|
||||
// 2. render()
|
||||
// 3. componentDidCatch() send errorInfo to Sentry
|
||||
// 4. render(), now with eventId provided from Sentry
|
||||
class ErrorBoundary extends React.Component<
|
||||
{},
|
||||
{hasError: boolean; message: string; eventId?: string}
|
||||
> {
|
||||
constructor(props: {}) {
|
||||
super(props);
|
||||
this.state = {hasError: false, message: '', eventId: undefined};
|
||||
}
|
||||
|
||||
// used in SSR
|
||||
static getDerivedStateFromError(error: Error) {
|
||||
return {hasError: true, message: error.message};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
componentDidCatch(error: Error, errorInfo: any) {
|
||||
if (error instanceof APIError || error instanceof NotFoundError) {
|
||||
return;
|
||||
}
|
||||
sendError(error, errorInfo).then((eventId) => {
|
||||
this.setState({eventId});
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.hasError) {
|
||||
return (
|
||||
<ResultContainer>
|
||||
<Tooltip
|
||||
overlay={`${this.state.message}${
|
||||
this.state.eventId ? ` (${this.state.eventId})` : ''
|
||||
}`}
|
||||
placement="top"
|
||||
trigger={['hover']}
|
||||
>
|
||||
<ResultItem color={COLORS.error}>
|
||||
<ResultIcon>
|
||||
<GoInfo />
|
||||
</ResultIcon>
|
||||
<ResultName>Error</ResultName>
|
||||
</ResultItem>
|
||||
</Tooltip>
|
||||
</ResultContainer>
|
||||
);
|
||||
}
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
const ErrorHandler: React.FC = ({children}) => (
|
||||
<ErrorBoundary>
|
||||
<Suspense
|
||||
fallback={
|
||||
<ResultContainer>
|
||||
<BarLoader />
|
||||
</ResultContainer>
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</Suspense>
|
||||
</ErrorBoundary>
|
||||
);
|
||||
|
||||
const CardContainer = styled.div`
|
||||
padding: 40px;
|
||||
font-size: 1rem;
|
||||
line-height: 1rem;
|
||||
|
||||
${mobile} {
|
||||
margin-bottom: 40px;
|
||||
padding: 0px;
|
||||
}
|
||||
`;
|
||||
|
||||
const CardTitle = styled.div`
|
||||
margin-bottom: 15px;
|
||||
font-size: 1em;
|
||||
font-weight: bold;
|
||||
|
||||
${mobile} {
|
||||
padding: 0 20px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 1.2rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
`;
|
||||
|
||||
const CardContent = styled.div`
|
||||
border-radius: 2px;
|
||||
|
||||
${mobile} {
|
||||
padding: 20px;
|
||||
box-shadow: 0px 2px 20px rgba(0, 0, 0, 0.1);
|
||||
background: white;
|
||||
border-radius: 0;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
`;
|
||||
|
||||
const Button = styled.div`
|
||||
margin-top: 5px;
|
||||
display: inline-block;
|
||||
padding: 5px 0;
|
||||
border: none;
|
||||
border-bottom: 1px dashed black;
|
||||
cursor: pointer;
|
||||
font-family: monospace;
|
||||
font-size: 0.8em;
|
||||
`;
|
||||
|
||||
const ResultContainer = styled.div`
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 4px 0;
|
||||
`;
|
||||
|
||||
export const ResultIcon = styled.div`
|
||||
width: 1em;
|
||||
`;
|
||||
|
||||
export const ResultItem = styled.div`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
word-break: break-all;
|
||||
color: ${({color}) => color};
|
||||
`;
|
||||
|
||||
export const ResultName = styled.div`
|
||||
margin-left: 6px;
|
||||
font-family: monospace;
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
`;
|
||||
|
||||
export const AvailableIcon = styled.div`
|
||||
margin-top: 2px;
|
||||
margin-left: 3px;
|
||||
padding: 0;
|
||||
width: 15px;
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
height: 15px;
|
||||
`;
|
||||
79
src/components/cards/index.tsx
Normal file
79
src/components/cards/index.tsx
Normal file
@@ -0,0 +1,79 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {mobile} from '../../util/css';
|
||||
|
||||
import DomainCard from './providers/Domains';
|
||||
import GithubCard from './providers/GitHubRepository';
|
||||
import GitLabCard from './providers/GitLab';
|
||||
import NpmCard from './providers/Npm';
|
||||
import PypiCard from './providers/PyPI';
|
||||
import RubyGemsCard from './providers/RubyGems';
|
||||
import CratesioCard from './providers/Cratesio';
|
||||
import HomebrewCard from './providers/Homebrew';
|
||||
import LinuxCard from './providers/Linux';
|
||||
import TwitterCard from './providers/Twitter';
|
||||
import InstagramCard from './providers/Instagram';
|
||||
import SpectrumCard from './providers/Spectrum';
|
||||
import SlackCard from './providers/Slack';
|
||||
import S3Card from './providers/S3';
|
||||
import JsOrgCard from './providers/JsOrg';
|
||||
import GithubSearchCard from './providers/GitHubSearch';
|
||||
import AppStoreCard from './providers/AppStore';
|
||||
import HerokuCard from './providers/Heroku';
|
||||
import VercelCard from './providers/Vercel';
|
||||
import NtaCard from './providers/Nta';
|
||||
import NetlifyCard from './providers/Netlify';
|
||||
import OcamlCard from './providers/Ocaml';
|
||||
import FirebaseCard from './providers/Firebase';
|
||||
|
||||
const Index: React.FC<{query: string}> = ({query}) => {
|
||||
const {
|
||||
i18n: {language},
|
||||
} = useTranslation();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Cards>
|
||||
<DomainCard query={query} />
|
||||
<GithubCard query={query} />
|
||||
<TwitterCard query={query} />
|
||||
<NpmCard query={query} />
|
||||
<HomebrewCard query={query} />
|
||||
<GitLabCard query={query} />
|
||||
<PypiCard query={query} />
|
||||
<CratesioCard query={query} />
|
||||
<RubyGemsCard query={query} />
|
||||
<LinuxCard query={query} />
|
||||
<OcamlCard query={query} />
|
||||
<VercelCard query={query} />
|
||||
<HerokuCard query={query} />
|
||||
<NetlifyCard query={query} />
|
||||
<JsOrgCard query={query} />
|
||||
<SlackCard query={query} />
|
||||
<InstagramCard query={query} />
|
||||
<SpectrumCard query={query} />
|
||||
<S3Card query={query} />
|
||||
<FirebaseCard query={query} />
|
||||
</Cards>
|
||||
<Cards>
|
||||
<GithubSearchCard query={query} />
|
||||
<AppStoreCard query={query} />
|
||||
{language === 'ja' ? <NtaCard query={query} /> : null}
|
||||
</Cards>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Index;
|
||||
|
||||
const Cards = styled.div`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
|
||||
${mobile} {
|
||||
flex-direction: column;
|
||||
}
|
||||
`;
|
||||
47
src/components/cards/providers/AppStore.tsx
Normal file
47
src/components/cards/providers/AppStore.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import React from 'react';
|
||||
import useFetch from 'fetch-suspense';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {FaAppStore, FaInfoCircle} from 'react-icons/fa';
|
||||
|
||||
import {Card, Result} from '../core';
|
||||
|
||||
const Search: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
const term = encodeURIComponent(query);
|
||||
const response = useFetch(
|
||||
`/availability/appstore/${term}?country=${t('countryCode')}`,
|
||||
) as {
|
||||
result: Array<{name: string; viewURL: string; price: number; id: string}>;
|
||||
};
|
||||
const apps = response.result;
|
||||
|
||||
return (
|
||||
<>
|
||||
{apps && apps.length > 0 ? (
|
||||
apps.map((app) => (
|
||||
<Result
|
||||
title={app.name.split(/[-–—\-:]/)[0]}
|
||||
message={`Price: ${app.price}`}
|
||||
link={app.viewURL}
|
||||
icon={<FaAppStore />}
|
||||
key={app.id}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
<Result title={t('noResult')} icon={<FaInfoCircle />} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const AppStoreCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
return (
|
||||
<Card title={t('providers.appStore')}>
|
||||
<Search query={query} />
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default AppStoreCard;
|
||||
31
src/components/cards/providers/Cratesio.tsx
Normal file
31
src/components/cards/providers/Cratesio.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {DiRust} from 'react-icons/di';
|
||||
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
|
||||
const CratesioCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
const lowerCase = query.toLowerCase();
|
||||
|
||||
const names = [lowerCase];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.rust')}>
|
||||
<Repeater items={names}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
query={`crates.io/api/v1/crates/${name}`}
|
||||
service="existence"
|
||||
link={`https://crates.io/crates/${name}`}
|
||||
message="Go to crates.io"
|
||||
icon={<DiRust />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default CratesioCard;
|
||||
60
src/components/cards/providers/Domains.tsx
Normal file
60
src/components/cards/providers/Domains.tsx
Normal file
@@ -0,0 +1,60 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {MdDomain} from 'react-icons/md';
|
||||
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
import {zones} from '../../../util/zones';
|
||||
|
||||
const DomainCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
const sanitizedQuery = query
|
||||
.replace(/[^0-9a-zA-Z_-]/g, '')
|
||||
.replace(/_/g, '-');
|
||||
const lowerCase = sanitizedQuery.toLowerCase();
|
||||
|
||||
const domainHackSuggestions = zones
|
||||
.map((zone) => new RegExp(`${zone}$`).exec(lowerCase.slice(1)))
|
||||
.filter((s): s is RegExpExecArray => s !== null)
|
||||
.map(
|
||||
(m) =>
|
||||
lowerCase.substring(0, m.index + 1) +
|
||||
'.' +
|
||||
lowerCase.substring(m.index + 1),
|
||||
);
|
||||
|
||||
const names = [
|
||||
`${lowerCase}.com`,
|
||||
`${lowerCase}app.com`,
|
||||
`${lowerCase}.app`,
|
||||
`${lowerCase}.dev`,
|
||||
`${lowerCase}.org`,
|
||||
`${lowerCase}.io`,
|
||||
...domainHackSuggestions,
|
||||
];
|
||||
const moreNames = [
|
||||
`${lowerCase}.sh`,
|
||||
`${lowerCase}.tools`,
|
||||
`${lowerCase}.design`,
|
||||
`${lowerCase}.build`,
|
||||
`get${lowerCase}.com`,
|
||||
];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.domains')}>
|
||||
<Repeater items={names} moreItems={moreNames}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
message="Go to Domainr.com"
|
||||
service="domain"
|
||||
link={`https://domainr.com/?q=${name}`}
|
||||
icon={<MdDomain />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default DomainCard;
|
||||
35
src/components/cards/providers/Firebase.tsx
Normal file
35
src/components/cards/providers/Firebase.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {DiFirebase} from 'react-icons/di';
|
||||
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
|
||||
const FirebaseCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
const sanitizedQuery = query
|
||||
.replace(/[^0-9a-zA-Z_-]/g, '')
|
||||
.replace(/_/g, '-');
|
||||
const lowerCase = sanitizedQuery.toLowerCase();
|
||||
|
||||
const names = [lowerCase];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.firebase')}>
|
||||
<Repeater items={names}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
query={`${name}.firebaseio.com`}
|
||||
service="existence"
|
||||
message="Go to Firebase"
|
||||
link={`https://${name}.firebaseio.com/`}
|
||||
icon={<DiFirebase />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default FirebaseCard;
|
||||
33
src/components/cards/providers/GitHubRepository.tsx
Normal file
33
src/components/cards/providers/GitHubRepository.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {FaGithub} from 'react-icons/fa';
|
||||
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
|
||||
const GithubCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
const lowerCase = query.toLowerCase();
|
||||
|
||||
const names = [query, `${lowerCase}-dev`, `${lowerCase}-team`];
|
||||
const moreNames = [`${lowerCase}hq`, `${lowerCase}-org`, `${lowerCase}js`];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.github')}>
|
||||
<Repeater items={names} moreItems={moreNames}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
query={`github.com/${name}`}
|
||||
service="existence"
|
||||
message={`Go to github.com/${name}`}
|
||||
link={`https://github.com/${name}`}
|
||||
prefix="github.com/"
|
||||
icon={<FaGithub />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default GithubCard;
|
||||
56
src/components/cards/providers/GitHubSearch.tsx
Normal file
56
src/components/cards/providers/GitHubSearch.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import React from 'react';
|
||||
import useFetch from 'fetch-suspense';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {FaGithub, FaInfoCircle} from 'react-icons/fa';
|
||||
|
||||
import {Card, Result} from '../core';
|
||||
|
||||
const Search: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
const searchQuery = encodeURIComponent(`${query} in:name`);
|
||||
const limit = 10;
|
||||
const response = useFetch(
|
||||
`https://api.github.com/search/repositories?q=${searchQuery}&per_page=${limit}`,
|
||||
) as {
|
||||
items: Array<{
|
||||
full_name: string;
|
||||
description: string;
|
||||
stargazers_count: number;
|
||||
html_url: string;
|
||||
id: string;
|
||||
}>;
|
||||
};
|
||||
const repos = response.items || [];
|
||||
|
||||
return (
|
||||
<>
|
||||
{repos.length > 0 ? (
|
||||
repos.map((repo) => (
|
||||
<Result
|
||||
title={repo.full_name}
|
||||
message={`${repo.description || repo.full_name} (🌟${
|
||||
repo.stargazers_count
|
||||
})`}
|
||||
link={repo.html_url}
|
||||
icon={<FaGithub />}
|
||||
key={repo.id}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
<Result title={t('noResult')} icon={<FaInfoCircle />} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const GithubSearchCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
return (
|
||||
<Card title={t('providers.githubSearch')}>
|
||||
<Search query={query} />
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default GithubSearchCard;
|
||||
31
src/components/cards/providers/GitLab.tsx
Normal file
31
src/components/cards/providers/GitLab.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {FaGitlab} from 'react-icons/fa';
|
||||
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
|
||||
const GitLabCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
const lowerCase = query.toLowerCase();
|
||||
|
||||
const names = [lowerCase];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.gitlab')}>
|
||||
<Repeater items={names}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
prefix="gitlab.com/"
|
||||
service="gitlab"
|
||||
message={`Open gitlab.com/${name}`}
|
||||
link={`https://gitlab.com/${name}`}
|
||||
icon={<FaGitlab />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default GitLabCard;
|
||||
34
src/components/cards/providers/Heroku.tsx
Normal file
34
src/components/cards/providers/Heroku.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {DiHeroku} from 'react-icons/di';
|
||||
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
|
||||
const HerokuCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
const sanitizedQuery = query
|
||||
.replace(/[^0-9a-zA-Z_-]/g, '')
|
||||
.replace(/_/g, '-');
|
||||
const lowerCase = sanitizedQuery.toLowerCase();
|
||||
|
||||
const names = [lowerCase];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.heroku')}>
|
||||
<Repeater items={names}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={`${name}.herokuapp.com`}
|
||||
service="existence"
|
||||
message="Go to Heroku"
|
||||
link={`https://${name}.herokuapp.com`}
|
||||
icon={<DiHeroku />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default HerokuCard;
|
||||
40
src/components/cards/providers/Homebrew.tsx
Normal file
40
src/components/cards/providers/Homebrew.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {IoIosBeer} from 'react-icons/io';
|
||||
|
||||
import {Card, Repeater, ExistentialAvailability} from '../core';
|
||||
|
||||
const HomebrewCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
const lowerCase = query.toLowerCase();
|
||||
|
||||
const names = [lowerCase];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.homebrew')}>
|
||||
<Repeater items={names}>
|
||||
{(name) => (
|
||||
<>
|
||||
<ExistentialAvailability
|
||||
name={name}
|
||||
target={`https://formulae.brew.sh/api/formula/${name}.json`}
|
||||
message="Go to formula page"
|
||||
link={`https://formulae.brew.sh/formula/${name}`}
|
||||
icon={<IoIosBeer />}
|
||||
/>
|
||||
<ExistentialAvailability
|
||||
name={name}
|
||||
target={`https://formulae.brew.sh/api/cask/${name}.json`}
|
||||
message="Go to formula page"
|
||||
link={`https://formulae.brew.sh/cask/${name}`}
|
||||
suffix=" (Cask)"
|
||||
icon={<IoIosBeer />}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default HomebrewCard;
|
||||
31
src/components/cards/providers/Instagram.tsx
Normal file
31
src/components/cards/providers/Instagram.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {FaInstagram} from 'react-icons/fa';
|
||||
|
||||
import {Card, Repeater, ExistentialAvailability} from '../core';
|
||||
|
||||
const InstagramCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
const lowerCase = query.toLowerCase();
|
||||
|
||||
const names = [query];
|
||||
const moreNames = [`${lowerCase}app`, `${lowerCase}_hq`, `get.${lowerCase}`];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.instagram')}>
|
||||
<Repeater items={names} moreItems={moreNames}>
|
||||
{(name) => (
|
||||
<ExistentialAvailability
|
||||
name={name}
|
||||
target={`https://instagram.com/${name}`}
|
||||
link={`https://instagram.com/${name}`}
|
||||
message="Go to Instagram"
|
||||
icon={<FaInstagram />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default InstagramCard;
|
||||
36
src/components/cards/providers/JsOrg.tsx
Normal file
36
src/components/cards/providers/JsOrg.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {FaJsSquare} from 'react-icons/fa';
|
||||
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
|
||||
const JsOrgCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
const sanitizedQuery = query
|
||||
.replace(/[^0-9a-zA-Z_-]/g, '')
|
||||
.replace(/_/g, '-');
|
||||
const lowerCase = sanitizedQuery.toLowerCase();
|
||||
|
||||
const names = [lowerCase];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.jsorg')}>
|
||||
<Repeater items={names}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={`${name}.js.org`}
|
||||
service="dns"
|
||||
message="Go to js.org repository"
|
||||
link="https://github.com/js-org/js.org"
|
||||
messageIfTaken={`Go to ${name}.js.org`}
|
||||
linkIfTaken={`https://${name}.js.org`}
|
||||
icon={<FaJsSquare />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default JsOrgCard;
|
||||
40
src/components/cards/providers/Linux.tsx
Normal file
40
src/components/cards/providers/Linux.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {DiUbuntu} from 'react-icons/di';
|
||||
import {DiDebian} from 'react-icons/di';
|
||||
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
|
||||
const LinuxCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
const lowerCase = query.toLowerCase();
|
||||
|
||||
const names = [lowerCase];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.linux')}>
|
||||
<Repeater items={names}>
|
||||
{(name) => (
|
||||
<>
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
service="launchpad"
|
||||
message="Go to Launchpad"
|
||||
link={`https://launchpad.net/ubuntu/+source/${name}`}
|
||||
icon={<DiUbuntu />}
|
||||
/>
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
service="debian"
|
||||
message="Go to debian.org"
|
||||
link={`https://packages.debian.org/buster/${name}`}
|
||||
icon={<DiDebian />}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default LinuxCard;
|
||||
34
src/components/cards/providers/Netlify.tsx
Normal file
34
src/components/cards/providers/Netlify.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {NetlifyIcon} from '../../Icons';
|
||||
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
|
||||
const NetlifyCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
const sanitizedQuery = query
|
||||
.replace(/[^0-9a-zA-Z_-]/g, '')
|
||||
.replace(/_/g, '-');
|
||||
const lowerCase = sanitizedQuery.toLowerCase();
|
||||
|
||||
const names = [lowerCase];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.netlify')}>
|
||||
<Repeater items={names}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={`${name}.netlify.com`}
|
||||
service="existence"
|
||||
message={`Open ${name}.netlify.com`}
|
||||
link={`https://${name}.netlify.com`}
|
||||
icon={<NetlifyIcon />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default NetlifyCard;
|
||||
46
src/components/cards/providers/Npm.tsx
Normal file
46
src/components/cards/providers/Npm.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {FaNpm} from 'react-icons/fa';
|
||||
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
|
||||
const NpmCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
const lowerCase = query.toLowerCase();
|
||||
|
||||
const names = [lowerCase, `${lowerCase}-js`];
|
||||
const moreNames = [`${lowerCase}js`];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.npm')}>
|
||||
<Repeater items={names} moreItems={moreNames}>
|
||||
{(name) => (
|
||||
<>
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
service="npm"
|
||||
message={`See ${name}`}
|
||||
link={`https://www.npmjs.com/package/${name}`}
|
||||
messageIfTaken={`See ${name}`}
|
||||
linkIfTaken={`https://www.npmjs.com/package/${name}`}
|
||||
icon={<FaNpm />}
|
||||
/>
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
service="npm-org"
|
||||
message="Create Org"
|
||||
link="https://www.npmjs.com/org/create"
|
||||
messageIfTaken={`See @${name}`}
|
||||
linkIfTaken={`https://www.npmjs.com/org/${name}`}
|
||||
prefix="@"
|
||||
suffix=" (Organization)"
|
||||
icon={<FaNpm />}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default NpmCard;
|
||||
45
src/components/cards/providers/Nta.tsx
Normal file
45
src/components/cards/providers/Nta.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import React from 'react';
|
||||
import useFetch from 'fetch-suspense';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {FaBuilding, FaInfoCircle} from 'react-icons/fa';
|
||||
|
||||
import {Card, Result} from '../core';
|
||||
|
||||
const Search: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
const term = encodeURIComponent(query);
|
||||
const response = useFetch(`/api/services/nta/${term}`) as {
|
||||
result: Array<{name: string; phoneticName: string}>;
|
||||
};
|
||||
|
||||
const apps = response.result;
|
||||
|
||||
return (
|
||||
<>
|
||||
{apps.length > 0 ? (
|
||||
apps.map((app, i) => (
|
||||
<Result
|
||||
title={app.name}
|
||||
message={`Phonetic: ${app.phoneticName}`}
|
||||
icon={<FaBuilding />}
|
||||
key={i}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
<Result title={t('noResult')} icon={<FaInfoCircle />} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const NtaCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
return (
|
||||
<Card title={t('providers.nta')}>
|
||||
<Search query={query} />
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default NtaCard;
|
||||
31
src/components/cards/providers/Ocaml.tsx
Normal file
31
src/components/cards/providers/Ocaml.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {OcamlIcon} from '../../Icons';
|
||||
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
|
||||
const OcamlCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
const lowerCase = query.toLowerCase();
|
||||
|
||||
const names = [lowerCase];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.ocaml')}>
|
||||
<Repeater items={names}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
query={`opam.ocaml.org/packages/${name}/`}
|
||||
service="existence"
|
||||
message="Go to opam"
|
||||
link={`https://opam.ocaml.org/packages/${name}/`}
|
||||
icon={<OcamlIcon />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default OcamlCard;
|
||||
34
src/components/cards/providers/PyPI.tsx
Normal file
34
src/components/cards/providers/PyPI.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {FaPython} from 'react-icons/fa';
|
||||
|
||||
import {capitalize} from '../../../util/text';
|
||||
import {Card, DedicatedAvailability, Repeater} from '../core';
|
||||
|
||||
const PypiCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
const names = [query];
|
||||
const moreNames = [`Py${capitalize(query)}`];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.pypi')}>
|
||||
<Repeater items={names} moreItems={moreNames}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
query={`pypi.org/pypi/${name}/json`}
|
||||
service="existence"
|
||||
message="Read Python Packaging User Guide"
|
||||
link="https://packaging.python.org/"
|
||||
messageIfTaken="Go to PyPI"
|
||||
linkIfTaken={`https://pypi.org/project/${name}`}
|
||||
icon={<FaPython />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default PypiCard;
|
||||
31
src/components/cards/providers/RubyGems.tsx
Normal file
31
src/components/cards/providers/RubyGems.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {FaGem} from 'react-icons/fa';
|
||||
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
|
||||
const RubyGemsCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
const names = [query];
|
||||
const moreNames = [`${query.toLowerCase()}-rb`];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.rubygems')}>
|
||||
<Repeater items={names} moreItems={moreNames}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
query={`rubygems.org/gems/${name}`}
|
||||
service="existence"
|
||||
message="Go to RubyGems"
|
||||
link={`https://rubygems.org/gems/${name}`}
|
||||
icon={<FaGem />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default RubyGemsCard;
|
||||
36
src/components/cards/providers/S3.tsx
Normal file
36
src/components/cards/providers/S3.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {FaAws} from 'react-icons/fa';
|
||||
|
||||
import {Card, DedicatedAvailability, Repeater} from '../core';
|
||||
|
||||
const S3Card: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
const sanitizedQuery = query
|
||||
.replace(/[^0-9a-zA-Z_-]/g, '')
|
||||
.replace(/_/g, '-');
|
||||
const lowerCase = sanitizedQuery.toLowerCase();
|
||||
|
||||
const names = [lowerCase];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.s3')}>
|
||||
<Repeater items={names}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
query={`${name}.s3.amazonaws.com`}
|
||||
service="existence"
|
||||
message={`Go to ${name}.s3.amazonaws.com`}
|
||||
link={`https://${name}.s3.amazonaws.com`}
|
||||
suffix=".s3.amazonaws.com"
|
||||
icon={<FaAws />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default S3Card;
|
||||
37
src/components/cards/providers/Slack.tsx
Normal file
37
src/components/cards/providers/Slack.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {FaSlack} from 'react-icons/fa';
|
||||
|
||||
import {Card, DedicatedAvailability, Repeater} from '../core';
|
||||
|
||||
const SlackCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
const sanitizedQuery = query
|
||||
.replace(/[^0-9a-zA-Z_-]/g, '')
|
||||
.replace(/_/g, '-');
|
||||
const lowerCase = sanitizedQuery.toLowerCase();
|
||||
|
||||
const names = [lowerCase];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.slack')}>
|
||||
<Repeater items={names}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
service="slack"
|
||||
message="Create Slack Team"
|
||||
link="https://slack.com/create"
|
||||
messageIfTaken={`Go to ${name}.slack.com`}
|
||||
linkIfTaken={`https://${name}.slack.com`}
|
||||
suffix=".slack.com"
|
||||
icon={<FaSlack />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default SlackCard;
|
||||
31
src/components/cards/providers/Spectrum.tsx
Normal file
31
src/components/cards/providers/Spectrum.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
import {SpectrumIcon} from '../../Icons';
|
||||
|
||||
const SpectrumCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
const names = [query];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.spectrum')}>
|
||||
<Repeater items={names}>
|
||||
{(name) => (
|
||||
<>
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
service="spectrum"
|
||||
message="Create Community"
|
||||
link="https://spectrum.chat/new/community"
|
||||
messageIfTaken="See community in Spectrum"
|
||||
linkIfTaken={`https://spectrum.chat/${name}`}
|
||||
icon={<SpectrumIcon />}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default SpectrumCard;
|
||||
45
src/components/cards/providers/Twitter.tsx
Normal file
45
src/components/cards/providers/Twitter.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {FaTwitter} from 'react-icons/fa';
|
||||
|
||||
import {capitalize} from '../../../util/text';
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
|
||||
const TwitterCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
const sanitizedQuery = query
|
||||
.replace(/[^0-9a-zA-Z_-]/g, '')
|
||||
.replace(/-/g, '_');
|
||||
const lowerCase = sanitizedQuery.toLowerCase();
|
||||
const capitalCase = capitalize(sanitizedQuery);
|
||||
|
||||
const names = [sanitizedQuery, `${capitalCase}App`, `${lowerCase}hq`];
|
||||
const moreNames = [
|
||||
`hey${lowerCase}`,
|
||||
`${capitalCase}Team`,
|
||||
`${lowerCase}_support`,
|
||||
`${lowerCase}_org`,
|
||||
`${lowerCase}_app`,
|
||||
`${capitalCase}JS`,
|
||||
];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.twitter')}>
|
||||
<Repeater items={names} moreItems={moreNames}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={name}
|
||||
query={name}
|
||||
service="twitter"
|
||||
message="Go to Twitter"
|
||||
link={`https://twitter.com/${name}`}
|
||||
icon={<FaTwitter />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default TwitterCard;
|
||||
45
src/components/cards/providers/Vercel.tsx
Normal file
45
src/components/cards/providers/Vercel.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import React from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {NowIcon} from '../../Icons';
|
||||
|
||||
import {Card, Repeater, DedicatedAvailability} from '../core';
|
||||
|
||||
const VercelCard: React.FC<{query: string}> = ({query}) => {
|
||||
const {t} = useTranslation();
|
||||
|
||||
const sanitizedQuery = query
|
||||
.replace(/[^0-9a-zA-Z_-]/g, '')
|
||||
.replace(/_/g, '-');
|
||||
const lowerCase = sanitizedQuery.toLowerCase();
|
||||
|
||||
const names = [lowerCase];
|
||||
|
||||
return (
|
||||
<Card title={t('providers.now')}>
|
||||
<Repeater items={names}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={`${name}.vercel.app`}
|
||||
service="existence"
|
||||
message={`Open ${name}.vercel.app`}
|
||||
link={`https://${name}.vercel.app`}
|
||||
icon={<NowIcon />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
<Repeater items={names}>
|
||||
{(name) => (
|
||||
<DedicatedAvailability
|
||||
name={`${name}.now.sh`}
|
||||
service="existence"
|
||||
message={`Open ${name}.now.sh`}
|
||||
link={`https://${name}.now.sh`}
|
||||
icon={<NowIcon />}
|
||||
/>
|
||||
)}
|
||||
</Repeater>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default VercelCard;
|
||||
44
src/index.tsx
Normal file
44
src/index.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import {Router} from 'react-router-dom';
|
||||
import {StoreProvider} from 'easy-peasy';
|
||||
import {createBrowserHistory} from 'history';
|
||||
|
||||
import App from './App';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
import {FullScreenSuspense} from './util/suspense';
|
||||
import {wrapHistoryWithGA, initSentry} from './util/analytics';
|
||||
import {initCrisp} from './util/crip';
|
||||
import {compose} from './util/array';
|
||||
import {store, wrapHistoryWithStoreHandler} from './store';
|
||||
import './util/i18n';
|
||||
|
||||
initSentry();
|
||||
initCrisp();
|
||||
|
||||
const history = compose(
|
||||
createBrowserHistory(),
|
||||
wrapHistoryWithStoreHandler,
|
||||
wrapHistoryWithGA,
|
||||
);
|
||||
|
||||
ReactDOM.render(
|
||||
<StoreProvider store={store}>
|
||||
<FullScreenSuspense>
|
||||
<Router history={history}>
|
||||
<App />
|
||||
</Router>
|
||||
</FullScreenSuspense>
|
||||
</StoreProvider>,
|
||||
document.getElementById('root'),
|
||||
);
|
||||
|
||||
serviceWorker.register({
|
||||
onUpdate: (registration) => {
|
||||
console.log('New version available! Ready to update?');
|
||||
if (registration && registration.waiting) {
|
||||
registration.waiting.postMessage({type: 'SKIP_WAITING'});
|
||||
}
|
||||
window.location.reload();
|
||||
},
|
||||
});
|
||||
1
src/react-app-env.d.ts
vendored
Normal file
1
src/react-app-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="react-scripts" />
|
||||
146
src/serviceWorker.ts
Normal file
146
src/serviceWorker.ts
Normal file
@@ -0,0 +1,146 @@
|
||||
// This optional code is used to register a service worker.
|
||||
// register() is not called by default.
|
||||
|
||||
// This lets the app load faster on subsequent visits in production, and gives
|
||||
// it offline capabilities. However, it also means that developers (and users)
|
||||
// will only see deployed updates on subsequent visits to a page, after all the
|
||||
// existing tabs open on the page have been closed, since previously cached
|
||||
// resources are updated in the background.
|
||||
|
||||
// To learn more about the benefits of this model and instructions on how to
|
||||
// opt-in, read https://bit.ly/CRA-PWA
|
||||
|
||||
const isLocalhost = Boolean(
|
||||
window.location.hostname === 'localhost' ||
|
||||
// [::1] is the IPv6 localhost address.
|
||||
window.location.hostname === '[::1]' ||
|
||||
// 127.0.0.0/8 are considered localhost for IPv4.
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/.exec(
|
||||
window.location.hostname,
|
||||
),
|
||||
);
|
||||
|
||||
type Config = {
|
||||
onSuccess?: (registration: ServiceWorkerRegistration) => void;
|
||||
onUpdate?: (registration: ServiceWorkerRegistration) => void;
|
||||
};
|
||||
|
||||
function registerValidSW(swUrl: string, config?: Config) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then((registration) => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker == null) {
|
||||
return;
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// At this point, the updated precached content has been fetched,
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
console.log(
|
||||
'New content is available and will be used when all ' +
|
||||
'tabs for this page are closed. See https://bit.ly/CRA-PWA.',
|
||||
);
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onUpdate) {
|
||||
config.onUpdate(registration);
|
||||
}
|
||||
} else {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.');
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onSuccess) {
|
||||
config.onSuccess(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl: string, config?: Config) {
|
||||
// Check if the service worker can be found. If it can't reload the page.
|
||||
fetch(swUrl, {
|
||||
headers: {'Service-Worker': 'script'},
|
||||
})
|
||||
.then((response) => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (
|
||||
response.status === 404 ||
|
||||
(contentType != null && !contentType.includes('javascript'))
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then((registration) => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Service worker found. Proceed as normal.
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function register(config?: Config) {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
if (isLocalhost) {
|
||||
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||
checkValidServiceWorker(swUrl, config);
|
||||
|
||||
// Add some additional logging to localhost, pointing developers to the
|
||||
// service worker/PWA documentation.
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://bit.ly/CRA-PWA',
|
||||
);
|
||||
});
|
||||
} else {
|
||||
// Is not localhost. Just register service worker
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready
|
||||
.then((registration) => {
|
||||
registration.unregister();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
26
src/setupTests.ts
Normal file
26
src/setupTests.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
// this adds jest-dom's custom assertions
|
||||
import '@testing-library/jest-dom/extend-expect';
|
||||
|
||||
// i18next
|
||||
import {join} from 'path';
|
||||
import i18n from 'i18next';
|
||||
import Backend from 'i18next-node-fs-backend';
|
||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
import {initReactI18next} from 'react-i18next';
|
||||
|
||||
i18n
|
||||
.use(Backend)
|
||||
.use(LanguageDetector)
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
backend: {
|
||||
loadPath: join(__dirname, '../public/locales/{{lng}}/{{ns}}.json'),
|
||||
},
|
||||
fallbackLng: 'en',
|
||||
ns: ['translation'],
|
||||
defaultNS: 'translation',
|
||||
debug: false,
|
||||
interpolation: {
|
||||
escapeValue: false, // not needed for react as it escapes by default
|
||||
},
|
||||
});
|
||||
47
src/store.tsx
Normal file
47
src/store.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import {History} from 'history';
|
||||
import {action, createTypedHooks, Action, createStore} from 'easy-peasy';
|
||||
|
||||
interface StatsModel {
|
||||
availableCount: number;
|
||||
totalCount: number;
|
||||
add: Action<StatsModel, boolean>;
|
||||
reset: Action<StatsModel, void>;
|
||||
}
|
||||
|
||||
interface StoreModel {
|
||||
stats: StatsModel;
|
||||
}
|
||||
|
||||
const statsModel: StatsModel = {
|
||||
availableCount: 0,
|
||||
totalCount: 0,
|
||||
add: action((state, isAvailable) => {
|
||||
state.totalCount += 1;
|
||||
if (isAvailable) {
|
||||
state.availableCount += 1;
|
||||
}
|
||||
}),
|
||||
reset: action((state) => {
|
||||
state.totalCount = 0;
|
||||
state.availableCount = 0;
|
||||
}),
|
||||
};
|
||||
|
||||
const storeModel: StoreModel = {
|
||||
stats: statsModel,
|
||||
};
|
||||
|
||||
export const store = createStore(storeModel);
|
||||
|
||||
export function wrapHistoryWithStoreHandler(history: History) {
|
||||
history.listen(() => {
|
||||
// reset stats counter
|
||||
store.getActions().stats.reset();
|
||||
});
|
||||
return history;
|
||||
}
|
||||
|
||||
const typedHooks = createTypedHooks<StoreModel>();
|
||||
export const useStoreActions = typedHooks.useStoreActions;
|
||||
export const useStoreDispatch = typedHooks.useStoreDispatch;
|
||||
export const useStoreState = typedHooks.useStoreState;
|
||||
1
src/types/react-tippy.d.ts
vendored
Normal file
1
src/types/react-tippy.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
declare module 'react-tippy';
|
||||
83
src/util/analytics.ts
Normal file
83
src/util/analytics.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import ReactGA from 'react-ga';
|
||||
import * as Sentry from '@sentry/browser';
|
||||
import {History} from 'history';
|
||||
|
||||
const isProduction = process.env.NODE_ENV !== 'development';
|
||||
|
||||
export function wrapHistoryWithGA(history: History) {
|
||||
if (isProduction) {
|
||||
ReactGA.initialize('UA-28919359-15');
|
||||
ReactGA.pageview(window.location.pathname + window.location.search);
|
||||
history.listen((location) => {
|
||||
ReactGA.pageview(location.pathname + location.search);
|
||||
});
|
||||
}
|
||||
return history;
|
||||
}
|
||||
|
||||
export function trackEvent({
|
||||
category,
|
||||
action,
|
||||
label = undefined,
|
||||
value = undefined,
|
||||
}: {
|
||||
category: string;
|
||||
action: string;
|
||||
label?: string;
|
||||
value?: number;
|
||||
}) {
|
||||
if (isProduction) {
|
||||
ReactGA.event({
|
||||
category,
|
||||
action,
|
||||
label,
|
||||
value,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function sendQueryEvent(query: string): void {
|
||||
trackEvent({category: 'Search', action: 'Invoke New Search', label: query});
|
||||
}
|
||||
|
||||
export function sendGettingStartedEvent(): void {
|
||||
trackEvent({category: 'Search', action: 'Getting Started'});
|
||||
}
|
||||
|
||||
export function sendExpandEvent(): void {
|
||||
trackEvent({category: 'Result', action: 'Expand Card'});
|
||||
}
|
||||
|
||||
export function sendAcceptSuggestionEvent(): void {
|
||||
trackEvent({category: 'Suggestion', action: 'Accept'});
|
||||
}
|
||||
|
||||
export function sendShuffleSuggestionEvent(): void {
|
||||
trackEvent({category: 'Suggestion', action: 'Shuffle'});
|
||||
}
|
||||
|
||||
export function initSentry(): void {
|
||||
if (isProduction) {
|
||||
Sentry.init({
|
||||
dsn: 'https://7ab2df74aead499b950ebef190cc40b7@sentry.io/1759299',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function sendError(
|
||||
error: Error,
|
||||
errorInfo: {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
[key: string]: any;
|
||||
},
|
||||
): Promise<string> {
|
||||
return new Promise((resolve) => {
|
||||
if (isProduction) {
|
||||
Sentry.withScope((scope) => {
|
||||
scope.setExtras(errorInfo);
|
||||
const eventId = Sentry.captureException(error);
|
||||
resolve(eventId);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
25
src/util/array.ts
Normal file
25
src/util/array.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
export function shuffleArray<T>(array: T[]): T[] {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
const temp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
export function sampleFromArray<T>(array: T[], maximum: number): T[] {
|
||||
return shuffleArray(array).slice(0, maximum);
|
||||
}
|
||||
|
||||
export function fillArray<T>(array: T[], filler: string, maximum: number): T[] {
|
||||
const deficit = maximum - array.length;
|
||||
if (deficit > 0) {
|
||||
array = [...array, ...Array(deficit).fill(filler)];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
export function compose<T>(arg: T, ...fn: ((arg: T) => T)[]): T {
|
||||
return fn.reduce((arg, f) => f(arg), arg);
|
||||
}
|
||||
14
src/util/crip.ts
Normal file
14
src/util/crip.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
interface CrispWindow extends Window {
|
||||
$crisp: unknown[];
|
||||
CRISP_WEBSITE_ID: string;
|
||||
}
|
||||
declare let window: CrispWindow;
|
||||
|
||||
export function initCrisp(): void {
|
||||
window.$crisp = [];
|
||||
window.CRISP_WEBSITE_ID = '92b2e096-6892-47dc-bf4a-057bad52d82e';
|
||||
const s = document.createElement('script');
|
||||
s.src = 'https://client.crisp.chat/l.js';
|
||||
s.async = true;
|
||||
document.getElementsByTagName('head')[0].appendChild(s);
|
||||
}
|
||||
12
src/util/css.ts
Normal file
12
src/util/css.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import {keyframes} from 'styled-components';
|
||||
|
||||
export const mobile = '@media screen and (max-width: 800px)';
|
||||
|
||||
export const slideUp = keyframes`
|
||||
from {
|
||||
transform: translateY(150%) skewY(10deg);
|
||||
}
|
||||
to {
|
||||
transform: translateY(0) skewY(0);
|
||||
}
|
||||
`;
|
||||
22
src/util/hooks.test.tsx
Normal file
22
src/util/hooks.test.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import React from 'react';
|
||||
import {render, waitFor} from '@testing-library/react';
|
||||
import {useDeferredState} from './hooks';
|
||||
import 'mutationobserver-shim';
|
||||
|
||||
const App: React.FC = () => {
|
||||
const [value, setValue] = useDeferredState(500, 0);
|
||||
React.useEffect(() => {
|
||||
setValue(1);
|
||||
setValue(2);
|
||||
setValue(3);
|
||||
}, [setValue]);
|
||||
return <div data-testid="root">{value}</div>;
|
||||
};
|
||||
|
||||
it('provoke state flow after certain time passed', async () => {
|
||||
const {getByTestId} = render(<App />);
|
||||
expect(getByTestId('root').textContent).toBe('0');
|
||||
await waitFor(() => {
|
||||
expect(getByTestId('root').textContent).toBe('3');
|
||||
});
|
||||
});
|
||||
21
src/util/hooks.ts
Normal file
21
src/util/hooks.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import {useState, useEffect} from 'react';
|
||||
|
||||
export function useDeferredState<T>(
|
||||
duration = 1000,
|
||||
initialValue: T,
|
||||
): [T, React.Dispatch<React.SetStateAction<T>>] {
|
||||
const [response, setResponse] = useState(initialValue);
|
||||
const [innerValue, setInnerValue] = useState(initialValue);
|
||||
|
||||
useEffect(() => {
|
||||
const fn = setTimeout(() => {
|
||||
setResponse(innerValue);
|
||||
}, duration);
|
||||
|
||||
return (): void => {
|
||||
clearTimeout(fn);
|
||||
};
|
||||
}, [duration, innerValue]);
|
||||
|
||||
return [response, setInnerValue];
|
||||
}
|
||||
30
src/util/i18n.ts
Normal file
30
src/util/i18n.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import i18n from 'i18next';
|
||||
import Backend from 'i18next-chained-backend';
|
||||
import LocalStorageBackend from 'i18next-localstorage-backend';
|
||||
import XHR from 'i18next-xhr-backend';
|
||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
import {initReactI18next} from 'react-i18next';
|
||||
|
||||
const TRANSLATION_VERSION = '1.16';
|
||||
|
||||
i18n
|
||||
.use(Backend)
|
||||
.use(LanguageDetector)
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
backend: {
|
||||
backends: [LocalStorageBackend, XHR],
|
||||
backendOptions: [
|
||||
{
|
||||
versions: {en: TRANSLATION_VERSION, ja: TRANSLATION_VERSION},
|
||||
},
|
||||
],
|
||||
},
|
||||
fallbackLng: 'en',
|
||||
debug: false,
|
||||
interpolation: {
|
||||
escapeValue: false, // not needed for react as it escapes by default
|
||||
},
|
||||
});
|
||||
|
||||
export default i18n;
|
||||
5
src/util/pwa.test.ts
Normal file
5
src/util/pwa.test.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import {isStandalone} from './pwa';
|
||||
|
||||
it('recognize standalone mode', () => {
|
||||
expect(isStandalone()).toEqual(false);
|
||||
});
|
||||
8
src/util/pwa.ts
Normal file
8
src/util/pwa.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
interface CustomNavigator extends Navigator {
|
||||
standalone?: boolean;
|
||||
}
|
||||
|
||||
export function isStandalone(): boolean {
|
||||
const navigator: CustomNavigator = window.navigator;
|
||||
return 'standalone' in navigator && navigator.standalone === true;
|
||||
}
|
||||
22
src/util/suspense.tsx
Normal file
22
src/util/suspense.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import React, {Suspense} from 'react';
|
||||
import styled from 'styled-components';
|
||||
import BarLoader from 'react-spinners/BarLoader';
|
||||
|
||||
export const FullScreenSuspense: React.FC = ({children}) => {
|
||||
return <Suspense fallback={<Fallback />}>{children}</Suspense>;
|
||||
};
|
||||
|
||||
const Container = styled.div`
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
`;
|
||||
|
||||
const Fallback: React.FC = () => (
|
||||
<Container>
|
||||
<BarLoader />
|
||||
</Container>
|
||||
);
|
||||
9
src/util/text.test.ts
Normal file
9
src/util/text.test.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import {capitalize} from './text';
|
||||
|
||||
it('capitalize text', () => {
|
||||
expect(capitalize('test')).toEqual('Test');
|
||||
expect(capitalize('Test')).toEqual('Test');
|
||||
expect(capitalize('tEST')).toEqual('Test');
|
||||
expect(capitalize('TEST')).toEqual('Test');
|
||||
expect(capitalize('')).toEqual('');
|
||||
});
|
||||
37
src/util/text.ts
Normal file
37
src/util/text.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
export function capitalize(text: string): string {
|
||||
if (text.length === 0) return '';
|
||||
return text[0].toUpperCase() + text.slice(1).toLowerCase();
|
||||
}
|
||||
|
||||
export function sanitize(text: string): string {
|
||||
return text
|
||||
.replace(/[\s@+!#$%^&*()[\]./<>{}]/g, '')
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '');
|
||||
}
|
||||
|
||||
export function upper(word: string): string {
|
||||
return word.toUpperCase();
|
||||
}
|
||||
|
||||
export function lower(word: string): string {
|
||||
return word.toLowerCase();
|
||||
}
|
||||
|
||||
export function stem(word: string): string {
|
||||
return word.replace(/[aiueo]$/, '');
|
||||
}
|
||||
|
||||
export function germanify(word: string): string {
|
||||
return word.replace('c', 'k').replace('C', 'K');
|
||||
}
|
||||
|
||||
export function njoin(
|
||||
lhs: string,
|
||||
rhs: string,
|
||||
{elision = true}: {elision?: boolean} = {},
|
||||
): string {
|
||||
return elision
|
||||
? lhs + rhs.replace(new RegExp(`^${lhs[-1]}`, 'i'), '')
|
||||
: lhs + rhs;
|
||||
}
|
||||
1756
src/util/zones.ts
Normal file
1756
src/util/zones.ts
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user