-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
show pending state and improve increment progress logic
Signed-off-by: Vu Van Dung <[email protected]>
- Loading branch information
Showing
12 changed files
with
78 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,7 @@ | ||
import { GraphQLClient } from "graphql-request"; | ||
import { env } from "~/env.mjs"; | ||
|
||
export function getClient(token?: string) { | ||
return new GraphQLClient("https://graphql.anilist.co", { | ||
fetch: async (url, init) => { | ||
// Temporary "logging" | ||
try { | ||
if (process.env.DEBUG_WEBHOOK) { | ||
const body: { operationName: string; variables?: object | undefined } = JSON.parse( | ||
String(init?.body), | ||
); | ||
await fetch(process.env.DEBUG_WEBHOOK, { | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
content: ` | ||
Fetching from AniList (${body.operationName}) | ||
\`\`\` | ||
${JSON.stringify(body.variables)} | ||
\`\`\` | ||
`.trim(), | ||
}), | ||
}); | ||
} | ||
} catch {} | ||
return fetch(url, init); | ||
}, | ||
headers: token ? { authorization: `Bearer ${token}` } : undefined, | ||
}); | ||
} |
12 changes: 8 additions & 4 deletions
12
...ib/hooks/use-transition-with-nprogress.ts → src/lib/hooks/use-nprogress.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import nProgress from "nprogress"; | ||
import { useEffect, useTransition } from "react"; | ||
|
||
export function useTransitionWithNProgress() { | ||
const [isPending, startTransition] = useTransition(); | ||
export function useNProgress(enabled: boolean) { | ||
useEffect(() => { | ||
if (isPending) nProgress.start(); | ||
if (enabled) nProgress.start(); | ||
else nProgress.done(); | ||
}, [isPending]); | ||
}, [enabled]); | ||
} | ||
|
||
export function useTransitionWithNProgress() { | ||
const [isPending, startTransition] = useTransition(); | ||
useNProgress(isPending); | ||
return startTransition; | ||
} |