Skip to content

Commit

Permalink
Adds better view on repo table and fixes team details bugs (#62)
Browse files Browse the repository at this point in the history
* Adds better view on repo table and fixes other team details page issues

* Fixes lint issues
  • Loading branch information
sudoFerraz authored Mar 24, 2024
1 parent d5c0f1e commit 0a8581c
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 27 deletions.
13 changes: 12 additions & 1 deletion src/app/(dashboard)/teams/[teamId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Button } from "@/components/ui/button";
import { useRouter } from "next/navigation";
import { OverviewDto } from "@/app/api/teams/types/overview.dto";
import { LoadingCircle } from "@/components/navigation/loading";
import { TextGenerateEffect } from "@/components/ui/text-generate-effect";

interface PageProps {
params: { teamId: string };
Expand All @@ -40,6 +41,7 @@ export default function TeamDetailsPage({ params }: PageProps) {
const { data: session } = useSession();

const [isLoading, setIsLoading] = useState(true);
const [emptyTeam, setEmptyTeam] = useState(false);
const [team, setTeam] = useState<Team>();
const [overview, setOverview] = useState<OverviewDto>();
const [userCredDtos, setUserCredDtos] = useState<UserCredDto[]>([]);
Expand Down Expand Up @@ -93,6 +95,9 @@ export default function TeamDetailsPage({ params }: PageProps) {
);
if (data.success) {
setRegisteredGitRepos(data.registeredRepos);
if (data.registeredRepos.length == 0) {
setEmptyTeam(true);
}
}
};

Expand Down Expand Up @@ -173,7 +178,13 @@ export default function TeamDetailsPage({ params }: PageProps) {
<div>
{isLoading ? (
<div className="pt-36 flex justify-center">
<LoadingCircle></LoadingCircle>
{emptyTeam ? (
<div className="pl-36 pr-36 flex justify-center">
<TextGenerateEffect words="Seems like there are no github repositories on this team, fix this by clicking on the manage repositories button above." />
</div>
) : (
<LoadingCircle></LoadingCircle>
)}
</div>
) : (
<div>
Expand Down
9 changes: 6 additions & 3 deletions src/app/(dashboard)/teams/[teamId]/teamInsights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export function TeamInsights({ overview }: TeamInsightsProps) {
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">Total team CRED</CardTitle>
<CardTitle className="text-sm font-medium">
Total team impact
</CardTitle>
<Icons.lineChart></Icons.lineChart>
</CardHeader>
<CardContent>
Expand All @@ -27,7 +29,7 @@ export function TeamInsights({ overview }: TeamInsightsProps) {
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">
Team CRED earned this week
Team impact earned week
</CardTitle>
<Icons.pizza></Icons.pizza>
</CardHeader>
Expand All @@ -36,7 +38,8 @@ export function TeamInsights({ overview }: TeamInsightsProps) {
{overview?.weekScore.toFixed(2)}
</div>
<p className="pt-1 text-xs text-muted-foreground">
+{overview?.wowScore.toFixed(2)}% over last week
{overview?.wowScore ? (overview?.wowScore > 0 ? "+" : "-") : ""}{" "}
{overview?.wowScore.toFixed(2)}% over last week
</p>
</CardContent>
</Card>
Expand Down
12 changes: 6 additions & 6 deletions src/components/overview/dashboardInsights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,24 @@ export function DashboardInsights({ overview }: DashboardInsightsProps) {
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">
Total CRED earned
</CardTitle>
<CardTitle className="text-sm font-medium">Total impact</CardTitle>
<Icons.pizza></Icons.pizza>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">
{overview?.totalScore.toFixed(2)}
</div>
<p className="pt-1 text-xs text-muted-foreground">
+{overview?.weekGrowth?.toFixed(2) || 0}% CRED earned
{overview?.weekGrowth ? (overview?.weekGrowth > 0 ? "+" : "-") : ""}{" "}
{overview?.weekGrowth.toFixed(2)}% all time growth during last week
</p>
</CardContent>
</Card>

<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">
CRED earned this week
Impact this week
</CardTitle>
<Icons.gitBranch></Icons.gitBranch>
</CardHeader>
Expand All @@ -38,7 +37,8 @@ export function DashboardInsights({ overview }: DashboardInsightsProps) {
{overview?.weekScore.toFixed(2)}
</div>
<p className="pt-1 text-xs text-muted-foreground">
+{overview?.wowScore.toFixed(2)}% over last week
{overview?.wowScore ? (overview?.wowScore > 0 ? "+" : "-") : ""}{" "}
{overview?.wowScore.toFixed(2)}% compared to last week
</p>
</CardContent>
</Card>
Expand Down
42 changes: 28 additions & 14 deletions src/components/teams/columns.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
"use client";

import { Button } from "@/components/ui/button";
import { MoreHorizontal } from "lucide-react";
import axios from "axios";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { ColumnDef } from "@tanstack/react-table";
import { ArrowUpDown } from "lucide-react";
import { Checkbox } from "@/components/ui/checkbox";
import { useEffect, useState } from "react";
import { Icons } from "../icons";
import { stringToColour } from "@/lib/utils";

export type GitRepoView = {
id: string;
Expand Down Expand Up @@ -80,10 +71,23 @@ export const columns: ColumnDef<GitRepoView>[] = [
{
accessorKey: "name",
header: () => <div className="text-left"> Name </div>,
cell: ({ row }) => {
return (
<div className="flex">
<span
className={`h-4 w-4 rounded-full`}
style={{
backgroundColor: `${stringToColour(row.getValue("name"))}`,
}}
></span>
<div className="pl-3">{row.getValue("name")}</div>
</div>
);
},
},
{
accessorKey: "created_at",
header: ({ column }) => {
header: () => {
return <div>Created At</div>;
},
cell: ({ row }) => {
Expand All @@ -96,7 +100,7 @@ export const columns: ColumnDef<GitRepoView>[] = [
},
{
accessorKey: "stars",
header: ({ column }) => {
header: () => {
return <div>Stars</div>;
},
cell: ({ row }) => {
Expand All @@ -105,7 +109,7 @@ export const columns: ColumnDef<GitRepoView>[] = [
},
{
accessorKey: "forks",
header: ({ column }) => {
header: () => {
return <div>Forks</div>;
},
cell: ({ row }) => {
Expand All @@ -115,5 +119,15 @@ export const columns: ColumnDef<GitRepoView>[] = [
{
accessorKey: "owner",
header: "Owner",
cell: ({ row }) => {
return (
<div className="flex">
<div className="h-5 w-5">
<Icons.gitHub></Icons.gitHub>
</div>
<div className="pl-3">{row.getValue("owner")}</div>
</div>
);
},
},
];
76 changes: 76 additions & 0 deletions src/components/ui/background-boxes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"use client";
import React from "react";
import { motion } from "framer-motion";
import { cn } from "@/lib/utils";

export const BoxesCore = ({ className, ...rest }: { className?: string }) => {
const rows = new Array(150).fill(1);
const cols = new Array(100).fill(1);
const colors = [
"--sky-300",
"--pink-300",
"--green-300",
"--yellow-300",
"--red-300",
"--purple-300",
"--blue-300",
"--indigo-300",
"--violet-300",
];
const getRandomColor = () => {
return colors[Math.floor(Math.random() * colors.length)];
};

return (
<div
style={{
transform: `translate(-40%,-60%) skewX(-48deg) skewY(14deg) scale(0.675) rotate(0deg) translateZ(0)`,
}}
className={cn(
"absolute left-1/4 p-4 -top-1/4 flex -translate-x-1/2 -translate-y-1/2 w-full h-full z-0 ",
className,
)}
{...rest}
>
{rows.map((_, i) => (
<motion.div
key={`row` + i}
className="w-16 h-8 border-l border-slate-700 relative"
>
{cols.map((_, j) => (
<motion.div
whileHover={{
backgroundColor: `var(${getRandomColor()})`,
transition: { duration: 0 },
}}
animate={{
transition: { duration: 2 },
}}
key={`col` + j}
className="w-16 h-8 border-r border-t border-slate-700 relative"
>
{j % 2 === 0 && i % 2 === 0 ? (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth="1.5"
stroke="currentColor"
className="absolute h-6 w-10 -top-[14px] -left-[22px] text-slate-700 stroke-[1px] pointer-events-none"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M12 6v12m6-6H6"
/>
</svg>
) : null}
</motion.div>
))}
</motion.div>
))}
</div>
);
};

export const Boxes = React.memo(BoxesCore);
54 changes: 54 additions & 0 deletions src/components/ui/text-generate-effect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"use client";
import { useEffect } from "react";
import { motion, stagger, useAnimate } from "framer-motion";
import { cn } from "@/lib/utils";

export const TextGenerateEffect = ({
words,
className,
}: {
words: string;
className?: string;
}) => {
const [scope, animate] = useAnimate();
const wordsArray = words.split(" ");
useEffect(() => {
animate(
"span",
{
opacity: 1,
},
{
duration: 2,
delay: stagger(0.2),
},
);
}, [scope.current]);

const renderWords = () => {
return (
<motion.div ref={scope}>
{wordsArray.map((word, idx) => {
return (
<motion.span
key={word + idx}
className="dark:text-white text-black opacity-0"
>
{word}{" "}
</motion.span>
);
})}
</motion.div>
);
};

return (
<div className={cn("font-bold", className)}>
<div className="mt-4">
<div className=" dark:text-white text-black text-2xl leading-snug tracking-wide">
{renderWords()}
</div>
</div>
</div>
);
};
13 changes: 13 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,16 @@ import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

export function stringToColour(str: string): string {
let hash = 0;
str.split("").forEach((char) => {
hash = char.charCodeAt(0) + ((hash << 5) - hash);
});
let colour = "#";
for (let i = 0; i < 3; i++) {
const value = (hash >> (i * 8)) & 0xff;
colour += value.toString(16).padStart(2, "0");
}
return colour;
}
22 changes: 19 additions & 3 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const config = {
'./components/**/*.{ts,tsx}',
'./app/**/*.{ts,tsx}',
'./src/**/*.{ts,tsx}',
],
],
prefix: "",
theme: {
container: {
Expand Down Expand Up @@ -74,7 +74,23 @@ const config = {
},
},
},
plugins: [require("tailwindcss-animate")],
plugins: [require("tailwindcss-animate"), addVariablesForColors],
} satisfies Config

export default config

const {
default: flattenColorPalette,
} = require("tailwindcss/lib/util/flattenColorPalette");

function addVariablesForColors({ addBase, theme }: any) {
let allColors = flattenColorPalette(theme("colors"));
let newVars = Object.fromEntries(
Object.entries(allColors).map(([key, val]) => [`--${key}`, val])
);

addBase({
":root": newVars,
});
}

export default config

0 comments on commit 0a8581c

Please sign in to comment.