1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
import { CardContent, Card } from '@/components/ui/card';
import { db } from '@/server/db';
import {
sessions,
storedContent,
userStoredContent,
users,
} from '@/server/db/schema';
import { eq, inArray } from 'drizzle-orm';
import { cookies, headers } from 'next/headers';
import { redirect } from 'next/navigation';
import Image from 'next/image';
import QueryAI from '@/components/QueryAI';
import MessagePoster from './MessagePoster';
export const runtime = 'edge';
export default async function Home() {
const token =
cookies().get('next-auth.session-token')?.value ??
cookies().get('__Secure-authjs.session-token')?.value ??
cookies().get('authjs.session-token')?.value ??
headers().get('Authorization')?.replace('Bearer ', '');
if (!token) {
return redirect('/api/auth/signin');
}
const session = await db
.select()
.from(sessions)
.where(eq(sessions.sessionToken, token!));
if (!session || session.length === 0) {
return redirect('/api/auth/signin');
}
const userContent = await db
.select()
.from(userStoredContent)
.where(eq(userStoredContent.userId, session[0].userId));
const userData = await db
.select()
.from(users)
.where(eq(users.id, session[0].userId))
.limit(1);
if (!userData || userData.length === 0) {
return redirect('/api/auth/signin');
}
const listOfContent =
userContent.map((content) => content.contentId).length > 0
? userContent.map((content) => content.contentId)
: [1];
const posts = await db
.select()
.from(storedContent)
.where(inArray(storedContent.id, listOfContent));
return (
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 flex flex-col items-center">
<div className="flex flex-col mt-16">
<div className="flex flex-col md:flex-row gap-4">
<Image
className="rounded-2xl"
src="/logo.png"
width={120}
height={120}
alt="logo"
/>
<div className="mt-4 text-gray-400 max-w-md">
<h1 className="text-xl font-bold text-white">SuperMemory</h1>
Remember that one thing you read a while ago? We got you covered.
Add the extension, click a button and I'll remember it for you.{' '}
<a
href="https://github.com/dhravyashah/anycontext"
target="_blank"
rel="noreferrer"
className="text-sky-500"
>
Get the Extension
</a>
</div>
</div>
</div>
<QueryAI />
<MessagePoster jwt={token} />
{/* TODO: LABEL THE WEBSITES USING A CLASSIFICATION MODEL */}
{/* <nav className="flex space-x-2 my-4">
<Badge variant="secondary">Technology (2)</Badge>
<Badge variant="secondary">Business & Finance (1)</Badge>
<Badge variant="secondary">Education & Career (1)</Badge>
</nav> */}
<main className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mt-16">
{posts.reverse().map((post) => (
<a
href={post.url}
target="_blank"
rel="noreferrer"
className="hover:scale-105 ease-in-out transition-transform duration-300"
>
<Card className="w-full">
<img
alt="Not found"
className="w-full h-48 object-cover rounded-md"
height="200"
src={
post.image && post.image !== 'Image not found'
? post.image
: '/placeholder.svg'
}
style={{
aspectRatio: '300/200',
objectFit: 'cover',
}}
width="300"
/>
<CardContent>
<h3 className="text-lg font-semibold mt-4">{post.title}</h3>
<p className="text-sm text-gray-600">{post.baseUrl}</p>
<p className="text-sm">{post.description}</p>
</CardContent>
</Card>
</a>
))}
</main>
</div>
);
}
|