Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat : Private, Public 채팅방 정렬 순서 변경 #70

Merged
merged 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
};
Loading