1
0
mirror of https://github.com/uetchy/namae.git synced 2025-07-06 16:05:59 +09:00
namae/web/src/components/cards/appstore.js

44 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-08-06 01:17:29 +09:00
import React from 'react'
import useFetch from 'fetch-suspense'
import { useTranslation } from 'react-i18next'
2019-08-07 14:08:45 +09:00
import { FaAppStore, FaInfoCircle } from 'react-icons/fa'
2019-08-06 01:17:29 +09:00
import { Card, Result } from '../Cards'
function Search({ query }) {
const { t } = useTranslation()
2019-08-06 01:17:29 +09:00
const term = encodeURIComponent(query)
const response = useFetch(
`/availability/appstore/${term}?country=${t('countryCode')}`
)
2019-08-06 01:17:29 +09:00
const apps = response.result
return (
2019-08-06 02:07:05 +09:00
<>
2019-08-07 14:08:45 +09:00
{apps.length > 0 ? (
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}
icon={<FaAppStore />}
key={app.id}
/>
))
) : (
<Result title="No Result" icon={<FaInfoCircle />} />
)}
2019-08-06 02:07:05 +09:00
</>
2019-08-06 01:17:29 +09:00
)
}
export default function AppStoreCard({ query }) {
const { t } = useTranslation()
return (
<Card title={t('providers.appStore')}>
<Search query={query} />
</Card>
)
}