1
0
mirror of https://github.com/uetchy/namae.git synced 2025-03-17 12:30:32 +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 term = encodeURIComponent(query)
// const country = 'us' const countryCode = country || 'us'
const limit = 3 const limit = 10
try { try {
const response = await fetch( 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' 'GET'
) )
const body = await response.json() const body = await response.json()

View File

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

View File

@ -1,20 +1,22 @@
import React from 'react' import React from 'react'
import useFetch from 'fetch-suspense' import useFetch from 'fetch-suspense'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { FaGithub } from 'react-icons/fa' import { FaGithub, FaInfoCircle } from 'react-icons/fa'
import { Card, Result } from '../Cards' import { Card, Result } from '../Cards'
function Search({ query }) { function Search({ query }) {
const searchQuery = encodeURIComponent(`${query} in:name`) const searchQuery = encodeURIComponent(`${query} in:name`)
const limit = 10
const response = useFetch( 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 const repos = response.items
return ( return (
<> <>
{repos.map((repo) => ( {repos.length > 0 ? (
repos.map((repo) => (
<Result <Result
title={repo.full_name} title={repo.full_name}
message={`Star: ${repo.stargazers_count}`} message={`Star: ${repo.stargazers_count}`}
@ -22,7 +24,10 @@ function Search({ query }) {
icon={<FaGithub />} icon={<FaGithub />}
key={repo.id} key={repo.id}
/> />
))} ))
) : (
<Result title="No Result" icon={<FaInfoCircle />} />
)}
</> </>
) )
} }