Skip to content

Feat : Added a messaging and improved the discussion section#12

Open
Juste-Leo2 wants to merge 3 commits into
mainfrom
dev2
Open

Feat : Added a messaging and improved the discussion section#12
Juste-Leo2 wants to merge 3 commits into
mainfrom
dev2

Conversation

@Juste-Leo2

Copy link
Copy Markdown
Owner

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
const renderMessageText = (text: string, navigation: any) => {
const renderMessageText = (text: string, navigation: Props['navigation']) => {

Comment on lines +33 to +60
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>
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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' })}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
{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
  1. Refactoring tasks, such as centralizing styles or configurations, should be handled in a separate pull request from feature implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant