Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c42fafb
search user fucntion
RoeeHaim Jun 25, 2025
7122d36
search user fucntion
RoeeHaim Jun 25, 2025
a074d55
route for the fu nc
RoeeHaim Jun 25, 2025
3ea59f4
.
RoeeHaim Jun 25, 2025
a98fbcb
send mail async func
RoeeHaim Jun 25, 2025
ee1fed9
send mail
RoeeHaim Jun 25, 2025
590ff20
option for 2 compose mail like in the real gmail (they have option fo…
RoeeHaim Jun 28, 2025
d31c3d2
when i click on the draft i can continue writing the mail
RoeeHaim Jun 28, 2025
479e503
when i click on the draft i can continue writing the mail
RoeeHaim Jun 28, 2025
d36a203
added function to convert to file
RoeeHaim Jun 28, 2025
f0a58bd
css fix
RoeeHaim Jun 28, 2025
266f026
added a lot of fucntions to the comose mail
RoeeHaim Jun 28, 2025
a79eb25
.
RoeeHaim Jun 28, 2025
133df8c
fix imports
RoeeHaim Jun 28, 2025
1d6d71a
labels
RoeeHaim Jun 29, 2025
5d2e122
labels
RoeeHaim Jun 29, 2025
c25802f
labels
RoeeHaim Jun 29, 2025
53e6b39
labels
RoeeHaim Jun 29, 2025
5c3bf68
labels
RoeeHaim Jun 29, 2025
4e17bb7
labels
RoeeHaim Jun 29, 2025
abe0c76
labels
RoeeHaim Jun 29, 2025
62f7b93
labels
RoeeHaim Jun 29, 2025
eb3ce42
fixed that the mail will be seen in the "sent" and it will not be twi…
RoeeHaim Jun 29, 2025
d4704d1
fix sending link in the mail
RoeeHaim Jun 29, 2025
f27268b
fix sending link in the mail
RoeeHaim Jun 29, 2025
1502fc8
fix sending link in the mail
RoeeHaim Jun 29, 2025
0ad7ba9
fix sending link in the mail
RoeeHaim Jun 29, 2025
c2a0721
refreshMails when i sent mail
RoeeHaim Jun 29, 2025
14fe9d6
GA-111 fixed attachment when sending mail
YuvalAnteby Jun 30, 2025
aa4bf43
Merge remote-tracking branch 'origin/GA-110-Mail-sending-page-fix' in…
YuvalAnteby Jun 30, 2025
eaefa13
GA-110 fixed displaying mail with HTML
YuvalAnteby Jun 30, 2025
e08e533
GA-110 fixed bloom filter checks
YuvalAnteby Jun 30, 2025
82ccac2
GA-110 fixed fetching mail by label
YuvalAnteby Jun 30, 2025
fe7fe3c
GA-110 small UI fix
YuvalAnteby Jun 30, 2025
716e7b7
GA-110 decided to use compose button in side menu mobile UI instead o…
YuvalAnteby Jun 30, 2025
bbef30c
Removed debug prints in mail API file
YuvalAnteby Jun 30, 2025
a85304f
Changed to use one base API URL
YuvalAnteby Jun 30, 2025
d8f34d1
comments got removed for some reason
YuvalAnteby Jun 30, 2025
28daeed
forward and reply fucnt
RoeeHaim Jul 4, 2025
b9d7710
dont need picture
RoeeHaim Jul 4, 2025
f4aa0e1
.
RoeeHaim Jul 4, 2025
0ec4027
fix
RoeeHaim Jul 4, 2025
b88d09e
fix the fix that yuval fixed
RoeeHaim Jul 4, 2025
1331c7a
i hope this is the final fix
RoeeHaim Jul 4, 2025
71cb063
auto refreshMails on drafts as well
RoeeHaim Jul 5, 2025
d155c35
.
RoeeHaim Jul 5, 2025
ccaa450
comments
RoeeHaim Jul 5, 2025
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
90 changes: 90 additions & 0 deletions frontend/src/api/labelsApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// src/api/labelsApi.js

// Base URL — adjust port/host if needed
const API_BASE = "http://localhost:3001/api";
const ROOT = `${API_BASE}/labels`;

/**
* Fetch all labels
* @returns {Promise<Array<{id:number,name:string,parent?:number}>>}
*/
export async function fetchLabels() {
const token = localStorage.getItem("token");
const res = await fetch(ROOT, {
method: "GET",
headers: {
"Authorization": `Bearer ${token}`
}
});
if (!res.ok) throw new Error(`fetchLabels failed: ${res.status}`);
return res.json();
}

/**
* Create a new label
* @param {string} name
*/
export async function createLabel(name) {
const token = localStorage.getItem("token");
const res = await fetch(ROOT, {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ name })
});
if (!res.ok) throw new Error(`createLabel failed: ${res.status}`);
}

