Skip to content

Commit

Permalink
Refactor code to use 'timestamp' instead of 'time' in ChatTalkContent
Browse files Browse the repository at this point in the history
  • Loading branch information
tako0614 committed Jul 15, 2024
1 parent 23b9931 commit 0df75fd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions components/chatmain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function chatmain({ state }: { state: AppStateType }) {
</div>
<ChatTalkTitleContent state={state}></ChatTalkTitleContent>
</div>
<div class="mt-[54px]"></div>
<ChatTalkContent state={state} />
</div>
<ChatSend state={state} />
Expand Down
23 changes: 12 additions & 11 deletions islands/ChatTalkContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ interface Messages {
messageid: string;
userName: string;
messages: string;
time: string;
timestamp: string;
type: string;
}
function ChatTalkMain({ state }: { state: AppStateType }) {
let SendPrimary = true;
Expand All @@ -15,25 +16,25 @@ function ChatTalkMain({ state }: { state: AppStateType }) {
return (
<>
{state.talkData.value.map((data: any, index: number) => {
const date = new Date(data.time);
const date = new Date(data.timestamp);
const isEncodeDate = new Date(DateState).toLocaleDateString() !==
date.toLocaleDateString();
DateState = data.time;
if (data.type == "message") {
if (data.sender == state.userName) {
DateState = data.timestamp;
if (data.type == "text") {
if (data.userName == state.userName) {
if (SendPrimary) {
SendPrimary = false;
OtherPrimary = true;
return (
<>
{isEncodeDate && (
<ChatDate
date={new Date(data.time)}
date={new Date(data.timestamp)}
/>
)}
<ChatSendMessage
isRead={data.isRead}
time={data.time}
time={data.timestamp}
message={data.message}
isPrimary={true}
isSendPrimary={true}
Expand All @@ -48,12 +49,12 @@ function ChatTalkMain({ state }: { state: AppStateType }) {
<>
{isEncodeDate && (
<ChatDate
date={new Date(data.time)}
date={new Date(data.timestamp)}
/>
)}
<ChatSendMessage
isRead={data.isRead}
time={data.time}
time={data.timestamp}
message={data.message}
isPrimary={true}
isSendPrimary={false}
Expand All @@ -66,12 +67,12 @@ function ChatTalkMain({ state }: { state: AppStateType }) {
<>
{isEncodeDate && (
<ChatDate
date={new Date(data.time)}
date={new Date(data.timestamp)}
/>
)}
<ChatSendMessage
isRead={data.isRead}
time={data.time}
time={data.timestamp}
message={data.message}
isPrimary={false}
isSendPrimary={false}
Expand Down
6 changes: 3 additions & 3 deletions routes/api/v2/client/talks/friend/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const handler = {
userName: CacheUser.userName,
message: message.message,
timestamp: message.timestamp,
type: message.type,
type: message.messageType,
};
}
}
Expand All @@ -106,7 +106,7 @@ export const handler = {
userName: "Unknown",
message: message.message,
timestamp: message.timestamp,
type: message.type,
type: message.messageType,
};
}
}
Expand All @@ -117,7 +117,7 @@ export const handler = {
userName: userInfo?.userName,
message: message.message,
timestamp: message.timestamp,
type: message.type,
type: message.messageType,
};
}
}));
Expand Down

0 comments on commit 0df75fd

Please sign in to comment.