Skip to content

Commit

Permalink
feature/applying-prettier (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-PS-05 authored Oct 24, 2024
1 parent 110b87d commit 4d53afe
Show file tree
Hide file tree
Showing 138 changed files with 2,438 additions and 4,173 deletions.
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ Thank you for considering contributing to MemFree! We appreciate your support an
3. **Make a Pull Request**: If you have new features to add, quality-of-life improvements, or bug fixes, feel free to make a pull request. Ensure your code adheres to our code style and includes appropriate tests.
4. **Feedback and Support**: Share your thoughts and feedback on our [Discord](https://discord.com/invite/7QqyMSTaRq) or via the [MemFree Feedback Form](https://feedback.memfree.me/).

## Code Style and Formatting

To maintain consistency across the codebase, please ensure you run the following command before submitting a pull request:

```bash
npm run prettier
```

## Features You Can Contribute

- **Search Engines and AI Models**: Integrate additional search engines or AI models to enhance search capabilities.
Expand Down
52 changes: 24 additions & 28 deletions frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
{
"$schema": "https://json.schemastore.org/eslintrc",
"root": true,
"extends": [
"next/core-web-vitals",
"prettier",
"plugin:tailwindcss/recommended"
],
"plugins": ["tailwindcss"],
"rules": {
"@next/next/no-html-link-for-pages": "off",
"react/jsx-key": "off",
"tailwindcss/no-custom-classname": "off",
"tailwindcss/classnames-order": "off"
},
"settings": {
"tailwindcss": {
"callees": ["cn"],
"config": "tailwind.config.ts"
"$schema": "https://json.schemastore.org/eslintrc",
"root": true,
"extends": ["next/core-web-vitals", "prettier", "plugin:tailwindcss/recommended"],
"plugins": ["tailwindcss"],
"rules": {
"@next/next/no-html-link-for-pages": "off",
"react/jsx-key": "off",
"tailwindcss/no-custom-classname": "off",
"tailwindcss/classnames-order": "off"
},
"next": {
"rootDir": true
}
},
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"parser": "@typescript-eslint/parser"
}
]
"settings": {
"tailwindcss": {
"callees": ["cn"],
"config": "tailwind.config.ts"
},
"next": {
"rootDir": true
}
},
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"parser": "@typescript-eslint/parser"
}
]
}
4 changes: 1 addition & 3 deletions frontend/actions/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import { cookies } from 'next/headers';

