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

Add News Image Above Title #635

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
33 changes: 29 additions & 4 deletions src/views/account/News/Atoms/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useTheme } from "@react-navigation/native";
import React from "react";
import { View } from "react-native";
import { Image, StyleSheet, View } from "react-native";
import { NativeItem, NativeText } from "@/components/Global/NativeComponents";
import parse_news_resume from "@/utils/format/format_pronote_news";
import formatDate from "@/utils/format/format_date_complets";
import { NativeStackNavigationProp } from "@react-navigation/native-stack";
import { RouteParameters } from "@/router/helpers/types";
import { Information } from "@/services/shared/Information";
import { AttachmentType } from "@/services/shared/Attachment";

type NewsItem = Omit<Information, "date"> & { date: string, important: boolean };

Expand All @@ -20,6 +21,16 @@ interface NewsListItemProps {

const NewsListItem: React.FC<NewsListItemProps> = ({ index, message, navigation, parentMessages, isED }) => {
const theme = useTheme();
const newsImage = message.attachments.find((attachment) => {
if (attachment.type !== AttachmentType.File) {
return;
}
const extension = attachment.name.split(".").pop()?.split("?")[0].toLowerCase();
if (!extension) {
return;
}
return ["jpg", "jpeg", "png"].includes(extension);
});
return (
<NativeItem
onPress={() => {
Expand All @@ -32,6 +43,13 @@ const NewsListItem: React.FC<NewsListItemProps> = ({ index, message, navigation,
chevron={false}
separator={index !== parentMessages.length - 1}
>
{newsImage && (
<Image
source={{ uri: newsImage.url }}
style={styles.newsImage}
resizeMode="cover"
/>
)}
Kertie2 marked this conversation as resolved.
Show resolved Hide resolved
<View style={{
flexDirection: "row",
alignItems: "center",
Expand Down Expand Up @@ -72,14 +90,12 @@ const NewsListItem: React.FC<NewsListItemProps> = ({ index, message, navigation,
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
marginTop: 6,
}}
>
<NativeText
numberOfLines={1}
variant="subtitle"
style={{
marginTop: 6,
}}
>
{formatDate(message.date)}
</NativeText>
Expand All @@ -94,4 +110,13 @@ const NewsListItem: React.FC<NewsListItemProps> = ({ index, message, navigation,
);
};

const styles = StyleSheet.create({
newsImage: {
width: "100%",
height: 200,
borderRadius: 8,
marginBottom: 8,
},
});

export default NewsListItem;
27 changes: 17 additions & 10 deletions src/views/account/News/News.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,17 @@ const NewsScreen: Screen<"News"> = ({ route, navigation }) => {
}
}, [informations, account.personalization.MagicNews]);

const renderItem: ListRenderItem<NewsItem> = useCallback(({ item, index }) => (
<NewsListItem
key={index}
index={index}
message={item}
navigation={navigation}
parentMessages={sortedMessages}
isED={account.service == AccountService.EcoleDirecte}
/>
), [navigation, sortedMessages]);
const renderItem: ListRenderItem<NewsItem> = useCallback(({ item, index }) => {
return (
<NewsListItem
index={index}
message={item}
navigation={navigation}
parentMessages={sortedMessages}
isED={account.service == AccountService.EcoleDirecte}
/>
);
}, [navigation, sortedMessages]);

const NoNewsMessage = () => (
<View
Expand Down Expand Up @@ -185,6 +186,12 @@ const NewsScreen: Screen<"News"> = ({ route, navigation }) => {
};

const styles = StyleSheet.create({
newsImage: {
width: "100%",
height: 200,
borderRadius: 8,
marginBottom: 8,
},
Comment on lines +189 to +194

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kertie2 tu peux retirer ça du coup vu que l'image n'est plus dans ce fichier

scrollViewContent: {
padding: 16,
paddingTop: 0,
Expand Down