/**
* Rename an existing label
* @param {number} id
* @param {string} newName
*/
export async function editLabel(id, newName) {
const token = localStorage.getItem("token");
const res = await fetch(`${ROOT}/${id}`, {
method: "PATCH",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ name: newName })
});
if (!res.ok) throw new Error(`editLabel failed: ${res.status}`);
}

/**
* Delete a label
* @param {number} id
*/
export async function deleteLabel(id) {
const token = localStorage.getItem("token");
const res = await fetch(`${ROOT}/${id}`, {
method: "DELETE",
headers: {
"Authorization": `Bearer ${token}`
}
});
if (!res.ok) throw new Error(`deleteLabel failed: ${res.status}`);
}

/**
* Create a sublabel under a parent label
* @param {number} parentId
* @param {string} name
*/
export async function createLabelUnderParent(parentId, name) {
const token = localStorage.getItem("token");
const res = await fetch(`${ROOT}/${parentId}/sublabel`, {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ name })
});
if (!res.ok) throw new Error(`createLabelUnderParent failed: ${res.status}`);
return res.json();
}
112 changes: 108 additions & 4 deletions frontend/src/api/mailApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ export async function deleteMail(mail) {
headers: {
'Authorization': `Bearer ${token}`,
}
})
if (!res.ok)
throw new Error(`getMails failed: ${res.status}`);
});

if (!res.ok) {
throw new Error(`deleteMail failed: ${res.status}`);
}
}

/**
Expand Down Expand Up @@ -180,4 +182,106 @@ export const searchMails = async (userId, query) => {
if (!res.ok)
throw new Error(`Search failed ${res.status}`);
return res.json();
};
}

/**
* Send a new mail or save as draft.
* @param { {
* subject: string,
* body: string,
* sentTo: String[],
* saveAsDraft?: boolean,
* files: Object[]
* } } mailData
* - subject: email subject
* - body: HTML or plain text body
* - sentTo: list of recipient email addresses
* - saveAsDraft: true to save in Drafts, false to actually send
*/
export async function sendMail({subject, body, sentTo, saveAsDraft = false, files = []}) {
const url = `${API_BASE}/mails`;
const token = localStorage.getItem("token");

// Comments: what we send in the request body
// subject: the mail's subject line
// body: the mail's content (HTML)
// sentTo: array of recipient emails
// saveAsDraft: boolean flag—true = save to Draft folder
const payload = {
subject,
body,
sentTo,
saveAsDraft,
files
};

const res = await fetch(url, {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});

if (!res.ok) {
throw new Error(`sendMail failed: ${res.status}`);
}

return res.json();
}

/**
* PATCH /api/mails/:id
* @param {number} mailId
* @param {{
* subject?: string,
* body?: string,
* sentTo?: string[],
* saveAsDraft?: boolean
* }} data
*/
export async function updateMail(mailId, {
subject,
body,
sentTo,
saveAsDraft = true
}) {
const url = `${API_BASE}/mails/${mailId}`;
const token = localStorage.getItem("token");

const res = await fetch(url, {
method: "PATCH",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({subject, body, sentTo, saveAsDraft})
});

if (!res.ok) throw new Error(`updateMail failed: ${res.status}`);
return res.json();
}

/**
* Fetch mails under a specific label.
*
* @param {Number} labelId label's id
* @param {number} page
* @returns {Promise<{ mails: any[], total: number }>}
*/
export async function getMailsByLabel(labelId, page = 1) {
const token = localStorage.getItem("token");
// note: backend endpoint is the same, just pass label=...
const url = `${API_BASE}/mails?label=${encodeURIComponent(labelId)}&page=${page}&limit=50`;
const res = await fetch(url, {
method: "GET",
headers: {
"Authorization": `Bearer ${token}`
}
});
if (!res.ok) {
throw new Error(`getMailsByLabel failed: ${res.status}`);
}
return res.json();
}
22 changes: 22 additions & 0 deletions frontend/src/api/userApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,25 @@ export async function loginWithJwt(mail, password) {
return 500;
}
}
export async function searchUsers(query) {
try {
const token = localStorage.getItem("token");
const res = await fetch(`${API_BASE}/users/search?q=${encodeURIComponent(query)}`, {
headers: {
"Authorization": `Bearer ${token}`
}
});

if (!res.ok) {
console.error("Search failed:", await res.text());
return [];
}

return await res.json();
} catch (error) {
console.error("Error searching users:", error);
return [];
}
}


Loading