From 2997f3c0cac0208fbf8ed9759bbdcbd199014548 Mon Sep 17 00:00:00 2001 From: Igor Kowalczyk Date: Thu, 2 Jan 2025 19:09:12 +0100 Subject: [PATCH] Refactor GraphQL types and remove unused getPopular function --- config.tsx | 32 +--- lib/graphql/index.ts | 2 - lib/graphql/src/getOGImage.ts | 48 +++--- lib/graphql/src/getPopular.ts | 89 ----------- lib/graphql/src/getRepos.ts | 139 ------------------ .../src/getTotalContributionsForYear.ts | 24 ++- lib/graphql/src/getTotalYears.ts | 14 +- lib/graphql/src/getUserData.ts | 55 +++---- lib/types.ts | 73 +++++++++ 9 files changed, 134 insertions(+), 342 deletions(-) delete mode 100644 lib/graphql/src/getPopular.ts delete mode 100644 lib/graphql/src/getRepos.ts create mode 100644 lib/types.ts diff --git a/config.tsx b/config.tsx index 22a2cf56e..6a45ff76e 100644 --- a/config.tsx +++ b/config.tsx @@ -1,3 +1,5 @@ +import { Contact, Header, Meta, Project, Technology } from "./lib/types"; + export const meta = { title: "Igor Kowalczyk", description: "Iā€™m a full-stack developer based in Poland šŸ‡µšŸ‡±. I have a passion for building web applications and solving problems.", @@ -21,35 +23,13 @@ export const meta = { username: "majonezexe", }, }, -}; +} satisfies Meta; export const header = { title: "Igor Kowalczyk", subtitle: "Full-stack developer", description: meta.description, - code: { - user: "igorkowalczyk", - }, -}; - -export type Project = { - name: string; - started?: string; - ended?: string; - description: string; - images: { - src: string; - alt: string; - width: number; - height: number; - }[]; - technologies: { - name: string; - icon: string; - }[]; - website: string | null; - github: string | null; -}; +} satisfies Header; export const projects = [ { @@ -299,7 +279,7 @@ export const contact = { ), }, ], -}; +} satisfies Contact; export const footer = { categories: [ @@ -485,4 +465,4 @@ export const technologies = [ icon: "/assets/tech/eslint.svg", link: "https://eslint.org/", }, -]; +] satisfies Technology[]; diff --git a/lib/graphql/index.ts b/lib/graphql/index.ts index a83f40b0d..2c50c1ab5 100644 --- a/lib/graphql/index.ts +++ b/lib/graphql/index.ts @@ -1,8 +1,6 @@ import "server-only"; export * from "./src/getOGImage"; -export * from "./src/getPopular"; -export * from "./src/getRepos"; export * from "./src/getTotalContributionsForYear"; export * from "./src/getTotalContributionsForYears"; export * from "./src/getTotalYears"; diff --git a/lib/graphql/src/getOGImage.ts b/lib/graphql/src/getOGImage.ts index 037c00510..8a67368fe 100644 --- a/lib/graphql/src/getOGImage.ts +++ b/lib/graphql/src/getOGImage.ts @@ -1,39 +1,27 @@ import { meta } from "@/config"; import { requestGraphql } from "@/lib/graphql/src/requestGraphql"; - -interface Language { - size: number; - node: { - color: string; - name: string; - }; -} - -interface Repository { - openGraphImageUrl: string; - isPrivate: boolean; - description: string; - languages: { - edges: Language[]; - totalSize: number; - }; - owner: { - avatarUrl: string; - name: string; - }; - stargazerCount: number; -} +import { Language } from "@/lib/types"; interface GraphqlResponse { data: { - repository: Repository | null; + repository: { + openGraphImageUrl: string; + isPrivate: boolean; + description: string; + languages: { + edges: Language[]; + totalSize: number; + }; + owner: { + avatarUrl: string; + name: string; + }; + stargazerCount: number; + } | null; }; } -export async function GetOGImage( - repo: string, - owner: string -): Promise { +} + +export async function GetOGImage(repo: string, owner: string): Promise { if (!repo || !owner) return null; if (owner !== meta.accounts.github.username) return null; diff --git a/lib/graphql/src/getPopular.ts b/lib/graphql/src/getPopular.ts deleted file mode 100644 index bf57f5857..000000000 --- a/lib/graphql/src/getPopular.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { meta } from "@/config"; -import { requestGraphql } from "@/lib/graphql/src/requestGraphql"; -import { stripTypenames } from "@/lib/utils"; - -interface Language { - name: string; - color: string; -} - -interface RepositoryNode { - name: string; - url: string; - owner: { - login: string; - }; - description: string; - isArchived: boolean; - forkCount: number; - id: string; - homepageUrl: string; - stargazerCount: number; - primaryLanguage: Language | null; -} - -interface RepositoryEdge { - node: RepositoryNode; -} - -interface Repositories { - edges: RepositoryEdge[]; -} - -interface User { - repositories: Repositories; -} - -interface GraphqlResponse { - data: { - user: User | null; - }; -} - -export async function GetPopular(): Promise { - const { data }: GraphqlResponse = await requestGraphql( - ` - query($username: String!) { - user(login: $username) { - repositories( - isFork: false - isLocked: false - privacy: PUBLIC - first: 2 - orderBy: {field: STARGAZERS, direction: DESC} - ownerAffiliations: OWNER - ) { - edges { - node { - ... on Repository { - name - url - owner { - login - } - description - isArchived - forkCount - id - homepageUrl - stargazerCount - primaryLanguage { - name - color - } - } - } - } - } - } - } - `, - { - username: meta.accounts.github.username, - } - ); - - if (!data || !data.user) return null; - - return stripTypenames(data.user); -} diff --git a/lib/graphql/src/getRepos.ts b/lib/graphql/src/getRepos.ts deleted file mode 100644 index b62833667..000000000 --- a/lib/graphql/src/getRepos.ts +++ /dev/null @@ -1,139 +0,0 @@ -import { meta } from "@/config"; -import { requestGraphql } from "@/lib/graphql/src/requestGraphql"; -import { stripTypenames } from "@/lib/utils"; - -interface Topic { - name: string; -} - -interface RepositoryTopic { - node: { - topic: Topic; - }; -} - -interface Language { - name: string; - color: string; -} - -interface RepositoryNode { - name: string; - id: string; - url: string; - owner: { - login: string; - }; - description: string; - isArchived: boolean; - forkCount: number; - repositoryTopics: { - edges: RepositoryTopic[]; - }; - homepageUrl: string; - stargazerCount: number; - primaryLanguage: Language | null; -} - -interface RepositoryEdge { - node: RepositoryNode; -} - -interface Repositories { - totalCount: number; - edges: RepositoryEdge[]; -} - -interface User { - repositories: Repositories; -} - -interface GraphqlResponse { - data: { - user: User | null; - }; -} - -export async function GetRepos(type: string, count: number): Promise { - if (type.toUpperCase() === "PRIVATE") { - const { data }: GraphqlResponse = await requestGraphql( - ` - query($username: String!, $count: Int!) { - user(login: $username) { - repositories( - first: $count - isFork: false - isLocked: false - privacy: PRIVATE - orderBy: {field: STARGAZERS, direction: DESC} - ownerAffiliations: OWNER - ) { - totalCount - } - } - } - `, - { - username: meta.accounts.github.username, - count: parseInt(count.toString()), - } - ); - - return stripTypenames(data); - } else { - const { data }: GraphqlResponse = await requestGraphql( - ` - query($username: String!, $count: Int!, $type: RepositoryPrivacy!) { - user(login: $username) { - repositories( - first: $count - isFork: false - isLocked: false - privacy: $type - orderBy: { field: STARGAZERS, direction: DESC } - ownerAffiliations: OWNER - ) { - totalCount - edges { - node { - ... on Repository { - name - id - url - owner { - login - } - description - isArchived - forkCount - repositoryTopics(first: 4) { - edges { - node { - topic { - name - } - } - } - } - homepageUrl - stargazerCount - primaryLanguage { - name - color - } - } - } - } - } - } - } - `, - { - username: meta.accounts.github.username, - count: parseInt(count.toString()), - type: type.toString().toUpperCase(), - } - ); - return stripTypenames(data); - } -} diff --git a/lib/graphql/src/getTotalContributionsForYear.ts b/lib/graphql/src/getTotalContributionsForYear.ts index 1620d24fb..af31b5823 100644 --- a/lib/graphql/src/getTotalContributionsForYear.ts +++ b/lib/graphql/src/getTotalContributionsForYear.ts @@ -1,21 +1,15 @@ import { meta } from "@/config"; import { requestGraphql } from "@/lib/graphql/src/requestGraphql"; -interface ContributionCalendar { - totalContributions: number; -} - -interface ContributionsCollection { - contributionCalendar: ContributionCalendar; -} - -interface User { - contributionsCollection: ContributionsCollection; -} - interface GraphqlResponse { data: { - user: User | null; + user: { + contributionsCollection: { + contributionCalendar: { + totalContributions: number; + }; + } | null; + }; }; } @@ -42,5 +36,7 @@ export async function getTotalContributionsForYear(year: number): Promise sum + node.stargazerCount, 0); diff --git a/lib/types.ts b/lib/types.ts new file mode 100644 index 000000000..162ce25c1 --- /dev/null +++ b/lib/types.ts @@ -0,0 +1,73 @@ +import { JSX } from "react"; + +export interface Language { + size: number; + node: { + color: string; + name: string; + }; +} + +export type Project = { + name: string; + started?: string; + ended?: string; + description: string; + images: { + src: string; + alt: string; + width: number; + height: number; + }[]; + technologies: { + name: string; + icon: string; + }[]; + website: string | null; + github: string | null; +}; + +export type Header = { + title: string; + subtitle: string; + description: string; +}; + +export type Contact = { + links: { + href: string; + title: string; + icon: JSX.Element; + }[]; +}; + +export type Technology = { + name: string; + icon: string; + class?: string; + link?: string; +}; + +export type Meta = { + title: string; + description: string; + shortDescription: string; + url: string; + accounts: { + github: { + username: string; + repo: string; + }; + twitter?: { + username: string; + }; + discord?: { + username: string; + invite?: string; + id: string; + }; + instagram?: { + username: string; + }; + }; +};