Skip to content

Commit

Permalink
enhance Dashboard.tsx: ensure Answers tab shows answers in UI language
Browse files Browse the repository at this point in the history
  • Loading branch information
dankim444 committed Aug 23, 2024
1 parent 4087925 commit e0e3fcd
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 18 deletions.
4 changes: 3 additions & 1 deletion client/public/locales/ar/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
"settings": "الإعدادات",
"statement": "تصريح",
"yes": "نعم",
"your-answers": "إجاباتك"
"your-answers": "إجاباتك",
"done": "انتهى",
"edit-answers": "تحرير إجاباتك"
},
"footer": {
"copyright": "حقوق النشر © 2023 - 2024 - جميع الحقوق محفوظة بواسطة مختبر CSS في جامعة بنسلفانيا",
Expand Down
4 changes: 3 additions & 1 deletion client/public/locales/bn/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
"settings": "সেটিংস",
"statement": "বিবৃতি",
"yes": "হ্যাঁ",
"your-answers": "আপনার উত্তর"
"your-answers": "আপনার উত্তর",
"done": "সম্পন্ন",
"edit-answers": "আপনার উত্তর সম্পাদনা করুন"
},
"footer": {
"copyright": "কপিরাইট © 2023 - 2024 - সমস্ত অধিকার সংরক্ষিত সিএসএস ল্যাব দ্বারা ইউপেন এ",
Expand Down
4 changes: 3 additions & 1 deletion client/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
"settings": "Settings",
"statement": "Statement",
"yes": "yes",
"your-answers": "Your answers"
"your-answers": "Your answers",
"done": "Done",
"edit-answers": "Edit your Answers"
},
"footer": {
"copyright": "Copyright © 2023 - 2024 - All right reserved by CSSLab at UPenn",
Expand Down
4 changes: 3 additions & 1 deletion client/public/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
"settings": "Configuración",
"statement": "Declaración",
"yes": "",
"your-answers": "Tus respuestas"
"your-answers": "Tus respuestas",
"done": "Terminado",
"edit-answers": "Edita tus respuestas"
},
"footer": {
"copyright": "Derechos de autor © 2023 - 2024 - Todos los derechos reservados por CSSLab en UPenn",
Expand Down
4 changes: 3 additions & 1 deletion client/public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
"settings": "Paramètres",
"statement": "Déclaration",
"yes": "oui",
"your-answers": "Vos réponses"
"your-answers": "Vos réponses",
"done": "finie",
"edit-answers": "Modifiez vos réponses"
},
"footer": {
"copyright": "Droits d'auteur © 2023 - 2024 - Tous droits réservés par CSSLab à UPenn",
Expand Down
4 changes: 3 additions & 1 deletion client/public/locales/hi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
"settings": "सेटिंग्स",
"statement": "बयान",
"yes": "हाँ",
"your-answers": "आपके उत्तर"
"your-answers": "आपके उत्तर",
"done": "अंत",
"edit-answers": "अपने उत्तर संपादित करें"
},
"footer": {
"copyright": "कॉपीराइट © 2023 - 2024 - सीएसएस लैब बाय यूपीएनएन के सभी अधिकार सुरक्षित",
Expand Down
4 changes: 3 additions & 1 deletion client/public/locales/ja/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
"settings": "設定",
"statement": "声明",
"yes": "はい",
"your-answers": "あなたの回答"
"your-answers": "あなたの回答",
"done": "終了した",
"edit-answers": "回答を編集する"
},
"footer": {
"copyright": "著作権 © 2023 - 2024 - CSSLab by UPenn によって全著作権所有",
Expand Down
4 changes: 3 additions & 1 deletion client/public/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
"settings": "Configurações",
"statement": "Declaração",
"yes": "sim",
"your-answers": "Suas respostas"
"your-answers": "Suas respostas",
"done": "Finalizada",
"edit-answers": "Edite suas respostas"
},
"footer": {
"copyright": "Copyright © 2023 - 2024 - Todos os direitos reservados pelo CSSLab na UPenn",
Expand Down
4 changes: 3 additions & 1 deletion client/public/locales/ru/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
"settings": "Настройки",
"statement": "Заявление",
"yes": "да",
"your-answers": "Ваши ответы"
"your-answers": "Ваши ответы",
"done": "Законченный",
"edit-answers": "Редактируйте свои ответы"
},
"footer": {
"copyright": "Авторские права © 2023 - 2024 - Все права защищены CSSLab при UPenn",
Expand Down
4 changes: 3 additions & 1 deletion client/public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
"settings": "设置",
"statement": "声明",
"yes": "",
"your-answers": "你的答案"
"your-answers": "你的答案",
"done": "完全的",
"edit-answers": "编辑您的答案"
},
"footer": {
"copyright": "版权所有 © 2023 - 2024 - CSSLab在宾夕法尼亚大学保留所有权利",
Expand Down
14 changes: 8 additions & 6 deletions client/src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ interface Answer {
}

const Dashboard: React.FC = () => {
const { t } = useTranslation();
const { t, i18n } = useTranslation();
const language = i18n.language; // get the current language
const loggedIn = useAppSelector((state) => state.login.loggedIn);
const [answerList, setAnswerList] = useState<Answer[]>([]);
const [activeTab, setActiveTab] = useState<string>("dashboard");
Expand Down Expand Up @@ -81,18 +82,19 @@ const Dashboard: React.FC = () => {
}
}, [loggedIn, navigate]);

