From f609c7492b7f5891672c3b4b17efa10df71f0918 Mon Sep 17 00:00:00 2001 From: nkwtnb Date: Wed, 13 Nov 2024 15:17:31 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=AA=E3=83=9D=E3=82=B8=E3=83=88=E3=83=AA?= =?UTF-8?q?=E6=83=85=E5=A0=B1=E3=82=92=E3=83=8F=E3=83=BC=E3=83=89=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=87=E3=82=A3=E3=83=B3=E3=82=B0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useProductFetcher.ts | 67 +++++++++++++++------------------- 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/src/hooks/useProductFetcher.ts b/src/hooks/useProductFetcher.ts index afe91a3..bfd4823 100644 --- a/src/hooks/useProductFetcher.ts +++ b/src/hooks/useProductFetcher.ts @@ -26,67 +26,57 @@ interface Response { } const sort = (repositories: Repository[]) => { - const sorted = repositories.sort((a: any, b: any) => { - if (a.name.toUpperCase() > b.name.toUpperCase()) return -1 - if (a.name.toUpperCase() < b.name.toUpperCase()) return 1 - return 0; - }) - // ポートフォリオのリポジトリは先頭に表示する - const index = sorted.findIndex(repo => repo.name === "portfolio"); - const portfolio = sorted[index]; - const filtered = sorted.filter(repo => repo.name !== "portfolio"); - filtered.unshift(portfolio); - return filtered; + return repositories + // const sorted = repositories.sort((a: any, b: any) => { + // if (a.name.toUpperCase() > b.name.toUpperCase()) return -1 + // if (a.name.toUpperCase() < b.name.toUpperCase()) return 1 + // return 0; + // }) + // // ポートフォリオのリポジトリは先頭に表示する + // const index = sorted.findIndex(repo => repo.name === "portfolio"); + // const portfolio = sorted[index]; + // const filtered = sorted.filter(repo => repo.name !== "portfolio"); + // filtered.unshift(portfolio); + // return filtered; } // プライベートリポジトリは、APIで取得できないため、個別で記載する -const mergePrivateRepository = (repositories: Repository[]) => { - const privateRepos: Repository[] = [ +const getRepositories = () => { + const repos: Repository[] = [ { name: "kron", description: "kintoneのレコードデータと添付ファイルを自動で毎日CSV出力するWebサービスです。", // homepage: "https://kron.nw-apps.jp/lp", skills: ["ruby", "rails", "tailwindcss", "typescript", "jest", "sendgrid", "cloudrun",], - thumbnail: kron_thumbnail.src, + thumbnail: "https://raw.githubusercontent.com/nkwtnb/xlsx-creator-web/refs/heads/images/thumbnail.png", isPrivate: true } ] - privateRepos.forEach(repo => { - repositories.push(repo) - }) - return repositories + return repos } const repositoryFetcher = async (url: string) => { - const data = await fetch(url).then(r => r.json()); - const repositories = data.items.map((item: GitHubApiResponse): Repository => { - return { - name: item.name, - description: item.description, - svn_url: item.svn_url, - homepage: item.homepage, - skills: item.topics.filter(topic => topic !== "portfolio") // portfolio以外の使用スキルタグを表示 - } - }); - const mergedRepositories = mergePrivateRepository(repositories) + // + const mergedRepositories = getRepositories() return mergedRepositories; } const thumbnailFetcher = async (url: string, repositories: Repository[]) => { + console.log("repos", repositories) if (!repositories) { return; } const thumbnails = await Promise.all(repositories.map(async repo => { - if (repo.isPrivate) return repo - const BRANCHES_URL = `https://api.github.com/repos/nkwtnb/${repo.name}/branches`; - const branches = await fetch(BRANCHES_URL).then(r => r.json()); - const hasImages = branches.some((branch: any) => branch.name === "images"); - if (!hasImages) return repo; - const URL = `https://api.github.com/repos/nkwtnb/${repo.name}/contents/thumbnail.png?ref=images`; - const resp = await fetch(URL).then(r => r.json()); - repo.thumbnail = resp.download_url; + // if (repo.isPrivate) return repo + // const BRANCHES_URL = `https://api.github.com/repos/nkwtnb/${repo.name}/branches`; + // const branches = await fetch(BRANCHES_URL).then(r => r.json()); + // const hasImages = branches.some((branch: any) => branch.name === "images"); + // if (!hasImages) return repo; + // const URL = `https://api.github.com/repos/nkwtnb/${repo.name}/contents/thumbnail.png?ref=images`; + // const resp = await fetch(URL).then(r => r.json()); + // repo.thumbnail = resp.download_url; return repo; })); - + console.log("thub", thumbnails) return thumbnails; } @@ -105,6 +95,7 @@ export const useProductFetcher = (): Response => { if (errorOnThumbnail) return makeResponse(undefined, errorOnThumbnail); if (!thumbnails) return makeResponse(undefined, undefined); const sorted = sort(thumbnails); + console.log(sorted) return { data: sorted, error: errorOnThumbnail,