1
0
mirror of https://github.com/uetchy/namae.git synced 2025-03-17 04:30:31 +09:00

fix: limit 10 items

This commit is contained in:
uetchy 2019-08-07 14:08:45 +09:00
parent 1031a70b0f
commit d480d14100
3 changed files with 33 additions and 24 deletions

View File

@ -8,12 +8,12 @@ module.exports = async (req, res) => {
}
const term = encodeURIComponent(query)
// const country = 'us'
const limit = 3
const countryCode = country || 'us'
const limit = 10
try {
const response = await fetch(
`https://itunes.apple.com/search?media=software&entity=software,iPadSoftware,macSoftware&country=${country}&limit=${limit}&term=${term}`,
`https://itunes.apple.com/search?media=software&entity=software,iPadSoftware,macSoftware&country=${countryCode}&limit=${limit}&term=${term}`,
'GET'
)
const body = await response.json()

View File

@ -1,7 +1,7 @@
import React from 'react'
import useFetch from 'fetch-suspense'
import { useTranslation } from 'react-i18next'
import { FaAppStore } from 'react-icons/fa'
import { FaAppStore, FaInfoCircle } from 'react-icons/fa'
import { Card, Result } from '../Cards'
@ -15,15 +15,19 @@ function Search({ query }) {
return (
<>
{apps.map((app) => (
<Result
title={app.name}
message={`Price: ${app.price}`}
link={app.viewURL}
icon={<FaAppStore />}
key={app.id}
/>
))}
{apps.length > 0 ? (
apps.map((app) => (
<Result
title={app.name}
message={`Price: ${app.price}`}
link={app.viewURL}
icon={<FaAppStore />}
key={app.id}
/>
))
) : (
<Result title="No Result" icon={<FaInfoCircle />} />
)}
</>
)
}

View File

@ -1,28 +1,33 @@
import React from 'react'
import useFetch from 'fetch-suspense'
import { useTranslation } from 'react-i18next'
import { FaGithub } from 'react-icons/fa'
import { FaGithub, FaInfoCircle } from 'react-icons/fa'
import { Card, Result } from '../Cards'
function Search({ query }) {
const searchQuery = encodeURIComponent(`${query} in:name`)
const limit = 10
const response = useFetch(
`https://api.github.com/search/repositories?q=${searchQuery}&per_page=3`
`https://api.github.com/search/repositories?q=${searchQuery}&per_page=${limit}`
)
const repos = response.items
return (
<>
{repos.map((repo) => (
<Result
title={repo.full_name}
message={`Star: ${repo.stargazers_count}`}
link={repo.html_url}
icon={<FaGithub />}
key={repo.id}
/>
))}
{repos.length > 0 ? (
repos.map((repo) => (
<Result
title={repo.full_name}
message={`Star: ${repo.stargazers_count}`}
link={repo.html_url}
icon={<FaGithub />}
key={repo.id}
/>
))
) : (
<Result title="No Result" icon={<FaInfoCircle />} />
)}
</>
)
}