Skip to content

Commit

Permalink
[build] fixed indentations, removed redundant comments
Browse files Browse the repository at this point in the history
  • Loading branch information
inhwa-s committed Nov 23, 2024
1 parent 1bb39be commit 0d7a964
Show file tree
Hide file tree
Showing 17 changed files with 159 additions and 175 deletions.
1 change: 1 addition & 0 deletions src/api/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const signUp = async (email, password) => {
email,
password,
});

return response.data;
} catch (error) {
throw new Error(error.response.data.message);
Expand Down
41 changes: 21 additions & 20 deletions src/api/chatCompletion.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
export const chatCompletion = async (keywords) => {
const fetchUrl = `${process.env.NEXT_PUBLIC_LAMBDA_URL}/chat-completion`;

try {
const response = await fetch(fetchUrl, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ keywords }),
});

if (!response.ok) {
return null;
}
const data = await response.json();
return data;
} catch (error) {
console.log(error);
const fetchUrl = `${process.env.NEXT_PUBLIC_LAMBDA_URL}/chat-completion`;

try {
const response = await fetch(fetchUrl, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ keywords }),
});

if (!response.ok) {
return null;
}
};

const data = await response.json();
return data;
} catch (error) {
console.log(error);
return null;
}
};
50 changes: 24 additions & 26 deletions src/api/connectDiary.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
export const connectDiary = async ({ diaryId, credentials }) => {
const fetchUrl = `${process.env.NEXT_PUBLIC_LAMBDA_URL}/connect-diary`;

try {
const response = await fetch(fetchUrl, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
diaryId: diaryId,
connected: '1',
user2: credentials.email,
user2Name: credentials.name,
}),
});
const fetchUrl = `${process.env.NEXT_PUBLIC_LAMBDA_URL}/connect-diary`;

if (!response.ok) {
console.error('Failed to create diary:', response.status);
try {
const response = await fetch(fetchUrl, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
diaryId: diaryId,
connected: '1',
user2: credentials.email,
user2Name: credentials.name,
}),
});

if (!response.ok) {
return null;
}

console.log('Diary connected successfully!');
return await response.json(); // Return the response if needed
} catch (error) {
console.error('Error during diary creation:', error);
return null; // Handle errors gracefully
}
};

return await response.json();
} catch (error) {
console.error('Error during diary creation:', error);
return null;
}
};

11 changes: 4 additions & 7 deletions src/api/createDiary.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export const createDiary = async ({ diaryId, date, credentials }) => {
console.log("createDiary diary info for user:", credentials, diaryId, date);
const fetchUrl = `${process.env.NEXT_PUBLIC_LAMBDA_URL}/create-diary`;

try {
const response = await fetch(fetchUrl, {
method: 'POST',
Expand All @@ -19,15 +18,13 @@ export const createDiary = async ({ diaryId, date, credentials }) => {
});

if (!response.ok) {
console.error('Failed to create diary:', response.status);
return null;
return null;
}

console.log('Diary created successfully!');
return await response.json(); // Return the response if needed
return await response.json();
} catch (error) {
console.error('Error during diary creation:', error);
return null; // Handle errors gracefully
return null;
}
};

40 changes: 20 additions & 20 deletions src/api/extractLabels.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
export const extractLabels = async (s3_url) => {
const fetchUrl = `${process.env.NEXT_PUBLIC_LAMBDA_URL}/extract-labels`;

try {
const response = await fetch(fetchUrl, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ s3_url }),
});

if (!response.ok) {
return null;
}
const data = await response.json();
return data;
} catch (error) {
console.log(error);
const fetchUrl = `${process.env.NEXT_PUBLIC_LAMBDA_URL}/extract-labels`;

try {
const response = await fetch(fetchUrl, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ s3_url }),
});

if (!response.ok) {
return null;
}
};
const data = await response.json();
return data;
} catch (error) {
console.log(error);
return null;
}
};
46 changes: 23 additions & 23 deletions src/api/readDiary.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
export const readDiary = async ({ diaryInfo }) => {
const fetchUrl = `${process.env.NEXT_PUBLIC_LAMBDA_URL}/read-diary`;

try {
const response = await fetch(fetchUrl, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
diaryId: diaryInfo.diaryId,
}),
});
const fetchUrl = `${process.env.NEXT_PUBLIC_LAMBDA_URL}/read-diary`;

if (!response.ok) {
console.error('Failed to write diary:', response.status);
return null;
}

return await response.json(); // Return the response if needed
} catch (error) {
console.error('Error during diary writting:', error);
return null; // Handle errors gracefully
try {
const response = await fetch(fetchUrl, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
diaryId: diaryInfo.diaryId,
}),
});

if (!response.ok) {
console.error('Failed to write diary:', response.status);
return null;
}
};

return await response.json();
} catch (error) {
console.error('Error during diary writting:', error);
return null;
}
};

