Skip to content

Commit

Permalink
refactor: 💡 handle edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
chauduong1192 committed Dec 6, 2024
1 parent 1613f22 commit 5f521fe
Show file tree
Hide file tree
Showing 13 changed files with 849 additions and 22 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-popover": "^1.1.2",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-toast": "^1.2.2",
"@tanstack/react-query": "^5.61.5",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
Expand Down
92 changes: 86 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/app/api/[...route]/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StatusCodes } from 'http-status-codes';
import { Env } from '@/app/api/configs/env';
import { formatResponse } from '@/app/api/helpers/response';

import { GithubCommit } from '@/types';
import { GithubBranch, GithubCommit } from '@/types';

const { GITHUB_URL, GITHUB_USERNAME, GITHUB_TOKEN, GENIMI_API_KEY } = Env;
const genAI = new GoogleGenerativeAI(GENIMI_API_KEY as string);
Expand Down Expand Up @@ -54,8 +54,16 @@ const githubApi = new Hono()
},
);
const newResponse = await response.json();
const formatRes = newResponse.filter((branch: GithubBranch) =>
branch.name.startsWith('chaud/'),
);
if (formatRes.length === 0) {
throw new Error(
'No branches found. Please try again with different repo.',
);
}
return formatResponse(c, StatusCodes.OK, {
data: newResponse,
data: formatRes,
});
} catch (error) {
throw error;
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import '@/styles/mdx.css';
import { CoreLayout } from '@/components/CoreLayout';

import Providers from '@/app/providers';
import { Toaster } from '@/components/ui/toaster';
import { siteConfig } from '@/constant/config';

const robotoMono = localFont({
Expand Down Expand Up @@ -99,6 +100,7 @@ export default function RootLayout({
className={`${robotoMono.variable} ${rubik.variable}`}
>
<body>
<Toaster />
<Providers>
<CoreLayout>{children}</CoreLayout>
</Providers>
Expand Down
19 changes: 17 additions & 2 deletions src/app/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
'use client';

import { QueryClientProvider } from '@tanstack/react-query';
import { QueryCache, QueryClientProvider } from '@tanstack/react-query';

Check warning on line 3 in src/app/providers.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint, ʦ TypeScript, 💅 Prettier, and 🃏 Test

Run autofix to sort these imports!

import { useToast } from '@/hooks/use-toast';
import { getQueryClient } from '@/lib/react-query/query-client';

export default function Providers({ children }: { children: React.ReactNode }) {
// NOTE: Avoid useState when initializing the query client if you don't
// have a suspense boundary between this and the code that may
// suspend because React will throw away the client on the initial
// render if it suspends and there is no boundary
const queryClient = getQueryClient();

const { toast } = useToast();

const queryClient = getQueryClient({
queryCache: new QueryCache({
onError: (error) => {
// eslint-disable-next-line no-console
console.error(error);
toast({
description: error.message,
variant: 'error',
});
},
}),
});

return (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
Expand Down
6 changes: 3 additions & 3 deletions src/app/shorts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export default async function ShortsPage() {
return (
<Container subTitle='Showcase of my shorts'>
<HeadingSection
headingText='Github repositories'
title='My open-source projects'
description="Here's a list of my open-source projects hosted on GitHub."
headingText='Welcome to my shorts'
title='Shorts'
description="Here's a collection of my shorts. Shorts are small projects that I've worked on."
withHr={true}
className='gap-0'
>
Expand Down
13 changes: 5 additions & 8 deletions src/components/GenerateDaily/GenerateDaily.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,22 @@ export const GenerateDaily = ({ repos }: GenerateDailyProps) => {
const [isVerified, setVerified] = useState<boolean>(false);

const { data: branchesQuery, isLoading: branchesLoading } = useQuery({
queryKey: ['branches', repoSelected],
queryKey: ['get-branches', repoSelected],
queryFn: () => getBranches(repoSelected),
enabled: !!repoSelected,
retry: false,
});

const { data: commitsQuery, isLoading: commitsLoading } = useQuery({
queryKey: [
'commits',
dateSelected?.toISOString(),
repoSelected,
branchSelected,
],
queryKey: ['get-commits', branchSelected, dateSelected?.toISOString()],
queryFn: async () =>
getCommitsByBranch({
full_name: repoSelected,
sha: branchSelected,
until: dateSelected?.toISOString() ?? '',
}),
enabled: !!branchSelected,
enabled: !!repoSelected && !!branchSelected && !!dateSelected,
retry: false,
});

const [copy] = useCopyToClipboard();
Expand Down
Loading

1 comment on commit 5f521fe

@vercel
Copy link

@vercel vercel bot commented on 5f521fe Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.