Skip to content

Commit

Permalink
fix: use positional arguments for suspense fetcher arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Jan 24, 2024
1 parent 6a8dcee commit 703f2f6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 45 deletions.
26 changes: 18 additions & 8 deletions packages/slice-machine/src/features/git/useGitRepos.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { useRequest } from "@prismicio/editor-support/Suspense";
import { managerClient } from "@src/managerClient";

type UseGitReposArgs = Parameters<typeof managerClient.git.fetchRepos>[0];

const getGitRepos = async (args?: UseGitReposArgs) => {
if (!args) {
async function getGitRepos(
provider?: "gitHub",
owner?: string,
query?: string,
page?: number,
) {
if (provider === undefined || owner === undefined) {
return;
}

return await managerClient.git.fetchRepos(args);
};
return await managerClient.git.fetchRepos({ provider, owner, query, page });
}

export const useGitRepos = (args?: UseGitReposArgs) => {
return useRequest(getGitRepos, [args]);
export const useGitRepos = (
args?: Parameters<typeof managerClient.git.fetchRepos>[0],
) => {
return useRequest(getGitRepos, [
args?.provider,
args?.owner,
args?.query,
args?.page,
]);
};
31 changes: 21 additions & 10 deletions packages/slice-machine/src/features/git/useHasWriteAPIToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,33 @@ import { useRequest } from "@prismicio/editor-support/Suspense";
import { useSliceMachineConfig } from "@src/hooks/useSliceMachineConfig";
import { managerClient } from "@src/managerClient";

import { GitRepoSpecifier, PrismicRepoSpecifier } from "./types";
import { GitRepoSpecifier } from "./types";

export const getHasWriteAPIToken = async (args: {
prismic: PrismicRepoSpecifier;
git: GitRepoSpecifier;
}): Promise<boolean> => {
return await managerClient.git.checkHasWriteAPIToken(args);
export const getHasWriteAPIToken = async (
prismicDomain: string,
gitProvider: "gitHub",
gitOwner: string,
gitName: string,
): Promise<boolean> => {
return await managerClient.git.checkHasWriteAPIToken({
prismic: {
domain: prismicDomain,
},
git: {
provider: gitProvider,
owner: gitOwner,
name: gitName,
},
});
};

export const useHasWriteAPIToken = (args: { git: GitRepoSpecifier }) => {
const [config] = useSliceMachineConfig();

return useRequest(getHasWriteAPIToken, [
{
prismic: { domain: config.repositoryName },
git: args.git,
},
config.repositoryName,
args.git.provider,
args.git.owner,
args.git.name,
]);
};
16 changes: 7 additions & 9 deletions packages/slice-machine/src/features/git/useLinkedGitRepos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { useRequest } from "@prismicio/editor-support/Suspense";
import { useSliceMachineConfig } from "@src/hooks/useSliceMachineConfig";
import { managerClient } from "@src/managerClient";

import { PrismicRepoSpecifier } from "./types";

type UseLinkedGitReposReturnType =
| {
repos: Awaited<
Expand All @@ -12,11 +10,13 @@ type UseLinkedGitReposReturnType =
}
| { error: unknown };

export const getLinkedGitRepos = async (args: {
prismic: PrismicRepoSpecifier;
}): Promise<UseLinkedGitReposReturnType> => {
export const getLinkedGitRepos = async (
prismicDomain: string,
): Promise<UseLinkedGitReposReturnType> => {
try {
const repos = await managerClient.git.fetchLinkedRepos(args);
const repos = await managerClient.git.fetchLinkedRepos({
prismic: { domain: prismicDomain },
});

return { repos };
} catch (error) {
Expand All @@ -27,7 +27,5 @@ export const getLinkedGitRepos = async (args: {
export const useLinkedGitRepos = () => {
const [config] = useSliceMachineConfig();

return useRequest(getLinkedGitRepos, [
{ prismic: { domain: config.repositoryName } },
]);
return useRequest(getLinkedGitRepos, [config.repositoryName]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,20 @@ export const useLinkedGitReposActions = () => {
git,
});

revalidateData(getLinkedGitRepos, [
{ prismic: { domain: config.repositoryName } },
]);
revalidateData(getLinkedGitRepos, [config.repositoryName]);
},
unlinkRepo: async (git: GitRepoSpecifier) => {
await managerClient.git.unlinkRepo({
prismic: { domain: config.repositoryName },
git,
});

revalidateData(getLinkedGitRepos, [
{ prismic: { domain: config.repositoryName } },
]);
revalidateData(getLinkedGitRepos, [config.repositoryName]);
revalidateData(getHasWriteAPIToken, [
{
prismic: { domain: config.repositoryName },
git,
},
config.repositoryName,
git.provider,
git.owner,
git.name,
]);
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export const useWriteAPITokenActions = (args: { git: GitRepoSpecifier }) => {
});

revalidateData(getHasWriteAPIToken, [
{
prismic: { domain: config.repositoryName },
git: args.git,
},
config.repositoryName,
args.git.provider,
args.git.owner,
args.git.name,
]);
},
deleteToken: async () => {
Expand All @@ -30,10 +30,10 @@ export const useWriteAPITokenActions = (args: { git: GitRepoSpecifier }) => {
});

revalidateData(getHasWriteAPIToken, [
{
prismic: { domain: config.repositoryName },
git: args.git,
},
config.repositoryName,
args.git.provider,
args.git.owner,
args.git.name,
]);
},
};
Expand Down

0 comments on commit 703f2f6

Please sign in to comment.