Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Krish120003/dash
Browse files Browse the repository at this point in the history
  • Loading branch information
Krish120003 committed Sep 17, 2023
2 parents 40902d5 + 5cd91b6 commit 505a30c
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 47 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@radix-ui/react-dialog": "^1.0.4",
"@radix-ui/react-dropdown-menu": "^2.0.5",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-popover": "^1.0.6",
"@radix-ui/react-select": "^1.2.2",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-toast": "^1.1.4",
Expand All @@ -29,7 +30,6 @@
"@trpc/server": "^10.37.1",
"@types/react-grid-layout": "^1.3.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"cohere-ai": "^6.2.2",
"googleapis": "105",
"lucide-react": "^0.279.0",
Expand Down
41 changes: 38 additions & 3 deletions pnpm-lock.yaml

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

41 changes: 41 additions & 0 deletions src/components/GDocsCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { api } from "~/utils/api";
import { cn } from "~/lib/utils";
import { HtmlHTMLAttributes } from "react";

const GDocsCard = () => {
const { data, isLoading } = api.docs.getLatestDocs.useQuery();
if (isLoading) {
return <>Loading</>;
}

if (!data) {
return <>No Repos</>;
}

// Type assertion or type guard to ensure 'data' is an array
if (!Array.isArray(data)) {
return <>Invalid Data</>;
}
}

return (
<div>
{data.length > 0 && data.slice(0, 5).map((repo) => (
<ul key={repo.title}>
<div
className={
repo.state === "closed"
? cn("mb-2 rounded-xl border-2 border-green-400 p-2 ")
: cn("mb-2 rounded-xl border-2 border-red-400 p-2 ")
}
>
<li>{repo.title}</li>
<li>{repo.url}</li>
</div>
</ul>
))}
</div>
);
};

export default GDocsCard;
35 changes: 35 additions & 0 deletions src/components/GithubCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { api } from "~/utils/api";
import { cn } from "~/lib/utils";

const GithubCard = () => {
const { data, isLoading } = api.prs.getLatestPrs.useQuery();

if (isLoading) {
return <>Loading</>;
}

if (!data) {
return <>No Repos</>;
}

return (
<div>
{data.slice(0, 5).map((repo) => (
<ul>
<div
className={
repo.state === "closed"
? cn("mb-2 rounded-xl border-2 border-green-400 p-2 ")
: cn("mb-2 rounded-xl border-2 border-red-400 p-2 ")
}
>
<li>{repo.title}</li>
<li>{repo.url}</li>
</div>
</ul>
))}
</div>
);
};

export default GithubCard;
94 changes: 53 additions & 41 deletions src/components/SaveLocation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import { Button } from "./ui/button";
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "./ui/form";
import { Input } from "./ui/input";

import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";

