Skip to content

Commit

Permalink
fix mostly
Browse files Browse the repository at this point in the history
  • Loading branch information
docimin committed Aug 23, 2024
1 parent 587d3ed commit 39e92be
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 20 deletions.
10 changes: 8 additions & 2 deletions src/app/[locale]/(account)/account/gallery/[galleryId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createAdminClient } from '@/app/appwrite-session'
import { Gallery } from '@/utils/types/models'
import PageLayout from '@/components/pageLayout'
import { getUser } from '@/utils/server-api/account/user'
import { redirect } from '@/navigation'

export const runtime = 'edge'

Expand All @@ -14,7 +15,13 @@ export const metadata = {
export default async function AccountSingleGalleryPage({
params: { galleryId },
}) {
const userData = await getUser()
let userData = null
try {
userData = await getUser()
} catch (error) {
return redirect('/login')
}

const userId = userData?.$id

const { databases } = await createAdminClient()
Expand All @@ -31,7 +38,6 @@ export default async function AccountSingleGalleryPage({
const galleryUserId = singleGallery?.userId

if (!galleryUserId) return notFound() // Wait for userId to be available
if (!userId) return notFound() // Wait for userId to be available

if (userId !== galleryUserId) {
return notFound()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ export function FollowerButton({ displayName, communityId }) {

useEffect(() => {
const getUserId = async () => {
const data = await account.get()
setUserId(data.$id)
try {
const data = await account.get()
setUserId(data?.$id)
} catch (error) {
setUserId(null)
}
}
getUserId().then()
}, [])
Expand Down
10 changes: 8 additions & 2 deletions src/app/[locale]/(main)/gallery/[galleryId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ export const runtime = 'edge'

export default async function GalleryPage({ params: { galleryId } }) {
const { databases } = await createSessionServerClient()
const userSelf = await getUser()
const enableNsfw = userSelf?.prefs?.nsfw || false
let userSelf = null
let enableNsfw = false
try {
userSelf = await getUser()
enableNsfw = userSelf?.prefs?.nsfw
} catch (e) {
// do nothing
}

const gallery: Gallery.GalleryType = await databases.listDocuments(
'hp_db',
Expand Down
9 changes: 7 additions & 2 deletions src/app/[locale]/(main)/gallery/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ function UploadButton() {
}

export default async function Gallery() {
const accountData = await getUser()
const enableNsfw = accountData?.prefs?.nsfw
let enableNsfw = false
try {
const accountData = await getUser()
enableNsfw = accountData?.prefs?.nsfw
} catch (e) {
// do nothing
}

return (
<PageLayout title={'Gallery'} middleComponent={<UploadButton />}>
Expand Down
7 changes: 4 additions & 3 deletions src/app/[locale]/(main)/gallery/upload/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { redirect } from '@/navigation'
export const runtime = 'edge'

export default async function Page() {
const user = await getUser()

if (!user.$id) {
let user = null
try {
user = await getUser()
} catch (e) {
return redirect('/login')
}

Expand Down
23 changes: 14 additions & 9 deletions src/app/[locale]/(user)/user/[profileUrl]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ export async function generateMetadata({

export default async function UserProfile({ params: { profileUrl } }) {
const { databases } = await createSessionServerClient()
const account = await getUser()
let account = null
try {
account = await getUser()
} catch (error) {
// User is not logged in
}

const userDataResponse: UserData.UserDataType = await databases.listDocuments(
'hp_db',
Expand All @@ -80,7 +85,7 @@ export default async function UserProfile({ params: { profileUrl } }) {
const userData = userDataResponse.documents[0]
const followers = await getFollowers(userData.$id, 0, 5000000)
const following = await getFollowing(userData.$id, 0, 5000000)
const isFollowingResponse = await getIsFollowing(account.$id, userData.$id)
const isFollowingResponse = await getIsFollowing(account?.$id, userData?.$id)
const isFollowing = isFollowingResponse?.documents?.length > 0 || false

const totalFollowers: number = followers?.length
Expand Down Expand Up @@ -211,20 +216,20 @@ export default async function UserProfile({ params: { profileUrl } }) {
{userData.displayName}
</CardTitle>
<FollowerButton
userId={account.$id}
displayName={userData.displayName}
userId={account?.$id}
displayName={userData?.displayName}
followerId={userData.$id}
isFollowing={isFollowing}
/>
</div>
<div className={'grid grid-cols-2'}>
<CardDescription>{userData.status}</CardDescription>
<CardDescription>{userData?.status}</CardDescription>
</div>
<CardDescription className={'flex pt-4 gap-4'}>
<Link
href={{
pathname: '/user/[profileUrl]/following',
params: { profileUrl: userData.profileUrl },
params: { profileUrl: userData?.profileUrl },
}}
>
<Button variant={'link'} className={'p-0'}>
Expand All @@ -239,7 +244,7 @@ export default async function UserProfile({ params: { profileUrl } }) {
<Link
href={{
pathname: '/user/[profileUrl]/followers',
params: { profileUrl: userData.profileUrl },
params: { profileUrl: userData?.profileUrl },
}}
>
{' '}
Expand All @@ -257,11 +262,11 @@ export default async function UserProfile({ params: { profileUrl } }) {
<Separator className={'mb-6'} />
<CardContent>
<div className={'grid grid-cols-2 mx-auto gap-4'}>
{userData.pronouns && (
{userData?.pronouns && (
<>
<div className={'col-span-1'}>Pronouns</div>
<div className="rounded-md border px-4 py-3 font-mono text-sm col-span-1">
{userData.pronouns}
{userData?.pronouns}
</div>
</>
)}
Expand Down

0 comments on commit 39e92be

Please sign in to comment.