Skip to content

Commit

Permalink
Merge pull request #93 from zetkin/undocumented-route-param-names
Browse files Browse the repository at this point in the history
  • Loading branch information
henrycatalinismith authored May 31, 2024
2 parents a64780c + 33c895b commit cd80125
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export async function PUT(
req: NextRequest,
context: {
params: {
lang: string;
msgId: string;
languageName: string;
messageId: string;
projectName: string;
};
},
) {
const { lang, msgId, projectName } = context.params;
const { languageName, messageId, projectName } = context.params;
const payload = await req.json();
const { text } = payload;
// TODO: include getProjectConfig() and getLyraConfig() in a try/catch block and check for error to return a certain 500 error
Expand All @@ -33,11 +33,11 @@ export async function PUT(
const projectConfig = lyraConfig.getProjectConfigByPath(
serverProjectConfig.projectPath,
);
if (!projectConfig.isLanguageSupported(lang)) {
throw new LanguageNotSupported(lang, projectName);
if (!projectConfig.isLanguageSupported(languageName)) {
throw new LanguageNotSupported(languageName, projectName);
}
const projectStore = await Cache.getProjectStore(projectConfig);
await projectStore.updateTranslation(lang, msgId, text);
await projectStore.updateTranslation(languageName, messageId, text);
} catch (e) {
if (
e instanceof LanguageNotFound ||
Expand All @@ -52,8 +52,8 @@ export async function PUT(
}

return NextResponse.json({
lang,
msgId,
languageName,
messageId,
text,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { NextRequest, NextResponse } from 'next/server';

export async function GET(
req: NextRequest, // keep this here even if unused
context: { params: { lang: string; projectName: string } },
context: { params: { languageName: string; projectName: string } },
) {
const { projectName, lang } = context.params;
const { projectName, languageName } = context.params;
try {
const translations = await Cache.getLanguage(projectName, lang);
const translations = await Cache.getLanguage(projectName, languageName);
return NextResponse.json({
lang,
languageName,
translations,
});
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Box, Button, Input, Link, Typography } from '@mui/joy';
import { useEffect, useMemo, useState } from 'react';

export default function Home(context: {
params: { lang: string; projectName: string };
params: { languageName: string; projectName: string };
}) {
const [filterText, setFilterText] = useState('');
const [messages, setMessages] = useState<MessageData[]>([]);
Expand Down Expand Up @@ -51,7 +51,7 @@ export default function Home(context: {
}, [sortedMessages, filterText]);

const {
params: { lang, projectName },
params: { languageName, projectName },
} = context;

useEffect(() => {
Expand Down Expand Up @@ -83,7 +83,9 @@ export default function Home(context: {

useEffect(() => {
async function loadTranslations() {
const res = await fetch(`/api/translations/${projectName}/${lang}`);
const res = await fetch(
`/api/translations/${projectName}/${languageName}`,
);

try {
const payload = await res.json();
Expand Down Expand Up @@ -180,7 +182,7 @@ export default function Home(context: {
message={msg}
onSave={async (text) => {
await fetch(
`/api/translations/${projectName}/${lang}/${msg.id}`,
`/api/translations/${projectName}/${languageName}/${msg.id}`,
{
body: JSON.stringify({
text,
Expand Down

0 comments on commit cd80125

Please sign in to comment.