export const getAuthToken = async () => {
const token =
cookies().get('__Secure-authjs.session-token')?.value ??
cookies().get('authjs.session-token')?.value;
const token = cookies().get('__Secure-authjs.session-token')?.value ?? cookies().get('authjs.session-token')?.value;
return {
data: token,
};
Expand Down
14 changes: 3 additions & 11 deletions frontend/app/[locale]/(marketing)/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ async function getPageFromParams(params) {
return page;
}

export async function generateMetadata({
params,
}: PageProps): Promise<Metadata> {
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
const page = await getPageFromParams(params);

if (!page) {
Expand Down Expand Up @@ -88,14 +86,8 @@ export default async function PagePage({ params }: PageProps) {
return (
<article className="container max-w-3xl py-6 lg:py-12">
<div className="space-y-4">
<h1 className="inline-block font-heading text-4xl lg:text-5xl">
{page.title}
</h1>
{page.description && (
<p className="text-xl text-muted-foreground">
{page.description}
</p>
)}
<h1 className="inline-block font-heading text-4xl lg:text-5xl">{page.title}</h1>
{page.description && <p className="text-xl text-muted-foreground">{page.description}</p>}
</div>
<hr className="my-4" />
<Mdx code={page.body.code} />
Expand Down
73 changes: 16 additions & 57 deletions frontend/app/[locale]/(search)/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { FailedUrlTable } from '@/components/failed-url-table';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Tabs, TabsContent } from '@/components/ui/tabs';
import { UrlTable } from '@/components/url-table';
Expand All @@ -19,70 +13,43 @@ export default async function page() {
if (!user) {
redirect('/login');
}
const [urls, failedUrls, indexCount, searchCount] = await getUserStatistics(
user.id,
);
const [urls, failedUrls, indexCount, searchCount] = await getUserStatistics(user.id);

return (
<ScrollArea className="group mx-auto overflow-auto peer-[[data-state=open]]:lg:pl-[300px] peer-[[data-state=open]]:xl:pl-[320px] my-10">
<div className="flex-1 space-y-4 p-4 md:p-8 pt-6">
<div className="flex items-center justify-between space-y-2">
<h2 className="text-3xl font-bold tracking-tight">
Search & Index Statistics
</h2>
<h2 className="text-3xl font-bold tracking-tight">Search & Index Statistics</h2>
</div>
<Tabs defaultValue="overview" className="space-y-4">
<TabsContent value="overview" className="space-y-4">
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">
Index Count
</CardTitle>
<Link
size={18}
strokeWidth={2}
color="gray"
></Link>
<CardTitle className="text-sm font-medium">Index Count</CardTitle>
<Link size={18} strokeWidth={2} color="gray"></Link>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold text-primary">
{indexCount}
</div>
<p className="pt-2 text-xs text-muted-foreground">
bookmarks and urls
</p>
<div className="text-2xl font-bold text-primary">{indexCount}</div>
<p className="pt-2 text-xs text-muted-foreground">bookmarks and urls</p>
</CardContent>
</Card>
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">
Search Count
</CardTitle>
<Search
size={18}
strokeWidth={2}
color="gray"
></Search>
<CardTitle className="text-sm font-medium">Search Count</CardTitle>
<Search size={18} strokeWidth={2} color="gray"></Search>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold text-primary">
{searchCount}
</div>
<p className="pt-2 text-xs text-muted-foreground">
AI search
</p>
<div className="text-2xl font-bold text-primary">{searchCount}</div>
<p className="pt-2 text-xs text-muted-foreground">AI search</p>
</CardContent>
</Card>
</div>
<div className="grid gap-4 grid-cols-1 ">
<Card className="col-span-4">
<CardHeader>
<CardTitle>Recent Indexed Urls</CardTitle>
<CardDescription>
Recent bookmarks and web pages you have
indexed
</CardDescription>
<CardDescription>Recent bookmarks and web pages you have indexed</CardDescription>
</CardHeader>
<CardContent className="pl-2">
<UrlTable urls={urls} />
Expand All @@ -93,22 +60,14 @@ export default async function page() {
<div className="grid gap-4 grid-cols-1 ">
<Card className="col-span-4">
<CardHeader>
<CardTitle>
Failed Indexed Urls
</CardTitle>
<CardTitle>Failed Indexed Urls</CardTitle>
<CardDescription className="text-md font-semibold py-2">
Some web pages are inaccessible,
Some web pages are not public.
Please install the browser extension
and index again.
Some web pages are inaccessible, Some web pages are not public. Please install the browser extension and index
again.
</CardDescription>
<CardDescription className="text-md font-semibold py-2">
Please refer to{' '}
<a
href="https://www.memfree.me/docs/index-bookmarks"
target="_blank"
className="text-primary"
>
<a href="https://www.memfree.me/docs/index-bookmarks" target="_blank" className="text-primary">
How to Index Web Pages
</a>
</CardDescription>
Expand Down
27 changes: 9 additions & 18 deletions frontend/app/[locale]/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@

import { Button } from '@/components/ui/button';

export default function Error({
reset,
}: {
reset: () => void;
}) {

return (
<div className="flex min-h-screen flex-col items-center justify-center">
<h2 className="mb-5 text-center">Something went wrong!</h2>
<Button
type="submit"
variant="default"
onClick={() => reset()}
>
Try again
</Button>
</div>
);
export default function Error({ reset }: { reset: () => void }) {
return (
<div className="flex min-h-screen flex-col items-center justify-center">
<h2 className="mb-5 text-center">Something went wrong!</h2>
<Button type="submit" variant="default" onClick={() => reset()}>
Try again
</Button>
</div>
);
}
5 changes: 1 addition & 4 deletions frontend/app/api/delete-url/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ export async function POST(req: Request) {
const { url } = await req.json();
const session = await auth();
if (!session?.user) {
return NextResponse.json(
{ message: 'Unauthorized' },
{ status: 401 },
);
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 });
}

await removeUrlFromErrorUrls(session?.user.id, url);
Expand Down
5 changes: 1 addition & 4 deletions frontend/app/api/index-md/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ export async function POST(req: Request) {
// TODO: Check if the user is authenticated
const user = await getUserById(userId);
if (!user) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 },
);
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}

const existedUrl = await urlsExists(userId, [url]);
Expand Down
18 changes: 4 additions & 14 deletions frontend/app/api/index2/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ export async function POST(req: Request) {
// TODO: Check if the user is authenticated
const user = await getUserById(userId);
if (!user) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 },
);
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
if (urls.length > 10) {
return NextResponse.json(
Expand Down Expand Up @@ -56,12 +53,8 @@ export async function POST(req: Request) {
})
.then(async (response) => {
if (!response.ok) {
console.error(
`Index Url Error! status: ${response.status}`,
);
throw new Error(
`Index Url Error! status: ${response.status}`,
);
console.error(`Index Url Error! status: ${response.status}`);
throw new Error(`Index Url Error! status: ${response.status}`);
}
const result = await response.json();
const indexCount = await addUrl(userId, url);
Expand All @@ -88,10 +81,7 @@ export async function POST(req: Request) {
const failedUrls = results.filter((r) => r.error);

if (successfulUrls.length === 0) {
return NextResponse.json(
{ error: 'All URL requests failed' },
{ status: 500 },
);
return NextResponse.json({ error: 'All URL requests failed' }, { status: 500 });
}

if (needCompact) {
Expand Down
31 changes: 6 additions & 25 deletions frontend/app/api/one-tap-login/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ export async function POST(req: Request) {
try {
const { token } = await req.json();
if (!token) {
return NextResponse.json(
{ message: 'Invalid token, please check' },
{ status: 400 }
);
return NextResponse.json({ message: 'Invalid token, please check' }, { status: 400 });
}

const googleAuthClient = new OAuth2Client(AUTH_GOOGLE_ID);
Expand All @@ -22,25 +19,12 @@ export async function POST(req: Request) {
});
const payload = ticket.getPayload();
if (!payload) {
return NextResponse.json(
{ message: 'Cannot extract payload from signin token' },
{ status: 400 }
);
return NextResponse.json({ message: 'Cannot extract payload from signin token' }, { status: 400 });
}

const {
email,
sub,
given_name,
family_name,
email_verified,
picture: image,
} = payload;
const { email, sub, given_name, family_name, email_verified, picture: image } = payload;
if (!email) {
return NextResponse.json(
{ message: 'Email not available' },
{ status: 400 }
);
return NextResponse.json({ message: 'Email not available' }, { status: 400 });
}

let user = await adapter.getUserByEmail!(email);
Expand All @@ -57,13 +41,10 @@ export async function POST(req: Request) {
if (user) {
return NextResponse.json(user);
} else {
return NextResponse.json(
{ message: 'User not found' },
{ status: 404 }
);
return NextResponse.json({ message: 'User not found' }, { status: 404 });
}
} catch (error) {
console.error('Request failed:', error);
return NextResponse.json({ error: `${error}` }, { status: 500 });
}
}
}
Loading

0 comments on commit 4d53afe

Please sign in to comment.