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

fix:fixed chat date separator issue on day's first message #1209

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
67 changes: 39 additions & 28 deletions packages/screens/Mini/Conversation/components/Conversations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,35 @@ export const Conversations = ({
);
}

const renderDateSeparator = (separatorDate: string) => {
return (
<View
style={{
position: "relative",
flexDirection: "row",
justifyContent: "center",
marginTop: layout.spacing_x2,
}}
>
<Separator style={{ position: "absolute", top: 10 }} />
<BrandText
style={[
fontSemibold14,
{
backgroundColor: neutral00,
zIndex: 10,
paddingHorizontal: layout.spacing_x2,
textAlign: "center",
marginBottom: layout.spacing_x3,
},
]}
>
{moment(separatorDate).format("L")}
</BrandText>
</View>
);
};

return (
<>
<View
Expand All @@ -138,9 +167,10 @@ export const Conversations = ({
index < messages.length - 1 ? messages[index + 1] : undefined;

const separatorDate = previousMessage
? moment(item.timestamp).format("DD/MM/YYYY") !==
moment(previousMessage.timestamp).format("DD/MM/YYYY") &&
item.timestamp
? moment(item.timestamp).format("L") ===
moment(previousMessage.timestamp).format("L")
? false
: item?.timestamp
: item.timestamp;

if (item.type === "group-join") {
Expand All @@ -155,31 +185,9 @@ export const Conversations = ({
: undefined;
return (
<>
{!!separatorDate && (
<View
style={{
position: "relative",
flexDirection: "row",
justifyContent: "center",
}}
>
<Separator style={{ position: "absolute", top: 10 }} />
<BrandText
style={[
fontSemibold14,
{
backgroundColor: neutral00,
zIndex: 10,
paddingHorizontal: layout.spacing_x2,
textAlign: "center",
marginBottom: layout.spacing_x3,
},
]}
>
{moment(separatorDate).format("YYYY, MMM DD")}
</BrandText>
</View>
)}
{!!separatorDate &&
!previousMessage &&
renderDateSeparator(separatorDate)}
{item.type === "accept-contact" && !previousMessage && (
<View style={{ marginBottom: layout.spacing_x5 }}>
<View
Expand Down Expand Up @@ -242,6 +250,9 @@ export const Conversations = ({
}
/>
)}
{!!separatorDate &&
previousMessage &&
renderDateSeparator(separatorDate)}
</>
);
}}
Expand Down
Loading