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

Uniformisation entre #624 et #669 #672

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 1 addition & 11 deletions src/views/account/Home/Elements/HomeworksElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,7 @@ const HomeworksElement: React.FC<HomeworksElementProps> = ({ navigation, onImpor
const hwSemaineActuelle = homeworks[dateToEpochWeekNumber(actualDay)]?.filter(
(hw) => hw.due / 1000 >= startTime && hw.due / 1000 <= endTime
) ?? [];
const truncateContent = (content: string) => {
if (content.length <= 120) {
return content;
}
const truncated = content.slice(0, 120);
const lastSpaceIndex = truncated.lastIndexOf(" ");
return `${truncated.slice(0, lastSpaceIndex)}...`;
};
hwSemaineActuelle.forEach(hw => {
hw.content = truncateContent(hw.content);
});

const hwSemaineProchaine = homeworks[dateToEpochWeekNumber(actualDay) + 1]?.filter(
(hw) => hw.due / 1000 >= startTime && hw.due / 1000 <= endTime
) ?? [];
Expand Down
37 changes: 16 additions & 21 deletions src/views/account/Homeworks/Atoms/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ const HomeworkItem = ({ homework, navigation, onDonePressHandler, index, total }

const route = useRoute();

const MAX_LENGTH = 120;

const stylesText = StyleSheet.create({
body: {
color: homework.done ? theme.colors.text + "80" : theme.colors.text,
fontFamily: "medium",
fontSize: 16,
lineHeight: 22,
maxHeight: 22 * 5,
},
});

Expand Down Expand Up @@ -74,7 +75,19 @@ const HomeworkItem = ({ homework, navigation, onDonePressHandler, index, total }
setMainLoaded(true);
}, [homework.done]);

const contentLines = homework.content.split("\n");
const truncateContent = (content: string): string => {
if (content.length <= MAX_LENGTH) {
return content;
}

const sanitized = content.replace(/(\n|<br>)/g, "");

const truncated = sanitized.slice(0, MAX_LENGTH);

const lastSpaceIndex = truncated.lastIndexOf(" ");

return `${truncated.slice(0, lastSpaceIndex)}…`;
};

const renderCategoryOrReturnType = () => {
if (category) {
Expand Down Expand Up @@ -104,7 +117,6 @@ const HomeworkItem = ({ homework, navigation, onDonePressHandler, index, total }
fill={"#FFF"}
color="#FFF"
/>

<NativeText style={{
color: "#FFF",
fontFamily: "semibold",
Expand All @@ -115,7 +127,6 @@ const HomeworkItem = ({ homework, navigation, onDonePressHandler, index, total }
>
{category}
</NativeText>

</View>
</LinearGradient>
);
Expand Down Expand Up @@ -188,23 +199,7 @@ const HomeworkItem = ({ homework, navigation, onDonePressHandler, index, total }
entering={FadeIn.duration(200)}
exiting={FadeOut.duration(200).delay(50)}
>

<View style={{ position: "relative" }}>
<HTMLView value={`<body>${parse_homeworks(homework.content).replace("\n", "")}</body>`} stylesheet={stylesText} />
{contentLines.length > 5 && (
<LinearGradient
colors={[theme.colors.background + "00", theme.colors.background + "80"]}
style={{
position: "absolute",
top: 0,
left: 0,
right: 0,
height: "100%",
zIndex: 1,
}}
/>
)}
</View>
<HTMLView value={`<body>${parse_homeworks(truncateContent(homework.content))}</body>`} stylesheet={stylesText} />
{route.name === "HomeScreen" && (
<View style={{ flex: 1, flexDirection: "row", gap: 4, paddingBottom: 4, paddingTop: 8, alignItems: "center", alignSelf: "flex-start" }}>
<Clock
Expand Down
Loading