Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/(root)/questions/[id]/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use client";

import { useEffect } from "react";

export default function ErrorBoundary({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
useEffect(() => console.error(error), [error]);
return (
<div>
<h1>Uh oh, something went wrong loading this question.</h1>
<button onClick={() => reset()}>Try again</button>
</div>
);
}
7 changes: 4 additions & 3 deletions app/(root)/questions/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ const QuestionDetails = async ({ params, searchParams }: RouteParams) => {
const { page, pagesize, filter } = await searchParams;

const { success, data: question } = await getQuestion({ questionId: id });
if (!success || !question) return redirect("/404");

console.log({ success, question });

after(async () => {
await incrementViews({ questionId: id });
});

if (!success || !question) return redirect("/404");

const {
success: areAnswersLoaded,
data: answersResult,
Expand Down Expand Up @@ -155,7 +156,7 @@ const QuestionDetails = async ({ params, searchParams }: RouteParams) => {
textStyles="small-regular text-dark400_light700"
/>
</div>
{/* <Preview content={content} /> */}
<Preview content={content} />
<div className="flex flex-wrap gap-2 mt-8">
{tags.map((tag: Tag) => (
<TagCard
Expand Down
26 changes: 13 additions & 13 deletions app/api/accounts/provider/route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import bcrypt from "bcryptjs";
// import bcrypt from "bcryptjs";
import { NextResponse } from "next/server";

import Account from "@/database/account.model";
import handleError from "@/lib/handlers/error";
import { NotFoundError, ValidationError } from "@/lib/http-error";
import dbConnect from "@/lib/mongoose";
import { AccountSchema, SignInSchema } from "@/lib/validations";
import { AccountSchema } from "@/lib/validations";

export async function POST(request: Request) {
const { providerAccountId, password } = await request.json();
const { providerAccountId } = await request.json();

try {
await dbConnect();
Expand All @@ -24,19 +24,19 @@ export async function POST(request: Request) {

if (!account) throw new NotFoundError("Account");

if (password) {
const validatedData = SignInSchema.partial().safeParse({
email: providerAccountId,
password,
});
// if (password) {
// const validatedData = SignInSchema.partial().safeParse({
// email: providerAccountId,
// password,
// });

if (!validatedData.success)
throw new ValidationError(validatedData.error.flatten().fieldErrors);
// if (!validatedData.success)
// throw new ValidationError(validatedData.error.flatten().fieldErrors);

const isValidPassword = await bcrypt.compare(password, account.password!);
// const isValidPassword = await bcrypt.compare(password, account.password!);

if (!isValidPassword) throw new Error("Invalid password!!!!!!");
}
// if (!isValidPassword) throw new Error("Invalid password!!!!!!");
// }

return NextResponse.json({ success: true, data: account }, { status: 200 });
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Metadata, Viewport } from "next";
import type { Metadata } from "next";
import { Space_Grotesk as SpaceGrotesk, Inter } from "next/font/google";
import { SessionProvider } from "next-auth/react";
import "./globals.css";
import React, { ReactNode } from "react";

import { auth } from "@/auth";
import { Toaster } from "@/components/ui/toaster";
import { metadata as md, viewport as vd } from "@/constants/metadata";
import { metadata as md } from "@/constants/metadata";
import ThemeProvider from "@/context/Theme";

const inter = Inter({
Expand All @@ -23,7 +23,7 @@ const spaceGrotesk = SpaceGrotesk({
});

export const metadata: Metadata = md;
export const viewport: Viewport = vd;
// export const viewport: Viewport = vd;

const RootLayout = async ({ children }: { children: ReactNode }) => {
const session = await auth();
Expand Down
11 changes: 9 additions & 2 deletions auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { IUserDoc } from "./database/user.model";
import { api } from "./lib/handlers/api";
import { SignInSchema } from "./lib/validations";

// POST /api/auth/credntials { email, password}
export const runtime = "nodejs";

export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [
GitHub,
Expand All @@ -23,7 +24,6 @@ export const { handlers, signIn, signOut, auth } = NextAuth({

const { data: existingAccount } = (await api.accounts.getByProvider(
email,
password,
)) as ActionResponse<IAccountDoc>;

if (!existingAccount) return null;
Expand All @@ -34,6 +34,13 @@ export const { handlers, signIn, signOut, auth } = NextAuth({

if (!existingUser) return null;

// const isValidPassword = await bycrpt.compare(
// password,
// existingAccount.password!,
// );

// if (!isValidPassword) return null;

return {
id: existingUser.id,
name: existingUser.name,
Expand Down
68 changes: 34 additions & 34 deletions components/Editor/Preview.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
// import { Code } from "bright";
// import { MDXRemote } from "next-mdx-remote/rsc";
// import React from "react";

// Code.theme = {
// light: "github-light",
// dark: "github-dark",
// lightSelector: "html.light",
// };

// const Preview = ({ content }: { content: string }) => {
// const formattedContent = content.replace(/\\/g, "").replace(/&#x20;/g, "");

// return (
// <section className="markdown prose grid break-words">
// <MDXRemote
// source={formattedContent}
// components={{
// pre: (props) => (
// <Code
// {...props}
// lineNumbers
// className="shadow-light-200 dark:shadow-dark-200"
// />
// ),
// }}
// />
// </section>
// );
// };

// export default Preview;

import { Code } from "bright";
import { MDXRemote } from "next-mdx-remote/rsc";
import remarkGfm from "remark-gfm";
Expand All @@ -44,7 +11,6 @@ Code.theme = {
};

const Preview = ({ content = "" }: { content: string }) => {
console.log(content);
// const formattedContent = content.replace(/\\/g, "").replace(/&#x20;/g, "");

// First apply basic content cleaning
Expand All @@ -63,6 +29,7 @@ const Preview = ({ content = "" }: { content: string }) => {
}
return (
<section className="markdown prose grid break-words">
<div>Test Preview </div>
<MDXRemote
source={formattedContent}
options={{
Expand All @@ -85,3 +52,36 @@ const Preview = ({ content = "" }: { content: string }) => {
};

export default Preview;

// import { Code } from "bright";
// import { MDXRemote } from "next-mdx-remote/rsc";
// import React from "react";

// Code.theme = {
// light: "github-light",
// dark: "github-dark",
// lightSelector: "html.light",
// };

// const Preview = ({ content }: { content: string }) => {
// const formattedContent = content.replace(/\\/g, "").replace(/&#x20;/g, "");

// return (
// <section className="markdown prose grid break-words">
// <MDXRemote
// source={formattedContent}
// components={{
// pre: (props) => (
// <Code
// {...props}
// lineNumbers
// className="shadow-light-200 dark:shadow-dark-200"
// />
// ),
// }}
// />
// </section>
// );
// };

// export default Preview;
2 changes: 1 addition & 1 deletion components/Metric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface MetricProps {
}

const Metric = ({
imageUrl,
imageUrl = "/images/site-logo.svg",
alt,
value,
href,
Expand Down
6 changes: 4 additions & 2 deletions components/answer/AllAnswers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import AnswerCard from "../cards/AnswerCard";
import DataRenderer from "../DataRenderer";
import CommonFilter from "../filter/CommonFilter";
import Pagination from "../Pagination";

interface Props extends ActionResponse<Answer[]> {
totalAnswers: number;
page: number;
Expand All @@ -21,8 +22,10 @@ const AllAnswers = ({
error,
totalAnswers,
}: Props) => {
console.log({ page, isNext, success, data, error, totalAnswers });

return (
<div className="mt-11 ">
<div className="mt-11">
<div className="flex justify-between gap-5 max-sm:flex-col sm:items-center">
<h3 className="primary-text-gradient ">
{totalAnswers} {totalAnswers > 1 ? "Answers" : "Answer"}
Expand All @@ -41,7 +44,6 @@ const AllAnswers = ({
answers.map((answer) => <AnswerCard key={answer._id} {...answer} />)
}
/>

<Pagination page={page} isNext={isNext} />
</div>
);
Expand Down
13 changes: 13 additions & 0 deletions components/cards/AnswerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ const AnswerCard = ({
showActionBtns = false,
showReadMore = false,
}: AnswerCardProps) => {
console.log({
_id,
content,
author,
question,
createdAt,
upvotes,
downvotes,
containerClasses,
showActionBtns,
showReadMore,
});

const hasVotedPromise = hasVoted({ targetId: _id, targetType: "answer" });

return (
Expand Down
15 changes: 7 additions & 8 deletions constants/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Metadata } from "next";

const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL!;
// const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL!;
export const metadata: Metadata = {
metadataBase: new URL(SITE_URL),
title: "Dev OverFlow",
description:
"Dev Overflow is a community-driven platform to ask and answer real-world programming questions. Learn, grow, and connect with developers around the world.",
Expand Down Expand Up @@ -88,9 +87,9 @@ export const metadata: Metadata = {
},
};

export const viewport = {
// Optional: Theme color for browser UI and mobile experience
width: "device-width",
initialScale: 1,
themeColor: "#18181b",
};
// export const viewport = {
// // Optional: Theme color for browser UI and mobile experience
// width: "device-width",
// initialScale: 1,
// themeColor: "#18181b",
// };
13 changes: 6 additions & 7 deletions lib/actions/collection.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PipelineStage } from "mongoose";
import mongoose from "mongoose";
import { revalidatePath } from "next/cache";

import { auth } from "@/auth";
// import { auth } from "@/auth";
import ROUTES from "@/constants/routes";
import { Collection, Question } from "@/database";

Expand Down Expand Up @@ -97,12 +97,11 @@ export async function hasSavedQuestion(

export async function getAllSavedQuestions(
params: PaginatedSearchParams,
): Promise<ActionResponse<{
collection: Collection[];
isNext: boolean;
}> | null> {
const session = await auth();
if (!session) return null;
): Promise<ActionResponse<{ collection: Collection[]; isNext: boolean }>> {
// const session = await auth();
// if (!session) return {

// };

const validationResult = await action({
params,
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/vote.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import mongoose, { ClientSession } from "mongoose";
import { revalidatePath } from "next/cache";
import { after } from "next/server";

import { auth } from "@/auth";
// import { auth } from "@/auth";
import ROUTES from "@/constants/routes";
import { Answer, Question, Vote } from "@/database";

Expand Down
4 changes: 2 additions & 2 deletions lib/handlers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export const api = {
accounts: {
getAll: () => fetchHandler(`${API_BASE_URL}/accounts`),
getById: (id: string) => fetchHandler(`${API_BASE_URL}/accounts/${id}`),
getByProvider: (providerAccountId: string, password?: string) =>
getByProvider: (providerAccountId: string) =>
fetchHandler(`${API_BASE_URL}/accounts/provider`, {
method: "POST",
body: JSON.stringify({ providerAccountId, password }),
body: JSON.stringify({ providerAccountId }),
}),
create: (userData: Partial<IAccount>) =>
fetchHandler(`${API_BASE_URL}/accounts`, {
Expand Down
Loading