@@ -33,4 +34,5 @@ export default function Loading({ setInitialEmails }) {
Loading.propTypes = {
setInitialEmails: PropTypes.func,
+ setInitialEmail: PropTypes.func,
};
From 93cd7246ea56ea9f6b4b34f56715879ccb574265 Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Mon, 2 Jun 2025 18:15:19 -0700
Subject: [PATCH 14/38] Add Function For Expanding Current Emails
---
frontend/src/components/client/client.jsx | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/frontend/src/components/client/client.jsx b/frontend/src/components/client/client.jsx
index 704c53a..50d0e2e 100644
--- a/frontend/src/components/client/client.jsx
+++ b/frontend/src/components/client/client.jsx
@@ -1,6 +1,6 @@
import { useEffect, useReducer } from "react";
import { Outlet, Route, Routes, useNavigate } from "react-router";
-import { fetchNewEmails } from "../../emails/emailHandler";
+import { fetchNewEmails, fetchMoreEmails } from "../../emails/emailHandler";
import "./client.css";
import Dashboard from "./dashboard/dashboard";
import Inbox from "./inbox/inbox";
@@ -92,6 +92,18 @@ function Client() {
}
};
+ // requests a page worth of emails and adds to the current email list,
+ // returns whether more emails exist or not
+ const requestMoreEmails = async () => {
+ const newEmails = fetchMoreEmails(client.emails.length);
+ if (newEmails.length > 0) {
+ handleAddEmails(newEmails);
+ } else {
+ return false;
+ }
+ return true;
+ };
+
const handleSetCurEmail = (email) => {
dispatchClient({
type: "emailChange",
@@ -132,6 +144,7 @@ function Client() {
emailList={client.emails}
setCurEmail={handleSetCurEmail}
curEmail={client.curEmail}
+ requestMoreEmails={requestMoreEmails}
/>
}
/>
@@ -155,6 +168,7 @@ function Client() {
emailList={client.emails}
handlePageChange={handlePageChange}
setCurEmail={handleSetCurEmail}
+ requestMoreEmails={requestMoreEmails}
/>
}
/>
From e2b96034d96f346215baee20cef4f2744471742a Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Mon, 2 Jun 2025 18:17:45 -0700
Subject: [PATCH 15/38] Modify Trimming Function To Work On Parameter
---
frontend/src/emails/emailHandler.js | 142 ++++++++++------------------
1 file changed, 48 insertions(+), 94 deletions(-)
diff --git a/frontend/src/emails/emailHandler.js b/frontend/src/emails/emailHandler.js
index 95dcc04..a284c84 100644
--- a/frontend/src/emails/emailHandler.js
+++ b/frontend/src/emails/emailHandler.js
@@ -3,48 +3,37 @@ import DOMPurify from "dompurify";
// TODO : env variable for baseUrl
// export const baseUrl = "http://127.0.0.1:8000";
export const baseUrl = "https://ee-backend-w86t.onrender.com";
-export let emails = [];
export let userPreferences = {
isChecked: true,
emailFetchInterval: 120,
theme: "light",
};
-export const fetchNewEmails = async () => {
- try {
- const requestedEmails = await fetchEmails(100);
- if (requestedEmails.length > 0) {
- const newEmails = getNewEmails(requestedEmails, emails); // O(n^2) operation
- if (newEmails.length > 0) {
- emails = [...emails, ...newEmails];
- window.location.hash = "#newEmails";
- }
- }
- } catch (error) {
- console.error(`Error fetching new emails: ${error}`);
- }
-};
-
-function getNewEmails(requestedEmails, allEmails) {
- return requestedEmails.filter((reqEmail) => {
- let exists = false;
- for (const email of allEmails) {
- if (email.email_id === reqEmail.email_id) exists = true;
- }
- return !exists;
- });
-}
-
-// export const retrieveUserData = async () => {
+// export const fetchNewEmails = async () => {
// try {
-// emails = await fetchEmails(100);
-// const user_id = null; // Get user ID
-// if (user_id) getUserPreferences(user_id);
+// const requestedEmails = await fetchEmails(100);
+// if (requestedEmails.length > 0) {
+// const newEmails = getNewEmails(requestedEmails, emails); // O(n^2) operation
+// if (newEmails.length > 0) {
+// emails = [...emails, ...newEmails];
+// window.location.hash = "#newEmails";
+// }
+// }
// } catch (error) {
-// console.error(error);
+// console.error(`Error fetching new emails: ${error}`);
// }
// };
+// function getNewEmails(requestedEmails, allEmails) {
+// return requestedEmails.filter((reqEmail) => {
+// let exists = false;
+// for (const email of allEmails) {
+// if (email.email_id === reqEmail.email_id) exists = true;
+// }
+// return !exists;
+// });
+// }
+
export const getUserPreferences = async (user_id) => {
try {
const preferences = await fetchUserPreferences(user_id);
@@ -99,31 +88,31 @@ export async function getReaderView(emailId) {
return email.reader_content;
}
-async function getSummaries(emailIds) {
- const option = {
- method: "GET",
- headers: {
- Authorization: `Bearer ${localStorage.getItem("auth_token")}`,
- "Content-Type": "application/json",
- },
- };
- try {
- const queryParams = new URLSearchParams();
- emailIds.forEach((id) => queryParams.append("ids", id));
- const req = new Request(
- `${baseUrl}/summaries/batch?${queryParams}`,
- option
- );
- const response = await fetch(req);
- if (!response.ok) {
- throw new Error(`Failed to retrieve summaries: ${response.statusText}`);
- }
- return await response.json();
- } catch (error) {
- console.error("Summary fetch error:", error);
- return []; // Return empty array on error for graceful degradation
- }
-}
+// async function getSummaries(emailIds) {
+// const option = {
+// method: "GET",
+// headers: {
+// Authorization: `Bearer ${localStorage.getItem("auth_token")}`,
+// "Content-Type": "application/json",
+// },
+// };
+// try {
+// const queryParams = new URLSearchParams();
+// emailIds.forEach((id) => queryParams.append("ids", id));
+// const req = new Request(
+// `${baseUrl}/summaries/batch?${queryParams}`,
+// option
+// );
+// const response = await fetch(req);
+// if (!response.ok) {
+// throw new Error(`Failed to retrieve summaries: ${response.statusText}`);
+// }
+// return await response.json();
+// } catch (error) {
+// console.error("Summary fetch error:", error);
+// return []; // Return empty array on error for graceful degradation
+// }
+// }
function parseDate(date) {
if (!date) return ["", "", "", ""]; // Handle null/undefined dates
@@ -140,6 +129,8 @@ function parseDate(date) {
}
}
+export async function fetchMoreEmails(curEmailsLength) {}
+
export default async function fetchEmails(numRequested) {
try {
// Fetch both emails and summaries concurrently
@@ -171,44 +162,7 @@ export default async function fetchEmails(numRequested) {
}
}
-export function getPageSummaries(emailList) {
- const toGetSummaries = emailList.filter(
- (email) => email.summary_text.length === 0
- );
- if (toGetSummaries.length > 0) addSummaries(toGetSummaries);
-}
-
-export function getTop5(emailList) {
- let toGetSummaries = emailList.length > 5 ? emailList.slice(0, 5) : emailList;
- toGetSummaries = toGetSummaries.filter(
- (email) => email.summary_text.length === 0
- );
- if (toGetSummaries.length > 0) addSummaries(toGetSummaries);
- return emailList.length > 5 ? emailList.slice(0, 5) : emailList;
-}
-
-async function addSummaries(emailList) {
- const ids = emailList.map((emailList) => {
- return emailList.email_id;
- });
- try {
- const summaries = await getSummaries(ids);
- summaries.reverse(); // link summaries to respected email
- for (let i = 0; i < emailList.length; i++) {
- const index = emails.indexOf(emailList[i]);
- emails[index] = {
- ...emails[index],
- summary_text: summaries[i].summary_text || "",
- keywords: summaries[i].keywords || [],
- };
- }
- if (emailList.length > 0) window.location.hash = "#newEmails";
- } catch (error) {
- console.error("Summaries adding error:", error);
- }
-}
-
-export function trimList(keyword) {
+export function trimList(emails, keyword) {
const toReturn = emails.filter((email) => {
if (email.subject.includes(keyword) || email.sender.includes(keyword))
return true;
From 9d1957d78b4efb19b52af9598cfb542cc987c0c1 Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Mon, 2 Jun 2025 22:29:44 -0700
Subject: [PATCH 16/38] Add Dynamic EmailsPerPage
---
frontend/src/components/client/client.jsx | 30 ++++++++++++++++++++---
frontend/src/components/login/Loading.jsx | 10 +++++---
2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/frontend/src/components/client/client.jsx b/frontend/src/components/client/client.jsx
index 50d0e2e..4ac8bc6 100644
--- a/frontend/src/components/client/client.jsx
+++ b/frontend/src/components/client/client.jsx
@@ -1,6 +1,6 @@
-import { useEffect, useReducer } from "react";
+import { useEffect, useReducer, useState } from "react";
import { Outlet, Route, Routes, useNavigate } from "react-router";
-import { fetchNewEmails, fetchMoreEmails } from "../../emails/emailHandler";
+import { fetchNewEmails, fetchEmails } from "../../emails/emailHandler";
import "./client.css";
import Dashboard from "./dashboard/dashboard";
import Inbox from "./inbox/inbox";
@@ -11,6 +11,9 @@ import Loading from "../login/Loading";
function Client() {
const navigate = useNavigate();
+ const [emailsPerPage, setEmailsPerPage] = useState(
+ Math.max(1, Math.floor(window.innerHeight / (window.innerHeight * 0.5)))
+ );
const [client, dispatchClient] = useReducer(clientReducer, {
expandedSideBar: false,
emails: [],
@@ -34,6 +37,26 @@ function Client() {
return () => clearInterval(clock);
}, [userPreferences.emailFetchInterval]);
+ useEffect(() => {
+ function updateEmailsPerPage() {
+ setEmailsPerPage(
+ Math.max(1, Math.floor(window.innerHeight / (window.innerHeight * 0.5)))
+ );
+ }
+
+ let resizeTimeout = null;
+ function handleResize() {
+ if (resizeTimeout) clearTimeout(resizeTimeout);
+ resizeTimeout = setTimeout(updateEmailsPerPage, 50);
+ }
+
+ window.addEventListener("resize", handleResize);
+ return () => {
+ window.removeEventListener("resize", handleResize);
+ if (resizeTimeout) clearTimeout(resizeTimeout);
+ };
+ }, []);
+
const root = document.querySelector(":root");
root.style.setProperty(
"--sidebar-width",
@@ -95,7 +118,7 @@ function Client() {
// requests a page worth of emails and adds to the current email list,
// returns whether more emails exist or not
const requestMoreEmails = async () => {
- const newEmails = fetchMoreEmails(client.emails.length);
+ const newEmails = await fetchEmails(client.emails.length);
if (newEmails.length > 0) {
handleAddEmails(newEmails);
} else {
@@ -118,6 +141,7 @@ function Client() {
path="loading"
element={
diff --git a/frontend/src/components/login/Loading.jsx b/frontend/src/components/login/Loading.jsx
index 97688db..9c0e31a 100644
--- a/frontend/src/components/login/Loading.jsx
+++ b/frontend/src/components/login/Loading.jsx
@@ -4,10 +4,13 @@ import { useNavigate } from "react-router";
import fetchEmails, { getUserPreferences } from "../../emails/emailHandler";
import "./Loading.css";
-const emailsPerPage = 20;
const user_id = null; // Get user ID
-export default function Loading({ setInitialEmails, setInitialEmail }) {
+export default function Loading({
+ setInitialEmails,
+ setInitialEmail,
+ emailsPerPage,
+}) {
const navigate = useNavigate();
useEffect(() => {
async function getInitialData() {
@@ -23,7 +26,7 @@ export default function Loading({ setInitialEmails, setInitialEmail }) {
}
}
getInitialData();
- }, [navigate, setInitialEmails, setInitialEmail]);
+ }, [navigate, setInitialEmails, setInitialEmail, emailsPerPage]);
return (
@@ -35,4 +38,5 @@ export default function Loading({ setInitialEmails, setInitialEmail }) {
Loading.propTypes = {
setInitialEmails: PropTypes.func,
setInitialEmail: PropTypes.func,
+ emailsPerPage: PropTypes.number,
};
From 09aea677c46e35e8456be49b8ce3eaf3d77b4028 Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Mon, 2 Jun 2025 22:38:19 -0700
Subject: [PATCH 17/38] Implement Refresh And Start Args For Email Fetch
---
frontend/src/emails/emailHandler.js | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/frontend/src/emails/emailHandler.js b/frontend/src/emails/emailHandler.js
index a284c84..28b4a5e 100644
--- a/frontend/src/emails/emailHandler.js
+++ b/frontend/src/emails/emailHandler.js
@@ -3,11 +3,6 @@ import DOMPurify from "dompurify";
// TODO : env variable for baseUrl
// export const baseUrl = "http://127.0.0.1:8000";
export const baseUrl = "https://ee-backend-w86t.onrender.com";
-export let userPreferences = {
- isChecked: true,
- emailFetchInterval: 120,
- theme: "light",
-};
// export const fetchNewEmails = async () => {
// try {
@@ -37,13 +32,22 @@ export let userPreferences = {
export const getUserPreferences = async (user_id) => {
try {
const preferences = await fetchUserPreferences(user_id);
- userPreferences = preferences;
+ return preferences;
} catch (error) {
console.error(error);
}
};
-async function getEmails(extension) {
+async function getEmails(number, ...args) {
+ let refresh = "false";
+ let curEmail = "0";
+ if (args.length > 0) {
+ if (typeof args[0] === "number") {
+ curEmail = parseInt(args[0], 10);
+ } else if (args[0]) {
+ refresh = "true";
+ }
+ }
const option = {
method: "GET",
headers: {
@@ -53,7 +57,7 @@ async function getEmails(extension) {
};
try {
const req = new Request(
- `${baseUrl}/emails/?skip=0&limit=${extension}&unread_only=false&sort_by=received_at&sort_order=desc&refresh=true`,
+ `${baseUrl}/emails/?skip=${curEmail}&limit=${number}&unread_only=false&sort_by=received_at&sort_order=desc&refresh=${refresh}`,
option
);
const response = await fetch(req);
@@ -129,12 +133,10 @@ function parseDate(date) {
}
}
-export async function fetchMoreEmails(curEmailsLength) {}
-
-export default async function fetchEmails(numRequested) {
+export default async function fetchEmails(pageSize, ...args) {
try {
// Fetch both emails and summaries concurrently
- const newEmails = await getEmails(numRequested);
+ const newEmails = await getEmails(pageSize, ...args);
// Validate array responses
if (!Array.isArray(newEmails.emails)) {
console.error("Invalid emails response:", newEmails);
From e48d1bf0dabdfbebc54d5473b07ac017d2ede029 Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Mon, 2 Jun 2025 23:00:45 -0700
Subject: [PATCH 18/38] Update New Email Fetch Functions To Work With Flow
---
frontend/src/components/client/client.jsx | 10 +++---
frontend/src/emails/emailHandler.js | 41 ++++++++++-------------
2 files changed, 23 insertions(+), 28 deletions(-)
diff --git a/frontend/src/components/client/client.jsx b/frontend/src/components/client/client.jsx
index 4ac8bc6..502fbf9 100644
--- a/frontend/src/components/client/client.jsx
+++ b/frontend/src/components/client/client.jsx
@@ -1,6 +1,6 @@
import { useEffect, useReducer, useState } from "react";
import { Outlet, Route, Routes, useNavigate } from "react-router";
-import { fetchNewEmails, fetchEmails } from "../../emails/emailHandler";
+import { fetchEmails, handleNewEmails } from "../../emails/emailHandler";
import "./client.css";
import Dashboard from "./dashboard/dashboard";
import Inbox from "./inbox/inbox";
@@ -27,15 +27,15 @@ function Client() {
useEffect(() => {
const clock = setInterval(async () => {
try {
- const newEmails = await fetchNewEmails();
- console.log(newEmails);
- // TODO: Do something with new emails
+ const requestedEmails = await fetchEmails(0, true);
+ const newEmails = handleNewEmails(client.emails, requestedEmails);
+ if (newEmails.length > 0) handleAddEmails(newEmails, true);
} catch (error) {
console.error(`Loading Emails Error: ${error}`);
}
}, userPreferences.emailFetchInterval * 1000);
return () => clearInterval(clock);
- }, [userPreferences.emailFetchInterval]);
+ }, [userPreferences.emailFetchInterval, client.emails, handleAddEmails]);
useEffect(() => {
function updateEmailsPerPage() {
diff --git a/frontend/src/emails/emailHandler.js b/frontend/src/emails/emailHandler.js
index 28b4a5e..966bc6e 100644
--- a/frontend/src/emails/emailHandler.js
+++ b/frontend/src/emails/emailHandler.js
@@ -4,30 +4,25 @@ import DOMPurify from "dompurify";
// export const baseUrl = "http://127.0.0.1:8000";
export const baseUrl = "https://ee-backend-w86t.onrender.com";
-// export const fetchNewEmails = async () => {
-// try {
-// const requestedEmails = await fetchEmails(100);
-// if (requestedEmails.length > 0) {
-// const newEmails = getNewEmails(requestedEmails, emails); // O(n^2) operation
-// if (newEmails.length > 0) {
-// emails = [...emails, ...newEmails];
-// window.location.hash = "#newEmails";
-// }
-// }
-// } catch (error) {
-// console.error(`Error fetching new emails: ${error}`);
-// }
-// };
+function getNewEmails(allEmails, requestedEmails) {
+ return requestedEmails.filter((reqEmail) => {
+ let exists = false;
+ for (const email of allEmails) {
+ if (email.email_id === reqEmail.email_id) exists = true;
+ }
+ return !exists;
+ });
+}
-// function getNewEmails(requestedEmails, allEmails) {
-// return requestedEmails.filter((reqEmail) => {
-// let exists = false;
-// for (const email of allEmails) {
-// if (email.email_id === reqEmail.email_id) exists = true;
-// }
-// return !exists;
-// });
-// }
+export const handleNewEmails = (allEmails, requestedEmails) => {
+ if (requestedEmails.length > 0) {
+ const newEmails = getNewEmails(allEmails, requestedEmails);
+ if (newEmails.length > 0) {
+ return newEmails;
+ }
+ }
+ return [];
+};
export const getUserPreferences = async (user_id) => {
try {
From 74aa604d7f901af621649bc8da0d14af8db43e3c Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Mon, 2 Jun 2025 23:17:55 -0700
Subject: [PATCH 19/38] Connect Pages & Fetching In Dashboard To Client
---
frontend/src/components/client/client.jsx | 4 +-
.../components/client/dashboard/dashboard.jsx | 12 +++++-
.../components/client/dashboard/miniview.jsx | 42 ++++++++++++++-----
3 files changed, 45 insertions(+), 13 deletions(-)
diff --git a/frontend/src/components/client/client.jsx b/frontend/src/components/client/client.jsx
index 502fbf9..6ff01c8 100644
--- a/frontend/src/components/client/client.jsx
+++ b/frontend/src/components/client/client.jsx
@@ -35,7 +35,8 @@ function Client() {
}
}, userPreferences.emailFetchInterval * 1000);
return () => clearInterval(clock);
- }, [userPreferences.emailFetchInterval, client.emails, handleAddEmails]);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [userPreferences.emailFetchInterval]);
useEffect(() => {
function updateEmailsPerPage() {
@@ -193,6 +194,7 @@ function Client() {
handlePageChange={handlePageChange}
setCurEmail={handleSetCurEmail}
requestMoreEmails={requestMoreEmails}
+ emailsPerPage={emailsPerPage}
/>
}
/>
diff --git a/frontend/src/components/client/dashboard/dashboard.jsx b/frontend/src/components/client/dashboard/dashboard.jsx
index b96b3e7..624a3bc 100644
--- a/frontend/src/components/client/dashboard/dashboard.jsx
+++ b/frontend/src/components/client/dashboard/dashboard.jsx
@@ -4,7 +4,13 @@ import MiniViewPanel from "./miniview";
import PropTypes from "prop-types";
import "./dashboard.css";
-function Dashboard({ emailList, handlePageChange, setCurEmail }) {
+function Dashboard({
+ emailList,
+ handlePageChange,
+ setCurEmail,
+ requestMoreEmails,
+ emailsPerPage,
+}) {
return (
);
@@ -75,6 +83,8 @@ const commonPropTypesDashboard = {
Dashboard.propTypes = {
...commonPropTypesDashboard,
emailList: PropTypes.array,
+ requestMoreEmails: PropTypes.func,
+ emailsPerPage: PropTypes.func,
};
WeightedEmailList.propTypes = {
diff --git a/frontend/src/components/client/dashboard/miniview.jsx b/frontend/src/components/client/dashboard/miniview.jsx
index 9e516a1..423aabc 100644
--- a/frontend/src/components/client/dashboard/miniview.jsx
+++ b/frontend/src/components/client/dashboard/miniview.jsx
@@ -3,10 +3,15 @@ import PropTypes from "prop-types";
import { useEffect, useRef, useState } from "react";
import FullScreenIcon from "../../../assets/FullScreenIcon";
import InboxIcon from "../../../assets/InboxArrow";
-import { emailsPerPage } from "../../../assets/constants";
import "./miniview.css";
-function MiniViewPanel({ emailList, handlePageChange, setCurEmail }) {
+function MiniViewPanel({
+ emailList,
+ handlePageChange,
+ setCurEmail,
+ requestMoreEmails,
+ emailsPerPage,
+}) {
return (
@@ -14,6 +19,8 @@ function MiniViewPanel({ emailList, handlePageChange, setCurEmail }) {
emailList={emailList}
setCurEmail={setCurEmail}
handlePageChange={handlePageChange}
+ requestMoreEmails={requestMoreEmails}
+ emailsPerPage={emailsPerPage}
/>
);
@@ -39,24 +46,31 @@ function MiniViewHead({ handlePageChange }) {
);
}
-function MiniViewBody({ emailList, setCurEmail, handlePageChange }) {
+function MiniViewBody({
+ emailList,
+ setCurEmail,
+ handlePageChange,
+ requestMoreEmails,
+ emailsPerPage,
+}) {
const [pages, setPages] = useState(1);
+ const [maxed, setMaxed] = useState(false);
const ref = useRef(null);
- const maxEmails =
- pages * emailsPerPage < emailList.length
- ? pages * emailsPerPage
- : emailList.length;
+ const maxEmails = pages * emailsPerPage;
const hasUnloadedEmails = maxEmails < emailList.length;
- const handleScroll = () => {
+ const handleScroll = async () => {
const fullyScrolled =
Math.abs(
ref.current.scrollHeight -
ref.current.clientHeight -
ref.current.scrollTop
) <= 1;
- if (fullyScrolled && hasUnloadedEmails) {
+ if (fullyScrolled && !maxed) {
setPages(pages + 1);
+ if (!hasUnloadedEmails) {
+ setMaxed(await requestMoreEmails);
+ }
}
};
@@ -108,9 +122,15 @@ const commonPropTypesDashboard = {
setCurEmail: PropTypes.func,
};
+const commonUtilityPropTypes = {
+ emailList: PropTypes.array,
+ requestMoreEmails: PropTypes.func,
+ emailsPerPage: PropTypes.number,
+};
+
MiniViewPanel.propTypes = {
...commonPropTypesDashboard,
- emailList: PropTypes.array,
+ ...commonUtilityPropTypes,
};
MiniViewHead.propTypes = {
@@ -119,7 +139,7 @@ MiniViewHead.propTypes = {
MiniViewBody.propTypes = {
...commonPropTypesDashboard,
- emailList: PropTypes.array,
+ commonUtilityPropTypes,
};
MiniViewEmail.propTypes = {
From 74430cc1b412c904f4949294a1589cf26bc5eb9f Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Tue, 3 Jun 2025 09:34:13 -0700
Subject: [PATCH 20/38] Add Summary Fetching & Setting
---
frontend/src/components/client/client.jsx | 28 +++++++--
.../components/client/dashboard/dashboard.jsx | 4 ++
frontend/src/emails/emailHandler.js | 59 +++++++++++--------
3 files changed, 61 insertions(+), 30 deletions(-)
diff --git a/frontend/src/components/client/client.jsx b/frontend/src/components/client/client.jsx
index 6ff01c8..908fbde 100644
--- a/frontend/src/components/client/client.jsx
+++ b/frontend/src/components/client/client.jsx
@@ -1,6 +1,10 @@
import { useEffect, useReducer, useState } from "react";
import { Outlet, Route, Routes, useNavigate } from "react-router";
-import { fetchEmails, handleNewEmails } from "../../emails/emailHandler";
+import {
+ fetchEmails,
+ handleNewEmails,
+ setSummary,
+} from "../../emails/emailHandler";
import "./client.css";
import Dashboard from "./dashboard/dashboard";
import Inbox from "./inbox/inbox";
@@ -12,7 +16,7 @@ import Loading from "../login/Loading";
function Client() {
const navigate = useNavigate();
const [emailsPerPage, setEmailsPerPage] = useState(
- Math.max(1, Math.floor(window.innerHeight / (window.innerHeight * 0.5)))
+ Math.max(1, Math.floor(window.innerHeight / 35))
);
const [client, dispatchClient] = useReducer(clientReducer, {
expandedSideBar: false,
@@ -40,9 +44,7 @@ function Client() {
useEffect(() => {
function updateEmailsPerPage() {
- setEmailsPerPage(
- Math.max(1, Math.floor(window.innerHeight / (window.innerHeight * 0.5)))
- );
+ setEmailsPerPage(Math.max(1, Math.floor(window.innerHeight / 35)));
}
let resizeTimeout = null;
@@ -135,6 +137,20 @@ function Client() {
});
};
+ const handleRequestSummaries = async (emails) => {
+ let curEmails = client.emails;
+ for (const email in emails) {
+ const res = await setSummary(email, curEmails);
+ if (res.length > 0) {
+ curEmails = res;
+ }
+ }
+ dispatchClient({
+ type: "emailAdd",
+ email: curEmails,
+ });
+ };
+
return (
<>
@@ -170,6 +186,7 @@ function Client() {
setCurEmail={handleSetCurEmail}
curEmail={client.curEmail}
requestMoreEmails={requestMoreEmails}
+ requestSummaries={handleRequestSummaries}
/>
}
/>
@@ -195,6 +212,7 @@ function Client() {
setCurEmail={handleSetCurEmail}
requestMoreEmails={requestMoreEmails}
emailsPerPage={emailsPerPage}
+ requestSummaries={handleRequestSummaries}
/>
}
/>
diff --git a/frontend/src/components/client/dashboard/dashboard.jsx b/frontend/src/components/client/dashboard/dashboard.jsx
index 624a3bc..4914268 100644
--- a/frontend/src/components/client/dashboard/dashboard.jsx
+++ b/frontend/src/components/client/dashboard/dashboard.jsx
@@ -10,6 +10,7 @@ function Dashboard({
setCurEmail,
requestMoreEmails,
emailsPerPage,
+ requestSummaries,
}) {
return (
@@ -17,6 +18,7 @@ function Dashboard({
emailList={emailList}
setCurEmail={setCurEmail}
handlePageChange={handlePageChange}
+ requestSummaries={requestSummaries}
/>
queryParams.append("ids", id));
-// const req = new Request(
-// `${baseUrl}/summaries/batch?${queryParams}`,
-// option
-// );
-// const response = await fetch(req);
-// if (!response.ok) {
-// throw new Error(`Failed to retrieve summaries: ${response.statusText}`);
-// }
-// return await response.json();
-// } catch (error) {
-// console.error("Summary fetch error:", error);
-// return []; // Return empty array on error for graceful degradation
-// }
-// }
+async function getSummary(emailId) {
+ const option = {
+ method: "GET",
+ headers: {
+ Authorization: `Bearer ${localStorage.getItem("auth_token")}`,
+ "Content-Type": "application/json",
+ },
+ };
+ try {
+ const req = new Request(`${baseUrl}/summaries/?email_id${emailId}`, option);
+ const response = await fetch(req);
+ if (!response.ok) {
+ throw new Error(`Failed to retrieve summaries: ${response.statusText}`);
+ }
+ let summary = await response.json();
+ summary.valid = true;
+ return summary;
+ } catch (error) {
+ console.error("Summary fetch error:", error);
+ return { valid: false };
+ }
+}
+
+export async function setSummary(email, emails) {
+ let curEmails = emails;
+ let curEmail = email;
+ const summary = await getSummary(email.email_id);
+ if (!summary.valid) return [];
+ curEmail.keywords = summary.keywords;
+ curEmail.summary_text = summary.summary_text;
+ const index = curEmails.indexOf(email);
+ curEmails[index] = curEmail;
+ return curEmails;
+}
function parseDate(date) {
if (!date) return ["", "", "", ""]; // Handle null/undefined dates
From 12419fc661bc47fb4cabf4ee9c34c47c21bba136 Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Tue, 3 Jun 2025 09:47:00 -0700
Subject: [PATCH 21/38] Extend Summary Fetching To Weighted Email List
---
.../src/components/client/dashboard/dashboard.jsx | 13 +++++++++++--
frontend/src/emails/emailHandler.js | 4 ++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/frontend/src/components/client/dashboard/dashboard.jsx b/frontend/src/components/client/dashboard/dashboard.jsx
index 4914268..d57c9b3 100644
--- a/frontend/src/components/client/dashboard/dashboard.jsx
+++ b/frontend/src/components/client/dashboard/dashboard.jsx
@@ -31,9 +31,18 @@ function Dashboard({
);
}
-function WeightedEmailList({ emailList, setCurEmail, handlePageChange }) {
- const emails = () => {
+function WeightedEmailList({
+ emailList,
+ setCurEmail,
+ handlePageChange,
+ requestSummaries,
+}) {
+ const emails = async () => {
const WEList = getTop5(emailList);
+ let needSummaries = WEList.filter(
+ (email) => email.summary_text.length < 1 && email.keywords.length < 1
+ );
+ if (needSummaries.legnth > 0) requestSummaries(needSummaries);
const returnBlock = [];
for (let i = 0; i < WEList.length; i++) {
returnBlock.push(
diff --git a/frontend/src/emails/emailHandler.js b/frontend/src/emails/emailHandler.js
index a0e13b5..a822364 100644
--- a/frontend/src/emails/emailHandler.js
+++ b/frontend/src/emails/emailHandler.js
@@ -180,6 +180,10 @@ export function trimList(emails, keyword) {
return toReturn;
}
+export function getTop5(emails) {
+ return emails.length > 5 ? emails.slice(0, 5) : emails;
+}
+
export async function markEmailAsRead(emailId) {
console.log(emailId);
return;
From e26e3fd6b6000c66b02d76309bc27a61dd8d20ab Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Tue, 3 Jun 2025 10:15:47 -0700
Subject: [PATCH 22/38] Remove Deprecated Email Storage In Router & Inbox
---
frontend/src/components/client/client.jsx | 3 +-
.../src/components/client/inbox/inbox.jsx | 5 ++-
frontend/src/components/router/Router.jsx | 38 +------------------
3 files changed, 6 insertions(+), 40 deletions(-)
diff --git a/frontend/src/components/client/client.jsx b/frontend/src/components/client/client.jsx
index 908fbde..8edaea1 100644
--- a/frontend/src/components/client/client.jsx
+++ b/frontend/src/components/client/client.jsx
@@ -1,7 +1,6 @@
import { useEffect, useReducer, useState } from "react";
import { Outlet, Route, Routes, useNavigate } from "react-router";
-import {
- fetchEmails,
+import fetchEmails, {
handleNewEmails,
setSummary,
} from "../../emails/emailHandler";
diff --git a/frontend/src/components/client/inbox/inbox.jsx b/frontend/src/components/client/inbox/inbox.jsx
index 93c0a9d..0312af1 100644
--- a/frontend/src/components/client/inbox/inbox.jsx
+++ b/frontend/src/components/client/inbox/inbox.jsx
@@ -3,7 +3,6 @@ import { useEffect, useRef, useState } from "react";
import ArrowIcon from "../../../assets/InboxArrow";
import { emailsPerPage } from "../../../assets/constants";
import EmailDisplay from "./emailDisplay";
-import { getPageSummaries } from "../../../emails/emailHandler";
import "./emailEntry.css";
import "./emailList.css";
import { trimList } from "../../../emails/emailHandler"; // shared API URL base
@@ -76,6 +75,8 @@ function InboxEmailList({
onClick,
handleEmailSearch,
}) {
+ // const [allEmailsLoaded, setAllEmailsLoaded] = useState(false);
+ // const [loadingEmails, setLoadingEmails] = useState(false);
const [pages, setPages] = useState(1);
const ref = useRef(null);
const maxEmails = Math.min(pages * emailsPerPage, emailList.length);
@@ -115,7 +116,7 @@ function InboxEmailList({
/>
);
}
- if (needsSummary.length > 0) getPageSummaries(needsSummary);
+ // if (needsSummary.length > 0) getPageSummaries(needsSummary);
return returnBlock;
};
return (
diff --git a/frontend/src/components/router/Router.jsx b/frontend/src/components/router/Router.jsx
index a400c88..a579b45 100644
--- a/frontend/src/components/router/Router.jsx
+++ b/frontend/src/components/router/Router.jsx
@@ -1,13 +1,5 @@
-import { useEffect, useState } from "react";
-import {
- BrowserRouter,
- Navigate,
- Route,
- Routes,
- useLocation,
-} from "react-router";
+import { BrowserRouter, Navigate, Route, Routes } from "react-router";
import { authenticate } from "../../authentication/authenticate";
-import { emails, userPreferences } from "../../emails/emailHandler";
import Client from "../client/client";
import Contact from "../login/contact";
import Error from "../login/Error";
@@ -30,24 +22,6 @@ export function Router() {
}
export function AppRouter() {
- const [userEmails, setUserEmails] = useState(emails);
- const location = useLocation();
- useEffect(() => {
- const interval = setInterval(() => {
- if (emails != userEmails || window.location.hash === "#newEmails") {
- setUserEmails(emails);
- window.history.replaceState(
- null,
- "",
- window.location.pathname + window.location.search
- ); // Remove the hash
- }
- }, 500);
-
- return () => clearInterval(interval);
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [location]);
-
return (
} />
@@ -60,15 +34,7 @@ export function AppRouter() {
path="/login"
element={}
/>
-
- }
- />
+ } />
} />
);
From 8adfb7761e693d83bd8d6b78fc2d9ada84fa25dc Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Tue, 10 Jun 2025 16:50:33 -0700
Subject: [PATCH 23/38] Summaries Function Initialized & Linked To WEList
---
frontend/src/components/client/client.jsx | 12 +++--
.../components/client/dashboard/dashboard.jsx | 52 +++++++++++++------
frontend/src/emails/emailHandler.js | 7 ++-
3 files changed, 50 insertions(+), 21 deletions(-)
diff --git a/frontend/src/components/client/client.jsx b/frontend/src/components/client/client.jsx
index 8edaea1..92d4952 100644
--- a/frontend/src/components/client/client.jsx
+++ b/frontend/src/components/client/client.jsx
@@ -138,12 +138,18 @@ function Client() {
const handleRequestSummaries = async (emails) => {
let curEmails = client.emails;
- for (const email in emails) {
- const res = await setSummary(email, curEmails);
+ console.log("In handle request summaries");
+
+ const result = await Promise.all(
+ emails.map((email) => setSummary(email, curEmails))
+ );
+
+ result.forEach((res) => {
if (res.length > 0) {
curEmails = res;
}
- }
+ });
+
dispatchClient({
type: "emailAdd",
email: curEmails,
diff --git a/frontend/src/components/client/dashboard/dashboard.jsx b/frontend/src/components/client/dashboard/dashboard.jsx
index d57c9b3..3801269 100644
--- a/frontend/src/components/client/dashboard/dashboard.jsx
+++ b/frontend/src/components/client/dashboard/dashboard.jsx
@@ -1,3 +1,4 @@
+import { useEffect, useState } from "react";
import ViewIcon from "../../../assets/ViewIcon";
import { getTop5 } from "../../../emails/emailHandler";
import MiniViewPanel from "./miniview";
@@ -37,26 +38,43 @@ function WeightedEmailList({
handlePageChange,
requestSummaries,
}) {
- const emails = async () => {
- const WEList = getTop5(emailList);
- let needSummaries = WEList.filter(
- (email) => email.summary_text.length < 1 && email.keywords.length < 1
- );
- if (needSummaries.legnth > 0) requestSummaries(needSummaries);
- const returnBlock = [];
- for (let i = 0; i < WEList.length; i++) {
- returnBlock.push(
+ const [WEEmails, setWEEmails] = useState([]);
+
+ useEffect(() => {
+ async function fetchEmails() {
+ const WEList = getTop5(emailList);
+ let needSummaries = WEList.filter((email) => {
+ return email.summary_text.length < 1 && email.keywords.length < 1;
+ });
+ if (needSummaries.length > 0) await requestSummaries(needSummaries);
+ setWEEmails(WEList);
+ }
+ fetchEmails();
+ }, [emailList, requestSummaries]);
+ // const emails = async () => {
+ // const WEList = getTop5(emailList);
+ // let needSummaries = WEList.filter(
+ // (email) => email.summary_text.length < 1 && email.keywords.length < 1
+ // );
+ // if (needSummaries.legnth > 0) await requestSummaries(needSummaries);
+ // const returnBlock = [];
+ // for (let i = 0; i < WEList.length; i++) {
+ // returnBlock.push();
+ // }
+ // return returnBlock;
+ // };
+ return (
+
+ {WEEmails.map((email) => {
- );
- }
- return returnBlock;
- };
- return
{emails()}
;
+ />;
+ })}
+
+ );
}
function WEListEmail({ email, setCurEmail, handlePageChange }) {
diff --git a/frontend/src/emails/emailHandler.js b/frontend/src/emails/emailHandler.js
index a822364..d4931fa 100644
--- a/frontend/src/emails/emailHandler.js
+++ b/frontend/src/emails/emailHandler.js
@@ -96,13 +96,18 @@ async function getSummary(emailId) {
},
};
try {
- const req = new Request(`${baseUrl}/summaries/?email_id${emailId}`, option);
+ const req = new Request(
+ `${baseUrl}/summaries/?email_id=${emailId}`,
+ option
+ );
const response = await fetch(req);
if (!response.ok) {
throw new Error(`Failed to retrieve summaries: ${response.statusText}`);
}
let summary = await response.json();
summary.valid = true;
+ console.log(`Summary for ${emailId}:`);
+ console.log(summary);
return summary;
} catch (error) {
console.error("Summary fetch error:", error);
From ba54c64112d10910ac36e75d7e7a914731799c6a Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Tue, 10 Jun 2025 17:13:06 -0700
Subject: [PATCH 24/38] Fix Subsequent Email Retreival
---
frontend/src/components/client/client.jsx | 2 +-
frontend/src/components/client/dashboard/miniview.jsx | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/frontend/src/components/client/client.jsx b/frontend/src/components/client/client.jsx
index 92d4952..b459354 100644
--- a/frontend/src/components/client/client.jsx
+++ b/frontend/src/components/client/client.jsx
@@ -120,7 +120,7 @@ function Client() {
// requests a page worth of emails and adds to the current email list,
// returns whether more emails exist or not
const requestMoreEmails = async () => {
- const newEmails = await fetchEmails(client.emails.length);
+ const newEmails = await fetchEmails(emailsPerPage, client.emails.length);
if (newEmails.length > 0) {
handleAddEmails(newEmails);
} else {
diff --git a/frontend/src/components/client/dashboard/miniview.jsx b/frontend/src/components/client/dashboard/miniview.jsx
index 423aabc..1cd028a 100644
--- a/frontend/src/components/client/dashboard/miniview.jsx
+++ b/frontend/src/components/client/dashboard/miniview.jsx
@@ -69,7 +69,7 @@ function MiniViewBody({
if (fullyScrolled && !maxed) {
setPages(pages + 1);
if (!hasUnloadedEmails) {
- setMaxed(await requestMoreEmails);
+ setMaxed(await requestMoreEmails());
}
}
};
From ee4aaa0ceb6bbc3c6f8ffe7325a2f5d94d89e293 Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Thu, 12 Jun 2025 17:05:15 -0700
Subject: [PATCH 25/38] Fix Email Loading On MiniView & WEList
---
frontend/src/components/client/client.jsx | 19 +++++--
.../components/client/dashboard/dashboard.jsx | 16 ++++--
.../components/client/dashboard/miniview.jsx | 9 +--
frontend/src/components/login/Loading.jsx | 1 +
frontend/src/emails/emailHandler.js | 56 +++++++++++--------
5 files changed, 63 insertions(+), 38 deletions(-)
diff --git a/frontend/src/components/client/client.jsx b/frontend/src/components/client/client.jsx
index b459354..5ad0e5b 100644
--- a/frontend/src/components/client/client.jsx
+++ b/frontend/src/components/client/client.jsx
@@ -117,16 +117,27 @@ function Client() {
}
};
+ const handleSetEmails = (emails) => {
+ dispatchClient({
+ type: "emailAdd",
+ email: emails,
+ });
+ };
+
// requests a page worth of emails and adds to the current email list,
// returns whether more emails exist or not
const requestMoreEmails = async () => {
+ let noMoreEmails = true;
+ console.log(
+ `fetchEmails being called with ${emailsPerPage} & ${client.emails.length}`
+ );
const newEmails = await fetchEmails(emailsPerPage, client.emails.length);
+ console.log(`newEmails.length = ${newEmails.length}`);
if (newEmails.length > 0) {
handleAddEmails(newEmails);
- } else {
- return false;
+ noMoreEmails = false;
}
- return true;
+ return noMoreEmails;
};
const handleSetCurEmail = (email) => {
@@ -164,7 +175,7 @@ function Client() {
element={
}
diff --git a/frontend/src/components/client/dashboard/dashboard.jsx b/frontend/src/components/client/dashboard/dashboard.jsx
index 3801269..2e78a2a 100644
--- a/frontend/src/components/client/dashboard/dashboard.jsx
+++ b/frontend/src/components/client/dashboard/dashboard.jsx
@@ -47,6 +47,8 @@ function WeightedEmailList({
return email.summary_text.length < 1 && email.keywords.length < 1;
});
if (needSummaries.length > 0) await requestSummaries(needSummaries);
+ console.log("We list is:");
+ console.log(WEList);
setWEEmails(WEList);
}
fetchEmails();
@@ -66,12 +68,14 @@ function WeightedEmailList({
return (
{WEEmails.map((email) => {
- ;
+ return (
+
+ );
})}
);
diff --git a/frontend/src/components/client/dashboard/miniview.jsx b/frontend/src/components/client/dashboard/miniview.jsx
index 1cd028a..ee6eb25 100644
--- a/frontend/src/components/client/dashboard/miniview.jsx
+++ b/frontend/src/components/client/dashboard/miniview.jsx
@@ -56,8 +56,8 @@ function MiniViewBody({
const [pages, setPages] = useState(1);
const [maxed, setMaxed] = useState(false);
const ref = useRef(null);
- const maxEmails = pages * emailsPerPage;
- const hasUnloadedEmails = maxEmails < emailList.length;
+ let maxEmails = Math.min(pages * emailsPerPage, emailList.length);
+ let hasUnloadedEmails = maxEmails < emailList.length;
const handleScroll = async () => {
const fullyScrolled =
@@ -67,10 +67,11 @@ function MiniViewBody({
ref.current.scrollTop
) <= 1;
if (fullyScrolled && !maxed) {
- setPages(pages + 1);
if (!hasUnloadedEmails) {
- setMaxed(await requestMoreEmails());
+ const haveWeMaxed = await requestMoreEmails();
+ setMaxed(haveWeMaxed);
}
+ setPages(pages + 1);
}
};
diff --git a/frontend/src/components/login/Loading.jsx b/frontend/src/components/login/Loading.jsx
index 9c0e31a..4e2369d 100644
--- a/frontend/src/components/login/Loading.jsx
+++ b/frontend/src/components/login/Loading.jsx
@@ -13,6 +13,7 @@ export default function Loading({
}) {
const navigate = useNavigate();
useEffect(() => {
+ // duplicate call
async function getInitialData() {
const initialEmails = await fetchEmails(emailsPerPage);
if (user_id) getUserPreferences(user_id);
diff --git a/frontend/src/emails/emailHandler.js b/frontend/src/emails/emailHandler.js
index d4931fa..38f60e7 100644
--- a/frontend/src/emails/emailHandler.js
+++ b/frontend/src/emails/emailHandler.js
@@ -88,31 +88,37 @@ export async function getReaderView(emailId) {
}
async function getSummary(emailId) {
- const option = {
- method: "GET",
- headers: {
- Authorization: `Bearer ${localStorage.getItem("auth_token")}`,
- "Content-Type": "application/json",
- },
+ console.log(`getSummary is called for ${emailId}`);
+ return {
+ valid: true,
+ keywords: ["keyword1", "keyword2"],
+ summary_text: `example summary text #${emailId}`,
};
- try {
- const req = new Request(
- `${baseUrl}/summaries/?email_id=${emailId}`,
- option
- );
- const response = await fetch(req);
- if (!response.ok) {
- throw new Error(`Failed to retrieve summaries: ${response.statusText}`);
- }
- let summary = await response.json();
- summary.valid = true;
- console.log(`Summary for ${emailId}:`);
- console.log(summary);
- return summary;
- } catch (error) {
- console.error("Summary fetch error:", error);
- return { valid: false };
- }
+ // const option = {
+ // method: "GET",
+ // headers: {
+ // Authorization: `Bearer ${localStorage.getItem("auth_token")}`,
+ // "Content-Type": "application/json",
+ // },
+ // };
+ // try {
+ // const req = new Request(
+ // `${baseUrl}/summaries/?email_id=${emailId}`,
+ // option
+ // );
+ // const response = await fetch(req);
+ // if (!response.ok) {
+ // throw new Error(`Failed to retrieve summaries: ${response.statusText}`);
+ // }
+ // let summary = await response.json();
+ // summary.valid = true;
+ // console.log(`Summary for ${emailId}:`);
+ // console.log(summary);
+ // return summary;
+ // } catch (error) {
+ // console.error("Summary fetch error:", error);
+ // return { valid: false };
+ // }
}
export async function setSummary(email, emails) {
@@ -166,6 +172,8 @@ export default async function fetchEmails(pageSize, ...args) {
received_at: parseDate(email.received_at),
};
});
+ console.log("returning");
+ console.log(processedEmails);
return processedEmails;
} catch (error) {
console.error("Email processing error:", error);
From 37df53be24ebb746ee89fba4f85edfcc7e744e43 Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Thu, 12 Jun 2025 17:19:44 -0700
Subject: [PATCH 26/38] Move HasUnloadedEmails To Client
---
frontend/src/components/client/client.jsx | 8 +++++---
.../components/client/dashboard/dashboard.jsx | 3 +++
.../src/components/client/dashboard/miniview.jsx | 16 +++++++++-------
frontend/src/emails/emailHandler.js | 2 --
4 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/frontend/src/components/client/client.jsx b/frontend/src/components/client/client.jsx
index 5ad0e5b..b87022f 100644
--- a/frontend/src/components/client/client.jsx
+++ b/frontend/src/components/client/client.jsx
@@ -17,6 +17,7 @@ function Client() {
const [emailsPerPage, setEmailsPerPage] = useState(
Math.max(1, Math.floor(window.innerHeight / 35))
);
+ const [hasUnloadedEmails, setHasUnloadedEmails] = useState(true);
const [client, dispatchClient] = useReducer(clientReducer, {
expandedSideBar: false,
emails: [],
@@ -127,7 +128,6 @@ function Client() {
// requests a page worth of emails and adds to the current email list,
// returns whether more emails exist or not
const requestMoreEmails = async () => {
- let noMoreEmails = true;
console.log(
`fetchEmails being called with ${emailsPerPage} & ${client.emails.length}`
);
@@ -135,9 +135,10 @@ function Client() {
console.log(`newEmails.length = ${newEmails.length}`);
if (newEmails.length > 0) {
handleAddEmails(newEmails);
- noMoreEmails = false;
+ console.log(`Length: ${newEmails.length}`);
+ } else {
+ setHasUnloadedEmails(false);
}
- return noMoreEmails;
};
const handleSetCurEmail = (email) => {
@@ -229,6 +230,7 @@ function Client() {
requestMoreEmails={requestMoreEmails}
emailsPerPage={emailsPerPage}
requestSummaries={handleRequestSummaries}
+ hasUnloadedEmails={hasUnloadedEmails}
/>
}
/>
diff --git a/frontend/src/components/client/dashboard/dashboard.jsx b/frontend/src/components/client/dashboard/dashboard.jsx
index 2e78a2a..193b2b6 100644
--- a/frontend/src/components/client/dashboard/dashboard.jsx
+++ b/frontend/src/components/client/dashboard/dashboard.jsx
@@ -12,6 +12,7 @@ function Dashboard({
requestMoreEmails,
emailsPerPage,
requestSummaries,
+ hasUnloadedEmails,
}) {
return (
@@ -27,6 +28,7 @@ function Dashboard({
setCurEmail={setCurEmail}
requestMoreEmails={requestMoreEmails}
emailsPerPage={emailsPerPage}
+ hasUnloadedEmails={hasUnloadedEmails}
/>
);
@@ -119,6 +121,7 @@ Dashboard.propTypes = {
requestMoreEmails: PropTypes.func,
emailsPerPage: PropTypes.func,
requestSummaries: PropTypes.func,
+ hasUnloadedEmails: PropTypes.bool,
};
WeightedEmailList.propTypes = {
diff --git a/frontend/src/components/client/dashboard/miniview.jsx b/frontend/src/components/client/dashboard/miniview.jsx
index ee6eb25..bebc1c1 100644
--- a/frontend/src/components/client/dashboard/miniview.jsx
+++ b/frontend/src/components/client/dashboard/miniview.jsx
@@ -11,6 +11,7 @@ function MiniViewPanel({
setCurEmail,
requestMoreEmails,
emailsPerPage,
+ hasUnloadedEmails,
}) {
return (
@@ -21,6 +22,7 @@ function MiniViewPanel({
handlePageChange={handlePageChange}
requestMoreEmails={requestMoreEmails}
emailsPerPage={emailsPerPage}
+ hasUnloadedEmails={hasUnloadedEmails}
/>
);
@@ -52,12 +54,12 @@ function MiniViewBody({
handlePageChange,
requestMoreEmails,
emailsPerPage,
+ hasUnloadedEmails,
}) {
const [pages, setPages] = useState(1);
- const [maxed, setMaxed] = useState(false);
const ref = useRef(null);
let maxEmails = Math.min(pages * emailsPerPage, emailList.length);
- let hasUnloadedEmails = maxEmails < emailList.length;
+ let hasLocallyUnloadedEmails = maxEmails < emailList.length;
const handleScroll = async () => {
const fullyScrolled =
@@ -66,10 +68,9 @@ function MiniViewBody({
ref.current.clientHeight -
ref.current.scrollTop
) <= 1;
- if (fullyScrolled && !maxed) {
- if (!hasUnloadedEmails) {
- const haveWeMaxed = await requestMoreEmails();
- setMaxed(haveWeMaxed);
+ if (fullyScrolled && (hasLocallyUnloadedEmails || hasUnloadedEmails)) {
+ if (hasUnloadedEmails) {
+ await requestMoreEmails();
}
setPages(pages + 1);
}
@@ -127,6 +128,7 @@ const commonUtilityPropTypes = {
emailList: PropTypes.array,
requestMoreEmails: PropTypes.func,
emailsPerPage: PropTypes.number,
+ hasUnloadedEmails: PropTypes.bool,
};
MiniViewPanel.propTypes = {
@@ -140,7 +142,7 @@ MiniViewHead.propTypes = {
MiniViewBody.propTypes = {
...commonPropTypesDashboard,
- commonUtilityPropTypes,
+ ...commonUtilityPropTypes,
};
MiniViewEmail.propTypes = {
diff --git a/frontend/src/emails/emailHandler.js b/frontend/src/emails/emailHandler.js
index 38f60e7..7771e3a 100644
--- a/frontend/src/emails/emailHandler.js
+++ b/frontend/src/emails/emailHandler.js
@@ -172,8 +172,6 @@ export default async function fetchEmails(pageSize, ...args) {
received_at: parseDate(email.received_at),
};
});
- console.log("returning");
- console.log(processedEmails);
return processedEmails;
} catch (error) {
console.error("Email processing error:", error);
From 8cbf141e6586cd4bf523bbad651f0a3e41b85329 Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Thu, 12 Jun 2025 17:33:02 -0700
Subject: [PATCH 27/38] Fix Summaries Call
---
.../components/client/dashboard/dashboard.jsx | 2 -
frontend/src/emails/emailHandler.js | 50 ++++++++-----------
2 files changed, 20 insertions(+), 32 deletions(-)
diff --git a/frontend/src/components/client/dashboard/dashboard.jsx b/frontend/src/components/client/dashboard/dashboard.jsx
index 193b2b6..8128769 100644
--- a/frontend/src/components/client/dashboard/dashboard.jsx
+++ b/frontend/src/components/client/dashboard/dashboard.jsx
@@ -49,8 +49,6 @@ function WeightedEmailList({
return email.summary_text.length < 1 && email.keywords.length < 1;
});
if (needSummaries.length > 0) await requestSummaries(needSummaries);
- console.log("We list is:");
- console.log(WEList);
setWEEmails(WEList);
}
fetchEmails();
diff --git a/frontend/src/emails/emailHandler.js b/frontend/src/emails/emailHandler.js
index 7771e3a..e2e637c 100644
--- a/frontend/src/emails/emailHandler.js
+++ b/frontend/src/emails/emailHandler.js
@@ -88,37 +88,27 @@ export async function getReaderView(emailId) {
}
async function getSummary(emailId) {
- console.log(`getSummary is called for ${emailId}`);
- return {
- valid: true,
- keywords: ["keyword1", "keyword2"],
- summary_text: `example summary text #${emailId}`,
+ const option = {
+ method: "GET",
+ headers: {
+ Authorization: `Bearer ${localStorage.getItem("auth_token")}`,
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ },
};
- // const option = {
- // method: "GET",
- // headers: {
- // Authorization: `Bearer ${localStorage.getItem("auth_token")}`,
- // "Content-Type": "application/json",
- // },
- // };
- // try {
- // const req = new Request(
- // `${baseUrl}/summaries/?email_id=${emailId}`,
- // option
- // );
- // const response = await fetch(req);
- // if (!response.ok) {
- // throw new Error(`Failed to retrieve summaries: ${response.statusText}`);
- // }
- // let summary = await response.json();
- // summary.valid = true;
- // console.log(`Summary for ${emailId}:`);
- // console.log(summary);
- // return summary;
- // } catch (error) {
- // console.error("Summary fetch error:", error);
- // return { valid: false };
- // }
+ try {
+ const req = new Request(`${baseUrl}/summaries/${emailId}`, option);
+ const response = await fetch(req);
+ if (!response.ok) {
+ throw new Error(`Failed to retrieve summaries: ${response.statusText}`);
+ }
+ let summary = await response.json();
+ summary.valid = true;
+ return summary;
+ } catch (error) {
+ console.error("Summary fetch error:", error);
+ return { valid: false };
+ }
}
export async function setSummary(email, emails) {
From 33f3bfd20cd6941298d7455df99113401e61c7b8 Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Thu, 12 Jun 2025 17:53:14 -0700
Subject: [PATCH 28/38] Fix WEList Email Loading Visuals
---
.../components/client/dashboard/dashboard.css | 4 ++
.../components/client/dashboard/dashboard.jsx | 54 ++++++++++---------
2 files changed, 33 insertions(+), 25 deletions(-)
diff --git a/frontend/src/components/client/dashboard/dashboard.css b/frontend/src/components/client/dashboard/dashboard.css
index 214a104..e55dfdb 100644
--- a/frontend/src/components/client/dashboard/dashboard.css
+++ b/frontend/src/components/client/dashboard/dashboard.css
@@ -36,6 +36,10 @@
gap: 1rem;
}
+.dashboard .welist-email-container.solo {
+ grid-template-columns: 1fr;
+}
+
.dashboard .email-link {
color: var(--icon-color);
border-radius: 0.2rem;
diff --git a/frontend/src/components/client/dashboard/dashboard.jsx b/frontend/src/components/client/dashboard/dashboard.jsx
index 8128769..d427929 100644
--- a/frontend/src/components/client/dashboard/dashboard.jsx
+++ b/frontend/src/components/client/dashboard/dashboard.jsx
@@ -40,7 +40,7 @@ function WeightedEmailList({
handlePageChange,
requestSummaries,
}) {
- const [WEEmails, setWEEmails] = useState([]);
+ const [WEEmails, setWEEmails] = useState(startMiniView(emailList.length));
useEffect(() => {
async function fetchEmails() {
@@ -53,18 +53,6 @@ function WeightedEmailList({
}
fetchEmails();
}, [emailList, requestSummaries]);
- // const emails = async () => {
- // const WEList = getTop5(emailList);
- // let needSummaries = WEList.filter(
- // (email) => email.summary_text.length < 1 && email.keywords.length < 1
- // );
- // if (needSummaries.legnth > 0) await requestSummaries(needSummaries);
- // const returnBlock = [];
- // for (let i = 0; i < WEList.length; i++) {
- // returnBlock.push();
- // }
- // return returnBlock;
- // };
return (
{WEEmails.map((email) => {
@@ -85,7 +73,21 @@ function WEListEmail({ email, setCurEmail, handlePageChange }) {
const summary = () => {
let returnBlock;
if (email.summary_text.length > 0) {
- returnBlock =
{email.summary_text}
;
+ returnBlock = (
+ <>
+
{email.summary_text}
+
{
+ setCurEmail(email); // Will not be reached when no email is present
+ handlePageChange("/client/inbox");
+ }}
+ >
+
+
+ >
+ );
} else {
returnBlock =
;
}
@@ -93,18 +95,12 @@ function WEListEmail({ email, setCurEmail, handlePageChange }) {
};
return (
-
+
0 ? "" : " solo"
+ }`}
+ >
{summary()}
-
{
- setCurEmail(email);
- handlePageChange("/client/inbox");
- }}
- >
-
-
);
}
@@ -133,4 +129,12 @@ WEListEmail.propTypes = {
email: PropTypes.object,
};
+const startMiniView = (size) => {
+ let toReturn = [];
+ for (let i = 0; i < Math.min(size, 5); i++) {
+ toReturn.push({ email_id: i, summary_text: "" });
+ }
+ return toReturn;
+};
+
export default Dashboard;
From 87d0ce5a60532d970158028c627c83fcadd0e626 Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Thu, 12 Jun 2025 18:43:07 -0700
Subject: [PATCH 29/38] Link Summaries & Email Fetching To Inbox
---
frontend/src/components/client/client.jsx | 22 +++++----
.../src/components/client/inbox/inbox.jsx | 48 ++++++++++++++-----
frontend/src/emails/emailHandler.js | 10 ++--
3 files changed, 52 insertions(+), 28 deletions(-)
diff --git a/frontend/src/components/client/client.jsx b/frontend/src/components/client/client.jsx
index b87022f..97514d5 100644
--- a/frontend/src/components/client/client.jsx
+++ b/frontend/src/components/client/client.jsx
@@ -149,22 +149,22 @@ function Client() {
};
const handleRequestSummaries = async (emails) => {
- let curEmails = client.emails;
+ const allEmails = client.emails;
+ const ids = emails.map((email) => {
+ return email.email_id;
+ });
console.log("In handle request summaries");
-
const result = await Promise.all(
- emails.map((email) => setSummary(email, curEmails))
+ allEmails.map((email) => {
+ let newEmail = email;
+ if (ids.includes(email.email_id)) newEmail = setSummary(email);
+ return newEmail;
+ })
);
- result.forEach((res) => {
- if (res.length > 0) {
- curEmails = res;
- }
- });
-
dispatchClient({
type: "emailAdd",
- email: curEmails,
+ email: result,
});
};
@@ -204,6 +204,8 @@ function Client() {
curEmail={client.curEmail}
requestMoreEmails={requestMoreEmails}
requestSummaries={handleRequestSummaries}
+ hasUnloadedEmails={hasUnloadedEmails}
+ emailsPerPage={emailsPerPage}
/>
}
/>
diff --git a/frontend/src/components/client/inbox/inbox.jsx b/frontend/src/components/client/inbox/inbox.jsx
index 0312af1..f9f535f 100644
--- a/frontend/src/components/client/inbox/inbox.jsx
+++ b/frontend/src/components/client/inbox/inbox.jsx
@@ -1,13 +1,21 @@
import PropTypes from "prop-types";
import { useEffect, useRef, useState } from "react";
import ArrowIcon from "../../../assets/InboxArrow";
-import { emailsPerPage } from "../../../assets/constants";
import EmailDisplay from "./emailDisplay";
import "./emailEntry.css";
import "./emailList.css";
import { trimList } from "../../../emails/emailHandler"; // shared API URL base
-function Inbox({ displaySummaries, emailList, setCurEmail, curEmail }) {
+function Inbox({
+ displaySummaries,
+ emailList,
+ setCurEmail,
+ curEmail,
+ requestMoreEmails,
+ requestSummaries,
+ hasUnloadedEmails,
+ emailsPerPage,
+}) {
const [filteredEmails, setFilteredEmails] = useState(emailList);
useEffect(() => {
@@ -26,6 +34,10 @@ function Inbox({ displaySummaries, emailList, setCurEmail, curEmail }) {
curEmail={curEmail}
onClick={setCurEmail}
handleEmailSearch={handleEmailSearch}
+ requestMoreEmails={requestMoreEmails}
+ requestSummaries={requestSummaries}
+ hasUnloadedEmails={hasUnloadedEmails}
+ emailsPerPage={emailsPerPage}
/>
@@ -74,23 +86,29 @@ function InboxEmailList({
curEmail,
onClick,
handleEmailSearch,
+ requestMoreEmails,
+ requestSummaries,
+ hasUnloadedEmails,
+ emailsPerPage,
}) {
// const [allEmailsLoaded, setAllEmailsLoaded] = useState(false);
// const [loadingEmails, setLoadingEmails] = useState(false);
const [pages, setPages] = useState(1);
const ref = useRef(null);
const maxEmails = Math.min(pages * emailsPerPage, emailList.length);
- const hasUnloadedEmails = maxEmails < emailList.length;
+ const hasLocallyUnloadedEmails = maxEmails < emailList.length;
- const handleScroll = () => {
- // add external summary call
+ const handleScroll = async () => {
const fullyScrolled =
Math.abs(
ref.current.scrollHeight -
ref.current.clientHeight -
ref.current.scrollTop
) <= 1;
- if (fullyScrolled && hasUnloadedEmails) {
+ if (fullyScrolled && (hasLocallyUnloadedEmails || hasUnloadedEmails)) {
+ if (hasUnloadedEmails) {
+ await requestMoreEmails();
+ }
setPages(pages + 1);
}
};
@@ -116,7 +134,7 @@ function InboxEmailList({
/>
);
}
- // if (needsSummary.length > 0) getPageSummaries(needsSummary);
+ if (needsSummary.length > 0) requestSummaries(needsSummary);
return returnBlock;
};
return (
@@ -154,11 +172,19 @@ function InboxEmailList({
}
// PropTypes
-Inbox.propTypes = {
+
+const sharedPropTypes = {
displaySummaries: PropTypes.bool,
emailList: PropTypes.array,
- setCurEmail: PropTypes.func,
curEmail: PropTypes.object,
+ requestMoreEmails: PropTypes.func,
+ requestSummaries: PropTypes.func,
+ hasUnloadedEmails: PropTypes.bool,
+ emailsPerPage: PropTypes.number,
+};
+Inbox.propTypes = {
+ ...sharedPropTypes,
+ setCurEmail: PropTypes.func,
};
EmailEntry.propTypes = {
@@ -169,9 +195,7 @@ EmailEntry.propTypes = {
};
InboxEmailList.propTypes = {
- displaySummaries: PropTypes.bool,
- emailList: PropTypes.array,
- curEmail: PropTypes.object,
+ ...sharedPropTypes,
onClick: PropTypes.func,
handleEmailSearch: PropTypes.func,
};
diff --git a/frontend/src/emails/emailHandler.js b/frontend/src/emails/emailHandler.js
index e2e637c..3732158 100644
--- a/frontend/src/emails/emailHandler.js
+++ b/frontend/src/emails/emailHandler.js
@@ -111,16 +111,14 @@ async function getSummary(emailId) {
}
}
-export async function setSummary(email, emails) {
- let curEmails = emails;
+export async function setSummary(email) {
let curEmail = email;
const summary = await getSummary(email.email_id);
- if (!summary.valid) return [];
+ console.log(`${email.email_id}`);
+ if (!summary.valid) return email;
curEmail.keywords = summary.keywords;
curEmail.summary_text = summary.summary_text;
- const index = curEmails.indexOf(email);
- curEmails[index] = curEmail;
- return curEmails;
+ return curEmail;
}
function parseDate(date) {
From 8d80c47d84631f7cb05925b0876547060f606676 Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Fri, 13 Jun 2025 20:34:11 -0700
Subject: [PATCH 30/38] Commit
---
frontend/src/components/client/client.jsx | 39 +++++++++++--------
.../components/client/dashboard/dashboard.jsx | 9 +++--
frontend/src/emails/emailHandler.js | 21 ++++++----
3 files changed, 41 insertions(+), 28 deletions(-)
diff --git a/frontend/src/components/client/client.jsx b/frontend/src/components/client/client.jsx
index 97514d5..69895ec 100644
--- a/frontend/src/components/client/client.jsx
+++ b/frontend/src/components/client/client.jsx
@@ -107,21 +107,21 @@ function Client() {
// add emails to the Front
dispatchClient({
type: "emailAdd",
- email: [...emailsToAdd, ...client.emails],
+ theEmails: [...emailsToAdd, ...client.emails],
});
} else {
// add emails to the back
dispatchClient({
type: "emailAdd",
- email: [...client.emails, ...emailsToAdd],
+ theEmails: [...client.emails, ...emailsToAdd],
});
}
};
- const handleSetEmails = (emails) => {
+ const handleSetEmails = async (emails) => {
dispatchClient({
type: "emailAdd",
- email: emails,
+ theEmails: emails,
});
};
@@ -141,7 +141,9 @@ function Client() {
}
};
- const handleSetCurEmail = (email) => {
+ const handleSetCurEmail = async (email) => {
+ console.log("setting to email");
+ console.log(email);
dispatchClient({
type: "emailChange",
email: email,
@@ -149,22 +151,27 @@ function Client() {
};
const handleRequestSummaries = async (emails) => {
- const allEmails = client.emails;
const ids = emails.map((email) => {
return email.email_id;
});
- console.log("In handle request summaries");
- const result = await Promise.all(
- allEmails.map((email) => {
- let newEmail = email;
- if (ids.includes(email.email_id)) newEmail = setSummary(email);
- return newEmail;
- })
- );
-
+ const result = setSummary(ids, client.emails);
+ const settledEmails = await Promise.allSettled(result);
+ const toSet = settledEmails
+ .filter((r) => r.status === "fulfilled")
+ .map((r) => r.value || r.result);
+ // console.log("In handle request summaries");
+ // const result = await Promise.all(
+ // allEmails.map((email) => {
+ // let newEmail = email;
+ // if (ids.includes(email.email_id)) newEmail = setSummary(email);
+ // return newEmail;
+ // })
+ // );
+ console.log("setting to summary");
+ console.log(toSet);
dispatchClient({
type: "emailAdd",
- email: result,
+ email: toSet,
});
};
diff --git a/frontend/src/components/client/dashboard/dashboard.jsx b/frontend/src/components/client/dashboard/dashboard.jsx
index d427929..55f710c 100644
--- a/frontend/src/components/client/dashboard/dashboard.jsx
+++ b/frontend/src/components/client/dashboard/dashboard.jsx
@@ -40,14 +40,15 @@ function WeightedEmailList({
handlePageChange,
requestSummaries,
}) {
+ console.log(emailList);
const [WEEmails, setWEEmails] = useState(startMiniView(emailList.length));
useEffect(() => {
async function fetchEmails() {
- const WEList = getTop5(emailList);
- let needSummaries = WEList.filter((email) => {
- return email.summary_text.length < 1 && email.keywords.length < 1;
- });
+ const WEList = getTop5(emailList) || [];
+ let needSummaries = WEList.filter(
+ (email) => email.summary_text.length < 1 && email.keywords.length < 1
+ );
if (needSummaries.length > 0) await requestSummaries(needSummaries);
setWEEmails(WEList);
}
diff --git a/frontend/src/emails/emailHandler.js b/frontend/src/emails/emailHandler.js
index 3732158..7dad29b 100644
--- a/frontend/src/emails/emailHandler.js
+++ b/frontend/src/emails/emailHandler.js
@@ -111,14 +111,19 @@ async function getSummary(emailId) {
}
}
-export async function setSummary(email) {
- let curEmail = email;
- const summary = await getSummary(email.email_id);
- console.log(`${email.email_id}`);
- if (!summary.valid) return email;
- curEmail.keywords = summary.keywords;
- curEmail.summary_text = summary.summary_text;
- return curEmail;
+export async function setSummary(ids, allEmails) {
+ const result = allEmails.map(async (email) => {
+ let toReturn = email;
+ if (ids.includes(email.email_id)) {
+ const summary = await getSummary(email.email_id);
+ if (!summary.valid) return toReturn;
+ toReturn.keywords = summary.keywords;
+ toReturn.summary_text = summary.summary_text;
+ console.log(`Summary of ${email.email_id} has been fetched`);
+ }
+ return toReturn;
+ });
+ return result;
}
function parseDate(date) {
From 2cc540a27139586bfd745e35c0fbc3820fdf8d9f Mon Sep 17 00:00:00 2001
From: S-Shahla <143126171+S-Shahla@users.noreply.github.com>
Date: Fri, 13 Jun 2025 22:14:20 -0700
Subject: [PATCH 31/38] Summaries Fetch Syncronus
---
frontend/src/components/client/client.jsx | 25 ++++++++---------------
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/frontend/src/components/client/client.jsx b/frontend/src/components/client/client.jsx
index 69895ec..2cd78b3 100644
--- a/frontend/src/components/client/client.jsx
+++ b/frontend/src/components/client/client.jsx
@@ -107,21 +107,23 @@ function Client() {
// add emails to the Front
dispatchClient({
type: "emailAdd",
- theEmails: [...emailsToAdd, ...client.emails],
+ email: [...emailsToAdd, ...client.emails],
});
} else {
// add emails to the back
dispatchClient({
type: "emailAdd",
- theEmails: [...client.emails, ...emailsToAdd],
+ email: [...client.emails, ...emailsToAdd],
});
}
};
const handleSetEmails = async (emails) => {
+ console.log("setting to emails");
+ console.log(emails);
dispatchClient({
type: "emailAdd",
- theEmails: emails,
+ email: emails,
});
};
@@ -142,8 +144,6 @@ function Client() {
};
const handleSetCurEmail = async (email) => {
- console.log("setting to email");
- console.log(email);
dispatchClient({
type: "emailChange",
email: email,
@@ -151,24 +151,17 @@ function Client() {
};
const handleRequestSummaries = async (emails) => {
+ console.log("entered handlerequestssummaries");
const ids = emails.map((email) => {
return email.email_id;
});
- const result = setSummary(ids, client.emails);
+ const result = await setSummary(ids, client.emails);
const settledEmails = await Promise.allSettled(result);
const toSet = settledEmails
.filter((r) => r.status === "fulfilled")
.map((r) => r.value || r.result);
- // console.log("In handle request summaries");
- // const result = await Promise.all(
- // allEmails.map((email) => {
- // let newEmail = email;
- // if (ids.includes(email.email_id)) newEmail = setSummary(email);
- // return newEmail;
- // })
- // );
- console.log("setting to summary");
- console.log(toSet);
+ console.log("setting to emails with summaries");
+ console.log(result);
dispatchClient({
type: "emailAdd",
email: toSet,
From 5d843c38e5620ba610cfcb84484e44c7af449339 Mon Sep 17 00:00:00 2001
From: Joseph Madigan
Date: Sat, 14 Jun 2025 00:46:12 -0700
Subject: [PATCH 32/38] Add JSDoc comments for email handling functions
- Added detailed JSDoc comments for various functions in emailHandler.js, including getNewEmails, handleNewEmails, getUserPreferences, getEmails, getSummary, setSummary, parseDate, fetchEmails, trimList, getTop5, and markEmailAsRead.
- Improved code documentation for better understanding and maintainability.
---
frontend/src/emails/emailHandler.js | 60 +++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/frontend/src/emails/emailHandler.js b/frontend/src/emails/emailHandler.js
index 9202471..9b9b2e0 100644
--- a/frontend/src/emails/emailHandler.js
+++ b/frontend/src/emails/emailHandler.js
@@ -4,6 +4,12 @@ import { fetchUserPreferences } from "../components/client/settings/settings";
// export const baseUrl = "http://127.0.0.1:8000";
export const baseUrl = "https://ee-backend-w86t.onrender.com";
+/**
+ * Filters out emails that already exist in the list.
+ * @param {Array} allEmails - The list of all emails.
+ * @param {Array} requestedEmails - The list of requested emails.
+ * @returns {Array} The list of new emails.
+ */
function getNewEmails(allEmails, requestedEmails) {
return requestedEmails.filter((reqEmail) => {
let exists = false;
@@ -14,6 +20,12 @@ function getNewEmails(allEmails, requestedEmails) {
});
}
+/**
+ * Handles the new emails by filtering out emails that already exist in the list.
+ * @param {Array} allEmails - The list of all emails.
+ * @param {Array} requestedEmails - The list of requested emails.
+ * @returns {Array} The list of new emails.
+ */
export const handleNewEmails = (allEmails, requestedEmails) => {
if (requestedEmails.length > 0) {
const newEmails = getNewEmails(allEmails, requestedEmails);
@@ -24,6 +36,11 @@ export const handleNewEmails = (allEmails, requestedEmails) => {
return [];
};
+/**
+ * Fetches the user preferences from the server.
+ * @param {string} user_id - The ID of the user.
+ * @returns {Promise