2025-10-18 20:04:24 +00:00
|
|
|
|
import React, { useState } from 'react'
|
|
|
|
|
|
import { AnimatePresence } from 'framer-motion'
|
|
|
|
|
|
import PostItem from './PostItem'
|
|
|
|
|
|
import CreatePost from './CreatePost'
|
2025-10-29 19:24:40 +00:00
|
|
|
|
// import { mockSocialPosts } from '@/mocks/mockIntranet'
|
2025-10-27 21:08:36 +00:00
|
|
|
|
import { mockEmployees } from '@/mocks/mockEmployees'
|
2025-10-29 19:24:40 +00:00
|
|
|
|
import { EmployeeDto, SocialMediaDto, SocialPostDto } from '@/proxy/intranet/models'
|
2025-10-18 20:04:24 +00:00
|
|
|
|
|
2025-10-29 19:24:40 +00:00
|
|
|
|
const SocialWall: React.FC<{ posts: SocialPostDto[] }> = ({ posts }) => {
|
|
|
|
|
|
// const [posts, setPosts] = useState<SocialPost[]>(mockSocialPosts)
|
2025-10-18 20:04:24 +00:00
|
|
|
|
const [filter, setFilter] = useState<'all' | 'mine'>('all')
|
|
|
|
|
|
|
2025-10-27 21:08:36 +00:00
|
|
|
|
// Ali Öztürk'ü "Siz" kullanıcısı olarak kullan
|
2025-12-03 21:01:00 +00:00
|
|
|
|
const currentUserAuthor: EmployeeDto = { ...mockEmployees[0], name: 'Siz' }
|
2025-10-27 21:08:36 +00:00
|
|
|
|
|
2025-10-18 20:04:24 +00:00
|
|
|
|
const handleCreatePost = (postData: {
|
|
|
|
|
|
content: string
|
2025-10-28 10:57:32 +00:00
|
|
|
|
location?: string
|
2025-10-18 20:04:24 +00:00
|
|
|
|
media?: {
|
|
|
|
|
|
type: 'mixed' | 'poll'
|
2025-10-29 19:24:40 +00:00
|
|
|
|
mediaItems?: SocialMediaDto[]
|
2025-10-18 20:04:24 +00:00
|
|
|
|
poll?: {
|
|
|
|
|
|
question: string
|
|
|
|
|
|
options: Array<{ text: string }>
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}) => {
|
|
|
|
|
|
let mediaForPost = undefined
|
|
|
|
|
|
|
|
|
|
|
|
if (postData.media) {
|
|
|
|
|
|
if (postData.media.type === 'mixed' && postData.media.mediaItems) {
|
|
|
|
|
|
// Convert MediaItems to post format
|
2025-10-29 19:24:40 +00:00
|
|
|
|
const images = postData.media.mediaItems.filter((m) => m.type === 'image')
|
|
|
|
|
|
const videos = postData.media.mediaItems.filter((m) => m.type === 'video')
|
|
|
|
|
|
|
2025-10-18 20:04:24 +00:00
|
|
|
|
if (images.length > 0 && videos.length === 0) {
|
|
|
|
|
|
mediaForPost = {
|
|
|
|
|
|
type: 'image' as const,
|
2025-10-29 19:24:40 +00:00
|
|
|
|
urls: images.map((i) => i.urls?.[0]).filter((url) => url !== undefined) as string[],
|
2025-10-18 20:04:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
} else if (videos.length > 0 && images.length === 0) {
|
|
|
|
|
|
mediaForPost = {
|
|
|
|
|
|
type: 'video' as const,
|
2025-10-29 19:24:40 +00:00
|
|
|
|
urls: videos[0].urls || [],
|
2025-10-18 20:04:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
} else if (images.length > 0 || videos.length > 0) {
|
|
|
|
|
|
// Mixed media - use first image for now
|
|
|
|
|
|
mediaForPost = {
|
|
|
|
|
|
type: 'image' as const,
|
2025-10-29 19:24:40 +00:00
|
|
|
|
urls: images.map((i) => i.urls?.[0]).filter((url) => url !== undefined) as string[],
|
2025-10-18 20:04:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (postData.media.type === 'poll' && postData.media.poll) {
|
|
|
|
|
|
mediaForPost = {
|
|
|
|
|
|
type: 'poll' as const,
|
2025-10-28 10:57:32 +00:00
|
|
|
|
pollQuestion: postData.media.poll.question,
|
|
|
|
|
|
pollOptions: postData.media.poll.options.map((opt, index) => ({
|
|
|
|
|
|
id: `opt-${index}`,
|
|
|
|
|
|
text: opt.text,
|
2025-10-29 19:24:40 +00:00
|
|
|
|
votes: 0,
|
2025-10-28 10:57:32 +00:00
|
|
|
|
})),
|
|
|
|
|
|
pollTotalVotes: 0,
|
2025-10-29 19:24:40 +00:00
|
|
|
|
pollEndsAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
|
2025-10-18 20:04:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-29 19:24:40 +00:00
|
|
|
|
const newPost: SocialPostDto = {
|
2025-10-18 20:04:24 +00:00
|
|
|
|
id: Date.now().toString(),
|
2025-10-29 19:24:40 +00:00
|
|
|
|
employee: currentUserAuthor,
|
2025-10-18 20:04:24 +00:00
|
|
|
|
content: postData.content,
|
2025-10-20 18:38:21 +00:00
|
|
|
|
creationTime: new Date(),
|
2025-10-18 20:04:24 +00:00
|
|
|
|
media: mediaForPost,
|
2025-10-28 10:57:32 +00:00
|
|
|
|
locationJson: postData.location,
|
|
|
|
|
|
likeCount: 0,
|
|
|
|
|
|
isLiked: false,
|
|
|
|
|
|
likeUsers: [],
|
2025-10-18 20:04:24 +00:00
|
|
|
|
comments: [],
|
2025-10-29 19:24:40 +00:00
|
|
|
|
isOwnPost: true,
|
2025-10-18 20:04:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-29 19:24:40 +00:00
|
|
|
|
// setPosts([newPost, ...posts])
|
2025-10-18 20:04:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleLike = (postId: string) => {
|
2025-10-29 19:24:40 +00:00
|
|
|
|
// setPosts(
|
|
|
|
|
|
// posts.map((post) => {
|
|
|
|
|
|
// if (post.id === postId) {
|
|
|
|
|
|
// return {
|
|
|
|
|
|
// ...post,
|
|
|
|
|
|
// likeCount: post.isLiked ? post.likeCount - 1 : post.likeCount + 1,
|
|
|
|
|
|
// isLiked: !post.isLiked
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return post
|
|
|
|
|
|
// })
|
|
|
|
|
|
// )
|
2025-10-18 20:04:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleComment = (postId: string, content: string) => {
|
2025-10-29 19:24:40 +00:00
|
|
|
|
// setPosts(
|
|
|
|
|
|
// posts.map((post) => {
|
|
|
|
|
|
// if (post.id === postId) {
|
|
|
|
|
|
// const commentAuthor = currentUserAuthor
|
|
|
|
|
|
// const newComment = {
|
|
|
|
|
|
// id: Date.now().toString(),
|
|
|
|
|
|
// creator: commentAuthor,
|
|
|
|
|
|
// content,
|
|
|
|
|
|
// creationTime: new Date()
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return {
|
|
|
|
|
|
// ...post,
|
|
|
|
|
|
// comments: [...post.comments, newComment]
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return post
|
|
|
|
|
|
// })
|
|
|
|
|
|
// )
|
2025-10-18 20:04:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleDelete = (postId: string) => {
|
|
|
|
|
|
if (window.confirm('Bu gönderiyi silmek istediğinizden emin misiniz?')) {
|
2025-10-29 19:24:40 +00:00
|
|
|
|
// setPosts(posts.filter((post) => post.id !== postId))
|
2025-10-18 20:04:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleVote = (postId: string, optionId: string) => {
|
2025-10-29 19:24:40 +00:00
|
|
|
|
// setPosts(
|
|
|
|
|
|
// posts.map((post) => {
|
|
|
|
|
|
// if (post.id === postId && post.media?.type === 'poll' && post.media.pollOptions) {
|
|
|
|
|
|
// // If user already voted, don't allow voting again
|
|
|
|
|
|
// if (post.media.pollUserVoteId) {
|
|
|
|
|
|
// return post
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return {
|
|
|
|
|
|
// ...post,
|
|
|
|
|
|
// media: {
|
|
|
|
|
|
// ...post.media,
|
|
|
|
|
|
// pollOptions: post.media.pollOptions.map((opt) =>
|
|
|
|
|
|
// opt.id === optionId ? { ...opt, votes: opt.votes + 1 } : opt
|
|
|
|
|
|
// ),
|
|
|
|
|
|
// pollTotalVotes: (post.media.pollTotalVotes || 0) + 1,
|
|
|
|
|
|
// pollUserVoteId: optionId
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return post
|
|
|
|
|
|
// })
|
|
|
|
|
|
// )
|
2025-10-18 20:04:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const filteredPosts = filter === 'mine' ? posts.filter((post) => post.isOwnPost) : posts
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2025-10-20 13:11:46 +00:00
|
|
|
|
<div className="mx-auto px-4">
|
2025-10-18 20:04:24 +00:00
|
|
|
|
{/* Filter Tabs */}
|
|
|
|
|
|
<div className="flex gap-4 mb-6 border-b border-gray-200 dark:border-gray-700">
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => setFilter('all')}
|
|
|
|
|
|
className={`pb-3 px-1 border-b-2 transition-colors font-medium ${
|
|
|
|
|
|
filter === 'all'
|
|
|
|
|
|
? 'border-blue-600 text-blue-600'
|
|
|
|
|
|
: 'border-transparent text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200'
|
|
|
|
|
|
}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
Tüm Gönderiler
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => setFilter('mine')}
|
|
|
|
|
|
className={`pb-3 px-1 border-b-2 transition-colors font-medium ${
|
|
|
|
|
|
filter === 'mine'
|
|
|
|
|
|
? 'border-blue-600 text-blue-600'
|
|
|
|
|
|
: 'border-transparent text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200'
|
|
|
|
|
|
}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
Gönderilerim
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Create Post */}
|
|
|
|
|
|
<CreatePost onCreatePost={handleCreatePost} />
|
|
|
|
|
|
|
|
|
|
|
|
{/* Posts Feed */}
|
|
|
|
|
|
<AnimatePresence>
|
|
|
|
|
|
{filteredPosts.length > 0 ? (
|
|
|
|
|
|
filteredPosts.map((post) => (
|
|
|
|
|
|
<PostItem
|
|
|
|
|
|
key={post.id}
|
|
|
|
|
|
post={post}
|
|
|
|
|
|
onLike={handleLike}
|
|
|
|
|
|
onComment={handleComment}
|
|
|
|
|
|
onDelete={handleDelete}
|
|
|
|
|
|
onVote={handleVote}
|
|
|
|
|
|
/>
|
|
|
|
|
|
))
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="text-center py-12">
|
|
|
|
|
|
<p className="text-gray-500 dark:text-gray-400 text-lg">
|
|
|
|
|
|
{filter === 'mine' ? 'Henüz bir gönderi paylaşmadınız.' : 'Henüz gönderi yok.'}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</AnimatePresence>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default SocialWall
|