11 changes: 5 additions & 6 deletions src/api/uploadImage.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
export const uploadImage = async ({credentials, file, diaryInfo }) => {
const fetchUrl = `${process.env.NEXT_PUBLIC_LAMBDA_URL}/upload-image`;

// Create a FormData object
const formData = new FormData();
formData.append('file', file); // Add the image file
formData.append('userId', credentials.email); // Add metadata
formData.append('diaryId', diaryInfo.diaryId); // Add diaryId if applicable
formData.append('name', credentials.name); // Add name if applicable
formData.append('file', file);
formData.append('userId', credentials.email);
formData.append('diaryId', diaryInfo.diaryId);
formData.append('name', credentials.name);

try {
const response = await fetch(fetchUrl, {
method: 'POST',
mode: 'cors',
body: formData, // Use FormData for the request body
body: formData,
});

if (!response.ok) {
Expand Down
54 changes: 27 additions & 27 deletions src/api/writeDiary.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
export const writeDiary = async ({ diaryInfo, credentials, s3_url, keywords }) => {
const fetchUrl = `${process.env.NEXT_PUBLIC_LAMBDA_URL}/write-diary`;

try {
const response = await fetch(fetchUrl, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
diaryId: diaryInfo.diaryId,
labels: keywords,
s3_url: s3_url,
email: credentials.email,
name: credentials.name,
}),
});
const fetchUrl = `${process.env.NEXT_PUBLIC_LAMBDA_URL}/write-diary`;

if (!response.ok) {
console.error('Failed to write diary:', response.status);
return null;
}

return await response.json(); // Return the response if needed
} catch (error) {
console.error('Error during diary writting:', error);
return null; // Handle errors gracefully
try {
const response = await fetch(fetchUrl, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
diaryId: diaryInfo.diaryId,
labels: keywords,
s3_url: s3_url,
email: credentials.email,
name: credentials.name,
}),
});

if (!response.ok) {
console.error('Failed to write diary:', response.status);
return null;
}
};

return await response.json();
} catch (error) {
console.error('Error during diary writting:', error);
return null;
}
};

6 changes: 1 addition & 5 deletions src/components/CreateDiary.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { createDiary } from '../api/createDiary';
import { connectDiary } from '../api/connectDiary';

function Diary({ setDiaryCreated, credentials, setDiaryConnected}) {
const [selectedAccordion, setSelectedAccordion] = useState(""); // To track which accordion is selected
const [selectedAccordion, setSelectedAccordion] = useState("");
const [date, setDate] = useState('');
const [loading, setLoading] = useState(false);
const [diaryId, setDiaryId] = useState("");

// Function to generate a random diary ID
function generateRandomString() {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
Expand All @@ -19,7 +18,6 @@ function Diary({ setDiaryCreated, credentials, setDiaryConnected}) {
return result;
}

// Handle the diary creation form submission
const handleDiaryCreation = async (e) => {
setLoading(true);
e.preventDefault();
Expand All @@ -28,15 +26,13 @@ function Diary({ setDiaryCreated, credentials, setDiaryConnected}) {
setDiaryCreated(true);
};

// Handle Connect Diary button click
const handleConnectDiary = async (e) => {
setLoading(true);
e.preventDefault();
await connectDiary({diaryId, credentials});
setDiaryConnected(true);
};


return (
<div className="DiaryMain">
<div>
Expand Down
6 changes: 3 additions & 3 deletions src/components/DiaryMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const DiaryMain = ({
<CreateDiary setDiaryCreated={setDiaryCreated} setDiaryConnected={setDiaryConnected} credentials={credentials} />
) : !diaryConnected ? (
<WaitingForConnection diaryInfo={diaryInfo} getDiaryInfo={getDiaryInfo} />
) : showReadDiary ? ( // Ensure this is checked before showWriteDiary
) : showReadDiary ? (
<ReadDiary setShowReadDiary={setShowReadDiary} diaryInfo={diaryInfo}/>
) : showWriteDiary ? (
<WriteDiary setShowWriteDiary={setShowWriteDiary} credentials={credentials} diaryInfo={diaryInfo}/>
Expand All @@ -62,13 +62,13 @@ const DiaryMain = ({
</div>
<p>{diaryInfo?.date || 'Unknown date'}{diaryInfo?.days || 0} days</p>
<div className="DiaryIcon" onClick={() => {
setShowWriteDiary(false); // Reset conflicting state
setShowWriteDiary(false);
setShowReadDiary(true);
}}>
<img src="./images/diary.png" alt="Diary" style={{ cursor: 'pointer' }} />
</div>
<button className="BasicButton" onClick={() => {
setShowReadDiary(false); // Reset conflicting state
setShowReadDiary(false);
setShowWriteDiary(true);
}}>
New Entry
Expand Down
Loading

0 comments on commit 0d7a964

Please sign in to comment.