Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show error message in UI if file path in projects.yaml is wrong #66

Merged
merged 2 commits into from
Mar 30, 2024
Merged
Changes from all commits
Commits
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
39 changes: 29 additions & 10 deletions webapp/src/app/projects/[projectName]/[lang]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function Home(context: {
from: 0,
to: MESSAGES_PER_PAGE,
});
const [error, setError] = useState(false);

const {
params: { lang, projectName },
Expand All @@ -26,13 +27,23 @@ export default function Home(context: {
const res = await fetch(`/api/messages/${projectName}`);
const payload = await res.json();
setMessages(payload.data);
setOffset((prevMsgOffset) => ({
from: 0,
to: Math.min(
prevMsgOffset.from + MESSAGES_PER_PAGE,
payload.data.length,
),
}));
setOffset((prevMsgOffset) => {
try {
return {
from: 0,
to: Math.min(
prevMsgOffset.from + MESSAGES_PER_PAGE,
payload.data.length,
),
};
} catch (error) {
setError(true);
return {
from: 0,
to: MESSAGES_PER_PAGE,
};
}
});
}

loadMessages();
Expand All @@ -41,14 +52,22 @@ export default function Home(context: {
useEffect(() => {
async function loadTranslations() {
const res = await fetch(`/api/translations/${projectName}/${lang}`);
const payload = await res.json();
setTranslations(payload.translations);

try {
const payload = await res.json();

setTranslations(payload.translations);
} catch (error) {
setError(true);
}
}

loadTranslations();
}, []);

return (
return error ? (
'Error: Please refer to server log'
) : (
<main>
<Typography level="h1">Messages</Typography>
<Button
Expand Down