Skip to content

Commit

Permalink
Merge pull request #70 from MOVIEJOJO7/feature/#67
Browse files Browse the repository at this point in the history
Feat : Private, Public 채팅방 정렬 순서 변경
  • Loading branch information
LikeFireAndSky authored Nov 15, 2023
2 parents 6a3e04f + 4cc76a8 commit 56d5270
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Components/Open/ChatList/ChatItem/ChatItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import OpenPeopleSvg from '@/public/OpenPeopleSvg.svg';
import { ChatItemProps } from '../ChatList.type';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { koreanTime } from '@/utils/changeKoreanTime';

const ChatItem = ({ chat }: ChatItemProps) => {
const firstUserImage = chat.users[0].picture;
Expand Down Expand Up @@ -58,12 +59,12 @@ const ChatItem = ({ chat }: ChatItemProps) => {
{`${chat.users.length}명 참여중`}
</Typography>
<Typography variant="small" color="gray" className="font-normal">
{chat.messages
? chat.messages[chat.messages.length]?.text
{chat.latestMessage
? chat.latestMessage.text
: '아직 채팅이 없습니다.'}
</Typography>
<Typography variant="small" color="gray" className="font-normal">
{`${chat.updatedAt}`}
{`${koreanTime(chat.updatedAt)}`}
</Typography>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/private/chatting.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type Chat = {
users: User[];
messages: Message[]; // message 객체가 속합니다.
updatedAt: Date;
latestMessage?: Message;
indexId?: number;
};

Expand Down
7 changes: 7 additions & 0 deletions app/private/chatting.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ export const fetchAllChat = async (token: string) => {
};

export const filterChat = (chatList: Chat[]) => {
// Date기준으로 정렬
chatList.sort((oldest: Chat, latest: Chat) => {
if (oldest.updatedAt > latest.updatedAt) return -1;
if (oldest.updatedAt < latest.updatedAt) return 1;
return 0;
});

const PersonalChat = chatList.filter(
(chat: Chat) => chat.isPrivate === true && chat.users.length === 2,
);
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"axios": "^1.6.0",
"bcryptjs": "^2.4.3",
"cloudinary": "^1.41.0",
"moment-timezone": "^0.5.43",
"next": "14.0.1",
"react": "^18",
"react-cookie": "^6.1.1",
Expand Down
3 changes: 3 additions & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const config: Config = withMT({
},
backgroundSize: {
'50%': '50%',
contain: 'contain',
cover: 'cover',
fill: 'fill',
},
extend: {
colors: {
Expand Down
7 changes: 7 additions & 0 deletions utils/changeKoreanTime.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use client';

import moment from 'moment-timezone';

export const koreanTime = (dateString: Date) => {
return moment(dateString).tz('Asia/Seoul').format('YYYY-MM-DD HH:mm:ss');
};

0 comments on commit 56d5270

Please sign in to comment.