Skip to content

Commit

Permalink
move models, fix users page, add followers & following
Browse files Browse the repository at this point in the history
  • Loading branch information
docimin committed Jun 22, 2024
1 parent 984c8e3 commit 1281b6b
Show file tree
Hide file tree
Showing 33 changed files with 475 additions and 312 deletions.
8 changes: 5 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@
"next-themes": "^0.3.0",
"node-appwrite": "^13.0.0",
"postcss": "^8.4.38",
"prettier": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.4",
"react": "18.3.1",
"react-day-picker": "^8.10.1",
"react-dom": "18.3.1",
Expand All @@ -89,6 +87,8 @@
},
"devDependencies": {
"@types/node": "20.14.2",
"@types/react": "18.3.3"
"@types/react": "18.3.3",
"prettier": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { Textarea } from '@/components/ui/textarea'
import { Button } from '@/components/ui/button'
import { Label } from '@/components/ui/label'
import { databases, Query, storage } from '@/app/appwrite-client'
import { GalleryType } from '@/utils/types'
import { useToast } from '@/components/ui/use-toast'
import * as Sentry from '@sentry/nextjs'
import { useRouter } from 'next/navigation'
import { Gallery } from '@/utils/types/models'

export default function FetchGallery({ singleGallery }) {
const { toast } = useToast()
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function FetchGallery({ singleGallery }) {
)

listDataResponse.then(
function (response: GalleryType) {
function (response: Gallery.GalleryType) {
const documentId = response.documents[0].$id
const imageId = response.documents[0].galleryId

Expand Down
9 changes: 3 additions & 6 deletions src/app/[lang]/(account)/account/gallery/[galleryId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Client from './page.client'
import { notFound } from 'next/navigation'
import { headers } from 'next/headers'
import { createAdminClient } from '@/app/appwrite-session'
import { GalleryDocumentsType } from '@/utils/types'
import { Gallery } from '@/utils/types/models'

export const runtime = 'edge'

Expand Down Expand Up @@ -31,11 +31,8 @@ export default async function AccountSingleGalleryPage({
const userId = userData?.$id

const { databases } = await createAdminClient()
const singleGallery: GalleryDocumentsType = await databases.getDocument(
'hp_db',
'gallery-images',
galleryId
)
const singleGallery: Gallery.GalleryDocumentsType =
await databases.getDocument('hp_db', 'gallery-images', galleryId)

const galleryUserId = singleGallery?.userId

Expand Down
4 changes: 2 additions & 2 deletions src/app/[lang]/(account)/account/page.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import {
changePreferences,
changeProfileUrl,
} from '@/utils/actions/account/account'
import { UserAccountType } from '@/utils/types/account'
import { Account } from '@/utils/types/models'

export default function AccountPage({
accountData,
mfaList,
userData,
}: {
accountData: UserAccountType
accountData: Account.AccountPrefs
mfaList: Models.MfaFactors
userData: any
}) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/[lang]/(main)/announcements/[announcementId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Link from 'next/link'
import { AnnouncementDocumentsType } from '@/utils/types'
import { createAdminClient } from '@/app/appwrite-session'
import { Announcements } from '@/utils/types/models'

export const runtime = 'edge'

Expand All @@ -22,7 +22,7 @@ export default async function Page({
}) {
const { databases } = await createAdminClient()

const announcementData: AnnouncementDocumentsType =
const announcementData: Announcements.AnnouncementDocumentsType =
await databases.getDocument('hp_db', 'announcements', announcementId)

return (
Expand Down
4 changes: 2 additions & 2 deletions src/app/[lang]/(main)/announcements/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Link from 'next/link'
import { AnnouncementDataType } from '@/utils/types'
import { ChevronRight, MegaphoneIcon } from 'lucide-react'
import { createAdminClient } from '@/app/appwrite-session'
import { Announcements } from '@/utils/types/models'

export const runtime = 'edge'

Expand All @@ -12,7 +12,7 @@ export const metadata = {

export default async function AnnouncementsPage() {
const { databases } = await createAdminClient()
const announcementDataResponse: AnnouncementDataType =
const announcementDataResponse: Announcements.AnnouncementDataType =
await databases.listDocuments('hp_db', 'announcements')
const announcementData = announcementDataResponse.documents

Expand Down
11 changes: 5 additions & 6 deletions src/app/[lang]/(main)/gallery/[galleryId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import Client from './page.client'
import { notFound } from 'next/navigation'
import { GalleryDocumentsType, GalleryType } from '@/utils/types'
import Link from 'next/link'
import { Button } from '@/components/ui/button'
import { createSessionServerClient } from '@/app/appwrite-session'
import { Query } from '@/app/appwrite-server'
import { getUser } from '@/utils/server-api/account/user'
import { UserDataType } from '@/utils/types/userData'
import { Gallery, UserData } from '@/utils/types/models'

export const metadata = {
title: 'Gallery',
Expand All @@ -16,12 +15,12 @@ export const metadata = {

export const runtime = 'edge'

export default async function Gallery({ params: { galleryId } }) {
export default async function GalleryPage({ params: { galleryId } }) {
const { account, databases } = await createSessionServerClient()

Check warning on line 19 in src/app/[lang]/(main)/gallery/[galleryId]/page.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused local symbol

Unused constant account
const userSelf = await getUser()
const enableNsfw = userSelf?.prefs?.nsfw || false

const gallery: GalleryType = await databases.listDocuments(
const gallery: Gallery.GalleryType = await databases.listDocuments(
'hp_db',
'gallery-images',
[Query.equal('$id', galleryId)]
Expand All @@ -30,11 +29,11 @@ export default async function Gallery({ params: { galleryId } }) {
if (!gallery.documents) {
return notFound()
}
const galleryData: GalleryDocumentsType = gallery.documents[0]
const galleryData: Gallery.GalleryDocumentsType = gallery.documents[0]

const userId = galleryData?.userId
//const userData = await getUserData(`queries[]=equal("$id","${userId}")`)
const userDataResponse: UserDataType = await databases.listDocuments(
const userDataResponse: UserData.UserDataType = await databases.listDocuments(
'hp_db',
'userdata',
[Query.equal('$id', userId)]
Expand Down
10 changes: 5 additions & 5 deletions src/app/[lang]/(main)/users/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
import { CakeIcon, CalendarDays } from 'lucide-react'
import Image from 'next/image'
import PageLayout from '@/components/pageLayout'
import { UserDataDocumentsType } from '@/utils/types/userData'
import { UserData } from '@/utils/types/models'

export const runtime = 'edge'

Expand All @@ -35,7 +35,7 @@ export default async function Users() {
'grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 2xl:grid-cols-7 3xl:grid-cols-8 5xl:grid-cols-10 gap-4 xl:gap-6 p-4 mx-auto'
}
>
{users.map((user: UserDataDocumentsType) => {
{users.map((user: UserData.UserDataDocumentsType) => {
const today = formatDate(new Date())
const birthday = user.birthday
? formatDate(new Date(user.birthday))
Expand All @@ -45,7 +45,7 @@ export default async function Users() {

return (
<Card className={'border-none h-40 w-40 mx-auto'} key={user.$id}>
<HoverCard>
<HoverCard openDelay={100} closeDelay={100}>
<HoverCardTrigger asChild>
<Link href={`/user/${user.profileUrl}`}>
{user.avatarId ? (
Expand All @@ -57,8 +57,8 @@ export default async function Users() {
height={1000}
/>
) : (
<div className="h-full w-full bg-gray-200 rounded-md flex items-center justify-center text-wrap truncate">
<p className="text-gray-400 text-center">
<div className="h-full w-full bg-gray-200 rounded-md flex items-center justify-center">
<p className="text-gray-400 text-center font-mono truncate px-2">
{user.displayName}
</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,36 @@ import Link from 'next/link'
import Image from 'next/image'
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
import { CakeIcon, CalendarDays } from 'lucide-react'
import { getFriends } from '@/utils/server-api/friends/getFriends'
import { getUser } from '@/utils/server-api/account/user'
import { UserDataDocumentsType } from '@/utils/types/userData'
import { UserData } from '@/utils/types/models'
import { getFollowers } from '@/utils/server-api/followers/getFollowers'

export const runtime = 'edge'

export default async function FriendsPage() {
export default async function FollowerPage() {
const { databases } = await createSessionServerClient()

const accountData = await getUser()
const followers = await getFollowers(accountData.$id)

if (accountData) {
return (
<PageLayout title={'Friends'}>
<div className={'flex flex-1 justify-center items-center h-full'}>
<div className={'p-4 gap-6 text-center'}>
<h1 className={'text-2xl font-semibold'}>Not logged in</h1>
<p className={'text-muted-foreground'}>
You must be logged in to view your friends.
</p>
</div>
</div>
</PageLayout>
)
}

const friends = await getFriends(accountData.$id)

// For each friend, look up their user data
const friendsData = await Promise.all(
friends.friends.map(async (friendId) => {
return await databases.getDocument('hp_db', 'userdata', friendId)
// For each follower, look up their user data
const followerData = await Promise.all(
followers.documents.map(async (follower) => {
return await databases.getDocument(
'hp_db',
'userdata',
follower.followerId
)
})
)

if (!friendsData) {
if (!followerData) {
return (
<PageLayout title={'Friends'}>
<div className={'flex flex-1 justify-center items-center h-full'}>
<div className={'p-4 gap-6 text-center'}>
<h1 className={'text-2xl font-semibold'}>No friends found</h1>
<h1 className={'text-2xl font-semibold'}>No followers found</h1>
<p className={'text-muted-foreground'}>
You don&apos;t have any friends yet. Make some friends by
connecting with other users.
They don&apos;t have any followers yet.
</p>
</div>
</div>
Expand All @@ -70,13 +56,13 @@ export default async function FriendsPage() {
}

return (
<PageLayout title={'Friends'}>
<PageLayout title={'Followers'}>
<div
className={
'grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 2xl:grid-cols-7 3xl:grid-cols-8 5xl:grid-cols-10 gap-4 xl:gap-6 p-4 mx-auto'
}
>
{friendsData.map((user: UserDataDocumentsType) => {
{followerData.map((user: UserData.UserDataDocumentsType) => {
const today = formatDate(new Date())
const birthday = user.birthday
? formatDate(new Date(user.birthday))
Expand Down
Loading

0 comments on commit 1281b6b

Please sign in to comment.