const getAnswers = async () => {
const getAnswers = async () => {
if (token === null) return;
try {
Backend.defaults.headers.common["Authorization"] = token;
const response = await Backend.post("/answers/getanswers", {
email: "[email protected]",
language: language, // get answers based on the current UI language
});
if (!Array.isArray(response.data)) {
console.error("Expected an array but got:", response.data);
return;
}

const updatedAnswers = response.data;
const statementIds = updatedAnswers.map(answer => answer.statementId);
const agreementResponse = await Backend.post("/results/agreementPercentage", { statementIds });
Expand Down Expand Up @@ -123,7 +125,7 @@ const Dashboard: React.FC = () => {

useEffect(() => {
getAnswers();
}, []);
}, [language]); // re-fetch answers when the language changes

// Change I_agree or others_agree variable -- Usage:
// For I_agree: handleCheckboxChange(id, 'I_agree')
Expand Down Expand Up @@ -312,7 +314,7 @@ const Dashboard: React.FC = () => {
onClick={useEditAnswer}
className="px-2 py-2 text-white bg-[#2d374a] hover:bg-[#1a202c] rounded-md w-[90px] h-[50px] text-center shadow-md transition duration-300 ease-in-out transform hover:scale-105"
>
{editing ? "Done" : "Edit your Answers"}
{editing ? t('dashboard.done') : t('dashboard.edit-answers')}
</button>
</th>
</tr>
Expand All @@ -329,7 +331,7 @@ const Dashboard: React.FC = () => {
scope="row"
className="min-w-[18rem] max-w-[60rem] px-6 py-4 font-medium text-gray-900 whitespace-normal dark:text-white"
>
{answer.statement.statement}
{(answer.statement as any)[`statement_${language}`] || answer.statement.statement}
</td>
<td className="px-6 py-4">
{editing && (
Expand Down
20 changes: 18 additions & 2 deletions server/routes/answers.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ router.post(
if (err) {
res.json({ ok: false, message: "something went wrong" });
} else {
const languageMap = {
en: "statement",
zh: "statement_zh",
ru: "statement_ru",
pt: "statement_pt",
ja: "statement_ja",
hi: "statement_hi",
fr: "statement_fr",
es: "statement_es",
bn: "statement_bn",
ar: "statement_ar",
};

const language = req.body.language;
const statementColumn = languageMap[language] || "statement"; // default to 'statement' if column is not supported

getSessionId(succ.email)
.then((sessionID) => {
if (sessionID) {
Expand All @@ -106,7 +122,7 @@ router.post(
{
model: statements,
as: "statement",
attributes: ["statement"],
attributes: [statementColumn], // select the correct column based on the language
},
],
order: [["createdAt", "DESC"]],
Expand Down Expand Up @@ -182,7 +198,7 @@ router.post(
others_agree: req.body.others_agree,
others_agree_reason: req.body.others_agree_reason,
perceived_commonsense: req.body.perceived_commonsense,
origLanguage: "en",
origLanguage: req.body.origLanguage,
sessionId: req.body.sessionId,
clientVersion: process.env.GITHUB_HASH,
};
Expand Down

0 comments on commit e0e3fcd

Please sign in to comment.