Skip to content

Commit

Permalink
Merge pull request #32 from ruru-m07/main
Browse files Browse the repository at this point in the history
🚀 dashboard
  • Loading branch information
ruru-m07 authored Feb 21, 2024
2 parents b7098be + 5250c6f commit 4e7310c
Show file tree
Hide file tree
Showing 25 changed files with 609 additions and 109 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
"glassit.step": 500,
// "bitoAI.codeCompletion.enableCommentToCode": true,
// "bitoAI.codeCompletion.enableAutoCompletion": true,
"cmake.options.statusBarVisibility": "hidden"
"cmake.options.statusBarVisibility": "hidden",
"editor.cursorBlinking": "smooth"
}
2 changes: 1 addition & 1 deletion actions/repo/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const create = async (
},
});

console.log(existingRepo);
// console.log(existingRepo);

if (existingRepo) {
return { error: "Repository already exist with this name!" };
Expand Down
17 changes: 17 additions & 0 deletions actions/user/update-bio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use server";

import { db } from "@/lib/db";

export const updateBio = async (username: string, bio: string) => {
if (!username) {
return { error: "Invalid user!" };
}
await db.user.update({
where: { username: username },
data: {
bio: bio,
},
});

return { success: "Profile update Successfully! 🎉" };
};
12 changes: 8 additions & 4 deletions app/[username]/[repository]/components/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function Code({ repodata }: { repodata: Repository }) {
</div>
<div className="flex">
<Button
className="mr-1 hover:border-[#51d89f] hover:bg-[#10241b] hover:text-[#51d89f]"
className="mr-1 dark:hover:border-[#51d89f] hover:border-[#166534] dark:hover:bg-[#10241b] hover:bg-[#a7f3d0] hover:text-[#166534] dark:hover:text-[#51d89f]"
variant={"outline"}
>
<Heart className="w-4 h-4 mr-2" />
Expand Down Expand Up @@ -293,9 +293,13 @@ export function Code({ repodata }: { repodata: Repository }) {
</Button>
<Dialog>
<DialogTrigger asChild>
<Button variant="outline" className="ml-auto">
Add File
</Button>
<Link
href={`${repodata.name}/upload/${repodata.DefualtBranch}`}
>
<Button variant="outline" className="ml-auto ">
Add File
</Button>
</Link>
</DialogTrigger>
</Dialog>
</div>
Expand Down
11 changes: 11 additions & 0 deletions app/[username]/[repository]/upload/[branch]/[[...path]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Upload from "../../components/Upload";

export default function Page() {
return (
<main className="mx-6 my-5 xl:mx-60">
<div>
<Upload />
</div>
</main>
);
}
157 changes: 157 additions & 0 deletions app/[username]/[repository]/upload/components/Upload.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
"use client";

import React, { useEffect, useState } from "react";
import Dropzone from "react-dropzone";
import { FileWithPath } from "file-selector";
import {
FileCode2,
GitCommitHorizontal,
GitPullRequestArrow,
} from "lucide-react";
import { Card } from "@/components/ui/card";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { useAuth } from "@/context/userContext";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import { Button } from "@/components/ui/button";
import { Label } from "@/components/ui/label";
import { useParams } from "next/navigation";
import Link from "next/link";

const Upload = () => {
const { user } = useAuth();
const params = useParams<{
username: string;
repository: string;
branch: string;
}>();
console.log(params);
const [files, setFiles] = useState<FileWithPath[]>([]);

const handlechange = async (acceptFiles: FileWithPath[]) => {
// Items to ignore
const ignoreList = [
".env",
"node_modules",
".git",
".next",
".vercel",
"dist",
];

// console.log(acceptFiles);
// Filter out files or folders listed in the ignoreList

const filteredFiles = acceptFiles.filter((file) => {
const fileName = file.path && file.path.toLowerCase();
return !ignoreList.some((item) => fileName?.includes(item.toLowerCase()));
});

setFiles((prevFiles) => [...prevFiles, ...filteredFiles]);
};

useEffect(() => {
console.log(files);
}, [files]);

return (
<div>
<div className="my-2 text-xl">
<Link
className=" hover:text-blue-700 hover:underline"
href={`/${params.username}/${params.repository}`}
>
{params.repository}{" "}
</Link>{" "}
/
</div>
<div className="items-center justify-center w-full p-5 border rounded-md">
<Dropzone onDrop={(acceptedFiles) => handlechange(acceptedFiles)}>
{({ getRootProps, getInputProps, isDragActive }) => (
<section className="flex items-center justify-center h-96">
<div
className="flex items-center justify-center w-full h-full "
{...getRootProps()}
>
<input {...getInputProps()} />
{isDragActive ? (
<div className="flex items-center justify-center w-full h-full border-4 border-dashed rounded-md">
<div className="grid place-items-center">
<FileCode2
className="mb-5 text-muted-foreground"
size={50}
/>
<p className="text-muted-foreground">
Drop to Upload file
</p>
</div>
</div>
) : (
<div className="grid w-full place-items-center">
<FileCode2
className="mb-5 text-muted-foreground"
size={50}
/>

<p className="text-muted-foreground">
Drag files here to add them to your repository
</p>
<p className="text-muted-foreground">
or
<span className="text-blue-600 cursor-pointer hover:underline">
choose your file
</span>
</p>
</div>
)}
</div>
</section>
)}
</Dropzone>
</div>

<Card className="flex my-5 border-none rounded-md">
<div>
<Avatar>
<AvatarImage
src={user?.image || "https://asset-cocola.vercel.app/copilot.png"}
alt={user?.username || "profile"}
/>
<AvatarFallback> </AvatarFallback>
</Avatar>
</div>
<div className="w-full ml-4 comment-box">
<Card className="w-full p-4 rounded-md">
<h1 className="text-xl ">Commit changes</h1>
<Input className="my-3" placeholder="Add file via upload" />
<Textarea
rows={5}
placeholder="Add an optional extended description..."
/>
<RadioGroup className="mt-3" defaultValue="main">
<div className="flex items-center space-x-2">
<RadioGroupItem value="main" id="r1" />
<GitCommitHorizontal size={25} />
<p className="ml-2">Commit directly to the main branch.</p>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem className="mr-1" value="new" id="r2" />
<GitPullRequestArrow size={20} />
<p className="ml-2">
Create a new branch for this commit and start a pull request.
</p>
</div>
</RadioGroup>
</Card>
<div className="flex gap-3 my-4">
<Button variant={"default"}>Commit changes</Button>
<Button variant={"danger2"}>Cancel</Button>
</div>
</div>
</Card>
</div>
);
};

export default Upload;
80 changes: 75 additions & 5 deletions app/[username]/components/UserSide.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
import React from "react";
import React, { useState } from "react";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { User } from "@prisma/client";
import { Button } from "@/components/ui/button";
import { ASSET_BASE_URL } from "@/resources";

import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
import { updateBio } from "@/actions/user/update-bio";
import Alert from "@/components/alert/Alert";
const UserSide = ({ userdata, user }: { userdata: User; user: User }) => {
const [error, setError] = useState<string | undefined>("");
const [success, setSuccess] = useState<string | undefined>("");
const [bio, setBio] = useState<string>();

const updateUserBio = () => {
setError("");
setSuccess("");

if (user?.username && bio) {
updateBio(user?.username, bio).then((data) => {
if (data?.error) {
setError(data.error);
}
if (data?.success) {
setSuccess(data.success);
setBio("");
}
});
}
};

return (
<div className="w-72">
<Avatar className="overflow-visible mt-3 w-72 h-72">
Expand All @@ -29,9 +62,46 @@ const UserSide = ({ userdata, user }: { userdata: User; user: User }) => {
) : null}

{userdata?.username === user?.username ? (
<Button className="w-full mt-4" variant={"outline"}>
Edit profile
</Button>
<Dialog>
<DialogTrigger asChild>
<Button className="w-full mt-4" variant={"outline"}>
Edit profile
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>Edit profile</DialogTitle>
<DialogDescription>
Make changes to your profile here. Click save when you&apos;re
done.
</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="bio" className="text-right">
Bio
</Label>
<Textarea
id="bio"
className="col-span-3"
value={bio}
onChange={(e) => setBio(e.target.value)}
/>
</div>
</div>
<div className="my-4">
{error ? <Alert message={error} variant={"alert"} /> : null}
{success ? (
<Alert message={success} variant={"success"} />
) : null}
</div>
<DialogFooter>
<Button onClick={updateUserBio} type="submit">
Save changes
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
) : (
<Button className="w-full mt-4" variant={"outline"}>
Follow
Expand Down
2 changes: 1 addition & 1 deletion app/chat/[user]/loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Loading = () => {
<div className="ml-4 h-full w-full border-slate-100">
<Card className="h-full">
<div className="px-2 h-full flex justify-center items-center">
<Loader2 />
<Loader2 size={30} />
</div>
</Card>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/chat/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function DashboardLayout({
},
{
id: 2,
name: "Ruru",
name: "ruru",
lastMessage: "Hello! How are you?",
time: "12:00",
avatar: "https://asset-cocola.vercel.app/ruru_m07.png",
Expand Down
16 changes: 16 additions & 0 deletions app/chat/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Loader2 from "@/components/Loader2";
import { Card } from "@/components/ui/card";

const Loading = () => {
return (
<div className="ml-4 h-full w-full border-slate-100">
<Card className="h-full">
<div className="px-2 h-full flex justify-center items-center">
<Loader2 size={30} />
</div>
</Card>
</div>
);
};

export default Loading;
Binary file added app/favicon.ico
Binary file not shown.
Loading

0 comments on commit 4e7310c

Please sign in to comment.