const SaveLocation: React.FC = () => {
const [selectedLocationType, setSelectedLocationType] = useState<string>(""); // State to store the selected location

Expand Down Expand Up @@ -79,46 +80,57 @@ const SaveLocation: React.FC = () => {
}

return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="w-2/3 space-y-6">
<FormField
control={form.control}
name="location"
render={({ field }) => (
<FormItem>
<FormLabel>Location</FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Please select a location" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="HOME">Home</SelectItem>
<SelectItem value="WORK">Work</SelectItem>
<SelectItem value="SCHOOL">School</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="radius"
control={form.control}
render={({ field }) => (
<FormItem>
<FormLabel>Radius</FormLabel>
<FormControl>
<Input placeholder="100" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button type="submit">Submit</Button>
</form>
</Form>
<Popover>
<PopoverTrigger>Location</PopoverTrigger>
<PopoverContent>
<Form {...form}>
<form
onSubmit={form.handleSubmit(onSubmit)}
className="w-2/3 space-y-6"
>
<FormField
control={form.control}
name="location"
render={({ field }) => (
<FormItem>
<FormLabel>Location</FormLabel>
<Select
onValueChange={field.onChange}
defaultValue={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Please select a location" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="HOME">Home</SelectItem>
<SelectItem value="WORK">Work</SelectItem>
<SelectItem value="SCHOOL">School</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="radius"
control={form.control}
render={({ field }) => (
<FormItem>
<FormLabel>Radius</FormLabel>
<FormControl>
<Input placeholder="100" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button type="submit">Submit</Button>
</form>
</Form>
</PopoverContent>
</Popover>
);
};

Expand Down
29 changes: 29 additions & 0 deletions src/components/ui/popover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from "react"
import * as PopoverPrimitive from "@radix-ui/react-popover"

import { cn } from "~/lib/utils"

const Popover = PopoverPrimitive.Root

const PopoverTrigger = PopoverPrimitive.Trigger

const PopoverContent = React.forwardRef<
React.ElementRef<typeof PopoverPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
<PopoverPrimitive.Portal>
<PopoverPrimitive.Content
ref={ref}
align={align}
sideOffset={sideOffset}
className={cn(
"z-50 w-72 rounded-md border border-neutral-200 bg-white p-4 text-neutral-950 shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-neutral-800 dark:bg-neutral-950 dark:text-neutral-50",
className
)}
{...props}
/>
</PopoverPrimitive.Portal>
))
PopoverContent.displayName = PopoverPrimitive.Content.displayName

export { Popover, PopoverTrigger, PopoverContent }
2 changes: 2 additions & 0 deletions src/server/api/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { gmailRouter } from "./routers/gmail";
import { newsRouter } from "./routers/news";
import { layoutRouter } from "./routers/layout";
import { githubRouter } from "./routers/prs";
import { docsRouter } from "./routers/docs";

/**
* This is the primary router for your server.
Expand All @@ -18,6 +19,7 @@ export const appRouter = createTRPCRouter({
news: newsRouter,
layout: layoutRouter,
prs: githubRouter,
docs: docsRouter,
});

// export type definition of API
Expand Down
56 changes: 56 additions & 0 deletions src/server/api/routers/docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { google } from "googleapis";
import { z } from "zod";

import { env } from "~/env.mjs";

import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";

interface File {
name: string;
description: string;
webContentLink: string;
size: number;
iconLink: string;
}

export const docsRouter = createTRPCRouter({
getLatestDocs: protectedProcedure.query(async ({ ctx }) => {
// get 20 latest emails

const drive = google.drive({
version: "v3",
auth: ctx.googleOauth2Client,
});

drive.files.list(
{
q: 'modifiedTime >= "2023-09-01T00:00:00.000Z"', // Customize the date as needed
orderBy: "modifiedTime desc", // Sort by modification time in descending order
},
(err, res) => {
if (err) {
console.error("Error retrieving files:", err);
return;
}

const files = res?.data.files;
const result: File[] = [];
if (files?.length === 0) {
console.log("No recently edited documents found.");
} else {
console.log("Recently edited documents:");
files?.forEach((file) => {
result.push({
name: file.name ?? "File",
description: file.description ?? "File",
webContentLink: file.webContentLink ?? "",
size: parseInt(file.size ?? "0"),
iconLink: file.iconLink ?? "",
});
});
}
return { result };
},
);
}),
});
6 changes: 4 additions & 2 deletions src/server/api/routers/prs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { createTRPCRouter, protectedProcedure } from "../trpc";

interface PullRequest {
title: string;
state: string;
state: "open" | "closed";
url: string;
}

Expand Down Expand Up @@ -51,7 +51,9 @@ export const githubRouter = createTRPCRouter({
for (const repo of topRepos ?? []) {
const pullRequests = await getAllPullRequests("arian81", repo.name);
pullRequests?.forEach((pr, index) => {
prs.push({ title: pr.title, state: pr.state, url: pr.html_url });
const state: "open" | "closed" =
pr.state === "open" ? "open" : "closed";
prs.push({ title: pr.title, state: state, url: pr.html_url });
});
}
return prs;
Expand Down

0 comments on commit 505a30c

Please sign in to comment.