Feat : Added a messaging and improved the discussion section#12
Feat : Added a messaging and improved the discussion section#12Juste-Leo2 wants to merge 3 commits into
Conversation
…ons and session management
There was a problem hiding this comment.
Code Review
This pull request introduces a new messaging system, including a MailListScreen for managing drafts and an enhanced ChatScreen that renders AI-generated mail proposals as interactive cards. The AI prompt was updated to output drafts in JSON format, which are then parsed and displayed with an option to open them in the mail thread. Feedback includes replacing the any type for navigation with proper TypeScript definitions, improving the robustness of the JSON parsing logic in the message renderer to handle missing fields, and using the system locale for date formatting instead of a hardcoded value.
| // Simple parse for ```txt | ||
| const renderMessageText = (text: string) => { | ||
| const parts = text.split(/```txt([\s\S]*?)```/); | ||
| const renderMessageText = (text: string, navigation: any) => { |
There was a problem hiding this comment.
L'utilisation du type any pour l'objet navigation n'est pas recommandée en TypeScript. Il est préférable d'utiliser le type Props['navigation'] déjà défini dans le fichier pour garantir la cohérence des routes et bénéficier de l'autocomplétion.
| const renderMessageText = (text: string, navigation: any) => { | |
| const renderMessageText = (text: string, navigation: Props['navigation']) => { |
| try { | ||
| const mailData = JSON.parse(part.trim()); | ||
| if (mailData.subject && mailData.content) { | ||
| return ( | ||
| <View key={index} style={styles.mailProposalCard}> | ||
| <View style={styles.mailProposalHeader}> | ||
| <Text style={styles.mailProposalIcon}>📬</Text> | ||
| <Text style={styles.mailProposalTitle}>Proposition de mail</Text> | ||
| </View> | ||
| <Text style={styles.mailProposalSubject} numberOfLines={1}><Text style={{ fontWeight: 'bold' }}>Objet :</Text> {mailData.subject}</Text> | ||
| <Text style={styles.mailProposalPreview} numberOfLines={3}>{mailData.content}</Text> | ||
| <TouchableOpacity | ||
| style={styles.mailProposalButton} | ||
| onPress={() => navigation.navigate('MailThread', { initialDraft: mailData })} | ||
| > | ||
| <Text style={styles.mailProposalButtonText}>Ouvrir dans la messagerie</Text> | ||
| </TouchableOpacity> | ||
| </View> | ||
| ); | ||
| } | ||
| } catch (e) { | ||
| // Fallback | ||
| return ( | ||
| <View key={index} style={styles.codeBlockContainer}> | ||
| <Text style={styles.codeBlockText}>{part.trim()}</Text> | ||
| </View> | ||
| ); | ||
| } |
There was a problem hiding this comment.
La structure actuelle peut entraîner un affichage incohérent si le JSON est valide mais ne contient pas les champs attendus (subject, content). Il est préférable de gérer le rendu de manière cohérente en utilisant un bloc de code (fallback) pour tout segment identifié par des backticks si le parsing JSON échoue ou si les champs requis sont absents.
try {
const mailData = JSON.parse(part.trim());
if (mailData.subject && mailData.content) {
return (
<View key={index} style={styles.mailProposalCard}>
<View style={styles.mailProposalHeader}>
<Text style={styles.mailProposalIcon}>📬</Text>
<Text style={styles.mailProposalTitle}>Proposition de mail</Text>
</View>
<Text style={styles.mailProposalSubject} numberOfLines={1}><Text style={{ fontWeight: 'bold' }}>Objet :</Text> {mailData.subject}</Text>
<Text style={styles.mailProposalPreview} numberOfLines={3}>{mailData.content}</Text>
<TouchableOpacity
style={styles.mailProposalButton}
onPress={() => navigation.navigate('MailThread', { initialDraft: mailData })}
>
<Text style={styles.mailProposalButtonText}>Ouvrir dans la messagerie</Text>
</TouchableOpacity>
</View>
);
}
} catch (e) {
// Fallback en cas d'erreur de parsing
}
return (
<View key={index} style={styles.codeBlockContainer}>
<Text style={styles.codeBlockText}>{part.trim()}</Text>
</View>
);
| <View style={styles.mailCardContent}> | ||
| <Text style={styles.mailCardTitle} numberOfLines={1}>{session.title}</Text> | ||
| <Text style={styles.mailCardDate}> | ||
| {new Date(session.updatedAt).toLocaleDateString('fr-FR', { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' })} |
There was a problem hiding this comment.
La locale 'fr-FR' est codée en dur. Pour une meilleure internationalisation (i18n), il est recommandé d'utiliser la locale du système (en passant undefined). De plus, toLocaleString est plus sémantique que toLocaleDateString lorsqu'on inclut des options d'heure. Notez que toute refactorisation vers une configuration centralisée doit être effectuée dans une PR distincte.
| {new Date(session.updatedAt).toLocaleDateString('fr-FR', { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' })} | |
| {new Date(session.updatedAt).toLocaleString(undefined, { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' })} |
References
- Refactoring tasks, such as centralizing styles or configurations, should be handled in a separate pull request from feature implementation.
No description provided.