Skip to content

Commit

Permalink
add status, add opengraph
Browse files Browse the repository at this point in the history
  • Loading branch information
docimin committed Oct 1, 2024
1 parent a8fc5f7 commit ec42a98
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
10 changes: 8 additions & 2 deletions src/app/[locale]/(main)/community/[communityId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getCommunity } from '@/utils/server-api/communities/getCommunity'
import PageClient from './page.client'
import { notFound } from 'next/navigation'
import { getCommunityAvatarUrlView } from '@/components/getStorageItem'

export const runtime = 'edge'

Expand All @@ -15,16 +16,21 @@ export async function generateMetadata({
return notFound()
}

let avatarUrl = '/logos/Headpat_Logo_web_1024x1024_240518-02.png'
if (community.avatarId) {
avatarUrl = getCommunityAvatarUrlView(community.avatarId)
}

return {
title: community?.name || 'Community',
description: community?.description,
icons: {
icon: '/logos/Headpat_Logo_web_1024x1024_240518-02.png',
icon: avatarUrl,
},
openGraph: {
title: community?.name || 'Community',
description: community?.description,
images: '/logos/Headpat_Logo_web_1024x1024_240518-02.png',
images: avatarUrl,
},
}
}
Expand Down
31 changes: 28 additions & 3 deletions src/components/community/admin/main.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use client'
import { Community } from '@/utils/types/models'
import { databases, functions } from '@/app/appwrite-client'
import { ExecutionMethod } from 'node-appwrite'
import { databases } from '@/app/appwrite-client'
import { useEffect, useState } from 'react'
import NoAccess from '@/components/static/noAccess'
import UploadAvatar from '@/components/community/uploadAvatar'
import UploadBanner from '@/components/community/uploadBanner'
import { Label } from '@/components/ui/label'
Expand Down Expand Up @@ -133,6 +131,33 @@ export default function CommunityAdminMain({
</div>
</div>
</div>

<div className="col-span-full">
<Label htmlFor="status">Status</Label>
<div className="relative mt-2">
<Input
id="status"
name="status"
type="text"
value={communityData ? communityData.status : ''}
onChange={(e) => {
if (e.target.value.length <= 24) {
setCommunityData({
...communityData,
status: e.target.value,
})
}
}}
maxLength={24}
/>
<div className="absolute inset-y-0 right-0 flex items-center pr-3 text-sm leading-5">
<span className="select-none">
{communityData ? communityData.status?.length : 0}
</span>
<span className="select-none text-gray-400">/{24}</span>
</div>
</div>
</div>
</div>

<div className="mt-8 flex">
Expand Down
19 changes: 10 additions & 9 deletions src/components/community/uploadAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,11 @@ export default function UploadAvatar({
const scale = 1
const rotate = 0
const aspect = 1
const maxSizeInBytes = 1024 * 1024 // 1 MB

function onSelectFile(e: React.ChangeEvent<HTMLInputElement>) {
if (e.target.files && e.target.files.length > 0) {
const file = e.target.files[0]
const maxSizeInBytes = 1024 * 1024 // 1 MB

if (file.size > maxSizeInBytes) {
toast.error('File size exceeds the 1 MB limit.')
if (fileInputRef.current) {
fileInputRef.current.value = '' // Reset the input field
}
return
}

setOpen(true)
setCrop(undefined) // Makes crop preview update between images.
Expand Down Expand Up @@ -91,6 +83,15 @@ export default function UploadAvatar({
try {
const file = formData.get('file') as File

if (file.size > maxSizeInBytes) {
toast.dismiss(loadingToast)
toast.error('File size exceeds the 1 MB limit.')
if (fileInputRef.current) {
fileInputRef.current.value = '' // Reset the input field
}
return
}

setIsUploading(true)

const data = await functions.createExecution(
Expand Down
1 change: 1 addition & 0 deletions src/components/community/uploadBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default function UploadBanner({
const file = formData.get('file') as File

if (file.size > maxSizeInBytes) {
toast.dismiss(loadingToast)
toast.error('File size exceeds the 5 MB limit.')
if (fileInputRef.current) {
fileInputRef.current.value = '' // Reset the input field
Expand Down

0 comments on commit ec42a98

Please sign in to comment.