1
0
mirror of https://github.com/uetchy/namae.git synced 2025-07-07 00:16:00 +09:00

48 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-08-31 08:41:53 +09:00
import useFetch from 'fetch-suspense';
import React from 'react';
import { useTranslation } from 'react-i18next';
2020-08-31 09:45:16 +09:00
import { FaInfoCircle } from 'react-icons/fa';
import { SiAppstore } from 'react-icons/si';
2020-08-31 08:41:53 +09:00
import { Card, Result } from '../core';
2019-08-06 01:17:29 +09:00
2020-06-29 12:24:01 +09:00
const Search: React.FC<{ query: string }> = ({ query }) => {
2020-08-31 08:41:53 +09:00
const { t } = useTranslation();
const term = encodeURIComponent(query);
const response = useFetch(
2020-08-31 09:45:16 +09:00
`/api/services/appstore/${term}?country=${t('countryCode')}`
2019-09-01 01:28:24 +09:00
) as {
2020-08-31 08:41:53 +09:00
result: Array<{ name: string; viewURL: string; price: number; id: string }>;
};
const apps = response.result;
2019-08-06 01:17:29 +09:00
return (
2019-08-06 02:07:05 +09:00
<>
2020-06-19 16:15:53 +09:00
{apps && apps.length > 0 ? (
2019-08-07 14:08:45 +09:00
apps.map((app) => (
<Result
2019-08-07 20:39:03 +09:00
title={app.name.split(/[-–—\-:]/)[0]}
2019-08-07 14:08:45 +09:00
message={`Price: ${app.price}`}
link={app.viewURL}
2020-08-31 09:45:16 +09:00
icon={<SiAppstore />}
2019-08-07 14:08:45 +09:00
key={app.id}
/>
))
) : (
2019-09-01 00:00:24 +09:00
<Result title={t('noResult')} icon={<FaInfoCircle />} />
2019-08-07 14:08:45 +09:00
)}
2019-08-06 02:07:05 +09:00
</>
2020-08-31 08:41:53 +09:00
);
};
2019-08-06 01:17:29 +09:00
2020-06-29 12:24:01 +09:00
const AppStoreCard: React.FC<{ query: string }> = ({ query }) => {
2020-08-31 08:41:53 +09:00
const { t } = useTranslation();
2019-08-06 01:17:29 +09:00
return (
<Card title={t('providers.appStore')}>
<Search query={query} />
</Card>
2020-08-31 08:41:53 +09:00
);
};
2019-09-01 01:28:24 +09:00
2020-08-31 08:41:53 +09:00
export default AppStoreCard;