From 04d11584bf8d2650011f71d987b8fbc2888793c8 Mon Sep 17 00:00:00 2001 From: Jerry Hogan Date: Thu, 17 Nov 2022 16:46:22 +0100 Subject: [PATCH] [solidjs-pod] Get all repositories from GitHub API#684 (#845) * in progress * chore: get all repos api * [Angular - NgRx - SCSS] 440: state & service refactor (#527) * setup: get branch caught up and ready for work * feat: refactored repository service and test * feat: refactor of user service and test * feat: updated user service spec * feat: created dashboard store files; updated global state files; renamed RepoState and updated all calls * attempt to fix issues with service updates; some refactoring and adjusting so app compiles * feat: added auth user data to auth state; updated nav component to use auth state * feat: adjusted auth call; fixed user call so home page loads * moved some user logic; still having reload issues and repo view issues * feat: got app working again! cleaned out console logs * rebased and fixed most files * fix broken tests * removed unused code * fix: fix pr comments and most tests * fix: fixed final broken unit test * fix: updated test; removed unused code in user effect; new user mapping file * add todo for refactor improvements; update authUser effect to use different rxjs operation Co-authored-by: LindaT * feat(solidjs) - Create navigation header (#840) * fix(angular-apollo-tailwind): append protocol if missing from user url (#637) * fix(angular-apollo-tailwind): append protocol if missing from user url Refs: #591 * test(angular-apollo-tailwind): update with testcases Closes: #591 * chore: repo card with story and test (#737) * chore: repo card with story and test * fix comments * fix coment Co-authored-by: Victor Chukwuebuka Umeh <41862157+vyktoremario@users.noreply.github.com> * chore: gist panel UI (#741) * chore: gist panel UI * fix coment * fix coment Co-authored-by: Victor Chukwuebuka Umeh <41862157+vyktoremario@users.noreply.github.com> * [solidjs-pod] : Create component for search input and filter sort buttons (#831) * in progress * in progress * in progress, paused for now * chore: search filter sort component * fixed comments on icons * [solidjs-tailwinf] Add user profile card (#830) * [SolidJS-Tailwind] Implement authentication (#734) * chore(solidjs): remove example components * feat(solidjs): add signin page * refactor(solidjs): improve auth setup * feat(solidjs): pencil in auth flow * feat(solidjs): add example github communication * [Angular - NgRx - SCSS] 440: state & service refactor (#527) * setup: get branch caught up and ready for work * feat: refactored repository service and test * feat: refactor of user service and test * feat: updated user service spec * feat: created dashboard store files; updated global state files; renamed RepoState and updated all calls * attempt to fix issues with service updates; some refactoring and adjusting so app compiles * feat: added auth user data to auth state; updated nav component to use auth state * feat: adjusted auth call; fixed user call so home page loads * moved some user logic; still having reload issues and repo view issues * feat: got app working again! cleaned out console logs * rebased and fixed most files * fix broken tests * removed unused code * fix: fix pr comments and most tests * fix: fixed final broken unit test * fix: updated test; removed unused code in user effect; new user mapping file * add todo for refactor improvements; update authUser effect to use different rxjs operation Co-authored-by: LindaT * feat(solidjs) - Create navigation header (#840) * fix(angular-apollo-tailwind): append protocol if missing from user url (#637) * fix(angular-apollo-tailwind): append protocol if missing from user url Refs: #591 * test(angular-apollo-tailwind): update with testcases Closes: #591 * chore: repo card with story and test (#737) * chore: repo card with story and test * fix comments * fix coment Co-authored-by: Victor Chukwuebuka Umeh <41862157+vyktoremario@users.noreply.github.com> * chore: gist panel UI (#741) * chore: gist panel UI * fix coment * fix coment Co-authored-by: Victor Chukwuebuka Umeh <41862157+vyktoremario@users.noreply.github.com> * chore(solidjs): remove example components * fixed comments, clean ups Co-authored-by: Linda Thompson Co-authored-by: LindaT Co-authored-by: Daian Scuarissi Co-authored-by: Oluwakorede Cole Co-authored-by: Jerry Hogan Co-authored-by: Victor Chukwuebuka Umeh <41862157+vyktoremario@users.noreply.github.com> * chore: updated amplify.yml file (#729) * chore: updated amplify.yml file * changed pnpm to npm * chore: workflow added (#745) * chore: workflow added * CI setup fixes and testing * CI setup fixes and testing * CI setup fixes and testing * tried everything but doesn't work, i think we have to merge this * auth token added to header * ..updates * ..updates * auth token added to header * fix file issues * CI adjustments * CI adjustments Co-authored-by: Linda Thompson Co-authored-by: LindaT Co-authored-by: Daian Scuarissi Co-authored-by: Oluwakorede Cole Co-authored-by: Victor Chukwuebuka Umeh <41862157+vyktoremario@users.noreply.github.com> Co-authored-by: Maarten Bicknese --- .github/workflows/ci-solidjs-tailwind.yml | 6 ++ .../src/components/Icons/index.js | 4 ++ .../components/RepoFilter/FilterDropdown.jsx | 2 +- .../src/components/RepoFilter/FilterText.jsx | 2 +- .../src/components/RepoFilter/RepoFilter.jsx | 2 +- .../src/components/icons/index.js | 1 + solidjs-tailwind/src/services/api.js | 25 +++++++++ .../src/services/queries/all-repos.js | 55 +++++++++++++++++++ solidjs-tailwind/src/services/user-repos.js | 52 ++++++++++++++++++ 9 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 solidjs-tailwind/src/services/api.js create mode 100644 solidjs-tailwind/src/services/queries/all-repos.js create mode 100644 solidjs-tailwind/src/services/user-repos.js diff --git a/.github/workflows/ci-solidjs-tailwind.yml b/.github/workflows/ci-solidjs-tailwind.yml index b55d1cdfe..357a34a48 100644 --- a/.github/workflows/ci-solidjs-tailwind.yml +++ b/.github/workflows/ci-solidjs-tailwind.yml @@ -21,11 +21,13 @@ jobs: steps: - uses: actions/checkout@v2 + uses: pnpm/action-setup@v2.2.4 with: fetch-depth: 0 - name: Use Node.js uses: actions/setup-node@v2 + uses: pnpm/action-setup@v2.2.4 with: node-version: ${{ matrix.node-version }} cache: 'pnpm' @@ -45,11 +47,13 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 + uses: pnpm/action-setup@v2.2.4 with: fetch-depth: 0 - name: Use Node.js uses: actions/setup-node@v2 + uses: pnpm/action-setup@v2.2.4 with: node-version: ${{ matrix.node-version }} cache: "pnpm" @@ -75,11 +79,13 @@ jobs: steps: - uses: actions/checkout@v2 + uses: pnpm/action-setup@v2.2.4 with: fetch-depth: 0 - name: Use Node.js uses: actions/setup-node@v2 + uses: pnpm/action-setup@v2.2.4 with: node-version: ${{ matrix.node-version }} cache: "pnpm" diff --git a/solidjs-tailwind/src/components/Icons/index.js b/solidjs-tailwind/src/components/Icons/index.js index 93e73e0cc..c8291f64f 100644 --- a/solidjs-tailwind/src/components/Icons/index.js +++ b/solidjs-tailwind/src/components/Icons/index.js @@ -1 +1,5 @@ export { default as TwitterIcon } from './TwitterIcon'; +export { default as CaretIcon } from './caret'; +export { default as CloseIcon } from './close'; +export { default as CorrectIcon } from './correct'; +export { default as RepoBookIcon } from './repo-book'; diff --git a/solidjs-tailwind/src/components/RepoFilter/FilterDropdown.jsx b/solidjs-tailwind/src/components/RepoFilter/FilterDropdown.jsx index e59c6a948..c776915c9 100644 --- a/solidjs-tailwind/src/components/RepoFilter/FilterDropdown.jsx +++ b/solidjs-tailwind/src/components/RepoFilter/FilterDropdown.jsx @@ -7,7 +7,7 @@ import { Switch, Match, } from 'solid-js'; -import { CaretIcon, CloseIcon, CorrectIcon } from '../icons'; +import { CaretIcon, CloseIcon, CorrectIcon } from '../Icons'; function clickOutside(el, accessor) { const onClick = (e) => { diff --git a/solidjs-tailwind/src/components/RepoFilter/FilterText.jsx b/solidjs-tailwind/src/components/RepoFilter/FilterText.jsx index 7f26730e1..2261f49ad 100644 --- a/solidjs-tailwind/src/components/RepoFilter/FilterText.jsx +++ b/solidjs-tailwind/src/components/RepoFilter/FilterText.jsx @@ -1,5 +1,5 @@ import { Show, splitProps } from 'solid-js'; -import { CloseIcon } from '../icons'; +import { CloseIcon } from '../Icons'; const modifyFilterTypeText = (filterText = 'test') => { if (filterText.endsWith('s')) { diff --git a/solidjs-tailwind/src/components/RepoFilter/RepoFilter.jsx b/solidjs-tailwind/src/components/RepoFilter/RepoFilter.jsx index c977f8a5b..7db66b8b9 100644 --- a/solidjs-tailwind/src/components/RepoFilter/RepoFilter.jsx +++ b/solidjs-tailwind/src/components/RepoFilter/RepoFilter.jsx @@ -1,5 +1,5 @@ import { mergeProps, Show } from 'solid-js'; -import { RepoBookIcon } from '../icons'; +import { RepoBookIcon } from '../Icons'; import { FILTER_TYPE_OPTIONS, SORT_OPTIONS } from './data'; import FilterDropdown from './FilterDropdown'; import FilterText from './FilterText'; diff --git a/solidjs-tailwind/src/components/icons/index.js b/solidjs-tailwind/src/components/icons/index.js index e00402d99..c8291f64f 100644 --- a/solidjs-tailwind/src/components/icons/index.js +++ b/solidjs-tailwind/src/components/icons/index.js @@ -1,3 +1,4 @@ +export { default as TwitterIcon } from './TwitterIcon'; export { default as CaretIcon } from './caret'; export { default as CloseIcon } from './close'; export { default as CorrectIcon } from './correct'; diff --git a/solidjs-tailwind/src/services/api.js b/solidjs-tailwind/src/services/api.js new file mode 100644 index 000000000..f625fae29 --- /dev/null +++ b/solidjs-tailwind/src/services/api.js @@ -0,0 +1,25 @@ +const FetchApi = ({ url, query, variables, headersOptions }) => { + return new Promise((resolve, reject) => { + fetch(url, { + method: 'POST', + headers: { + ...headersOptions, + Accept: 'application/vnd.github+json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + query, + variables, + }), + }) + .then((res) => res.json()) + .then((result) => { + resolve(result); + }) + .catch((error) => { + reject(error); + }); + }); +}; + +export default FetchApi; diff --git a/solidjs-tailwind/src/services/queries/all-repos.js b/solidjs-tailwind/src/services/queries/all-repos.js new file mode 100644 index 000000000..697509912 --- /dev/null +++ b/solidjs-tailwind/src/services/queries/all-repos.js @@ -0,0 +1,55 @@ +export const USER_REPOS_QUERY = ` + query UserRepos( + $username: String! + $afterCursor: String + $beforeCursor: String + $orderBy: RepositoryOrder + $first: Int + $last: Int + ) { + owner: user(login: $username) { + repositories( + first: $first + last: $last + after: $afterCursor + before: $beforeCursor + orderBy: $orderBy + ownerAffiliations: [OWNER] + ) { + nodes { + id + name + description + stargazerCount + forkCount + isArchived + isFork + primaryLanguage { + id + color + name + } + languages(first: 10, orderBy: { direction: ASC, field: SIZE }) { + nodes { + color + name + id + } + } + isPrivate + visibility + updatedAt + owner { + login + } + } + pageInfo { + endCursor + startCursor + hasNextPage + hasPreviousPage + } + } + } + } +`; diff --git a/solidjs-tailwind/src/services/user-repos.js b/solidjs-tailwind/src/services/user-repos.js new file mode 100644 index 000000000..7e488ae57 --- /dev/null +++ b/solidjs-tailwind/src/services/user-repos.js @@ -0,0 +1,52 @@ +import { useAuth } from "../auth"; +import FetchApi from "./api"; +import { USER_REPOS_QUERY } from "./queries/all-repos"; + +const getUserRepos = async ({ + url +}) => { + const { authStore } = useAuth(); + const data = { + url, + query: USER_REPOS_QUERY, + variable: null, + headersOptions: { + authorization: `Bearer ${authStore.token}`, + } + } + const resp = await FetchApi(data); + const nodes = resp?.owner?.repositories?.nodes; + const pageInfo = resp?.owner?.repositories?.pageInfo; + + if (!nodes) { + return undefined; + } + const repos = nodes?.reduce((acc, repo) => { + return repo + ? [ + ...acc, + { + id: repo.id, + name: repo.name, + description: repo.description, + stargazerCount: repo.stargazerCount, + forkCount: repo.forkCount, + primaryLanguage: { + name: repo.primaryLanguage?.name, + color: repo.primaryLanguage?.color, + }, + visibility: repo.visibility, + updatedAt: repo.updatedAt, + owner: repo.owner, + }, + ] + : acc; + }, []); + + return { + pageInfo, + repos + }; +}; + +export default getUserRepos;