Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ffb4dcb
Prise en charge du vocabulaire anglais pour la création de posts
Mar 10, 2025
f30b119
Ajout d'une liste déroulante pour la langue d'écriture
Mar 10, 2025
ce19789
Traductions en anglais
Mar 10, 2025
5a5a785
Modification de la db pour intégrer des échanges entre posts anglais …
Mar 10, 2025
5f627d1
Prise en compte de la nouvelle db pour la création d'un post
Mar 10, 2025
50c4c0e
Correction du bouton pour changer de langue pour que changer dans lan…
Mar 10, 2025
09d41d4
Ajout de la prise en charge du contenu en anglais
Mar 11, 2025
f3c7843
Prise en charge de l'anglais pour la création et l'édition de posts
Mar 11, 2025
7b2b4f2
Test stricte sur la valeur de locale
Mar 11, 2025
b440491
Giga changement permettant de gérer les traductions. Mais ça marche p…
Mar 11, 2025
12dfff9
Retablissement de la db initiale en ajoutant cette fois ci un slugtr …
Mar 11, 2025
5dc1f46
db changée mais osef
Mar 11, 2025
f6634db
Mise en place de l'ajout d'un post en vue d'être traduit lors de la c…
Mar 12, 2025
26ee5c4
Prise en charge de la redirection vers le post traduit
Mar 13, 2025
8f9aac7
Menage du spaghetti code que j'avais ajouté
Mar 13, 2025
5dfc006
Api qui ne sert plus à rien du coup (je sais même pas d'où sort get-l…
Mar 13, 2025
29bc8ba
Merge branch 'Telecom-Etude:main' into main
ImTooFastForYou Mar 13, 2025
7a2d0b3
Fixé l'affichage des noms sur les posts
Mar 15, 2025
2c66e01
Fixed format
Mar 15, 2025
785efb4
Fixed types and format
Mar 15, 2025
56b8e5c
Fixed the locale use to avoid usePathname()
Mar 15, 2025
afd3ea4
Fixed useless modification
Mar 15, 2025
6a7bf75
Removed useless imports
Mar 15, 2025
5241150
Fixed useless modification
Mar 15, 2025
f45fabb
"translated" semble plus approprié
Mar 15, 2025
709df19
Code pour update la db. Attention à son utilisation si des posts exis…
Mar 15, 2025
9e183b8
Renamed the file
Mar 19, 2025
d045d75
Used last elements instead of pop/push
Mar 19, 2025
a16bd05
Got rid of useless db
Mar 19, 2025
cbc7742
Modified it to generate the new column and fixed minor issues
Mar 19, 2025
ccd94d7
Made slugtr not mandatory
Mar 19, 2025
e865d2e
Prettier format fixes
Mar 19, 2025
89011a7
Modified PostPresentation to change slugtr to a string | null type
Mar 19, 2025
4d01705
Tests pour m'assurer que les migrations et l'ajout de slugtr marchent…
Mar 24, 2025
efb7571
Removed the ? to make slugtr non undefined
Mar 24, 2025
05d797b
Added a test on locale to make a difference in the slugs.
Mar 24, 2025
121c6c0
Used constants
Mar 26, 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
6 changes: 3 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ model ContactForm {

model Post {
id Int @id @unique @default(autoincrement())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the prisma extension + formatOnSave.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

title String
title String
locale String
slug String @unique
slug String @unique
slugtr String @unique
authors User[]
content String
content String
validated Boolean @default(false)
labels Label[]
createdAt DateTime @default(now())
Expand Down
65 changes: 65 additions & 0 deletions prisma/update-db.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

choose better name, like "add-slugtr.ts"
We already know it concerns the db as it is inside the prisma folder 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done !

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

async function updateSlugTr() {
await prisma.post.updateMany({
where: {
locale: "fr",
},
data: {
slugtr: {
set: await prisma.$queryRaw`CONCAT(title, '_not_translated')`,
},
},
});

await prisma.post.updateMany({
where: {
locale: "en",
},
data: {
slugtr: {
set: await prisma.$queryRaw`CONCAT(title, '_not_translated')`,
},
},
});
// Cette partie ne devrait pas être incluse si les posts ont une version en français et en anglais car ces derniers seraient dupliqués.
const posts = await prisma.post.findMany({
include: {
authors: true,
labels: true,
},
});

for (const post of posts) {
const newLocale = post.locale === "fr" ? "en" : "fr";

await prisma.post.create({
data: {
title: post.title + "_not_translated",
locale: newLocale,
slugtr: post.slugtr,
slug: post.slug,
authors: {
connect: post.authors.map(author => ({ id: author.id })),
},
content: "",
validated: false,
labels: {
connect: post.labels.map(label => ({ id: label.id })),
},
},
});
}
}

updateSlugTr()
.then(() => {
console.log("Mise à jour terminée");
prisma.$disconnect();
})
.catch(error => {
console.error("Erreur :", error);
prisma.$disconnect();
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ import { useState } from "react";
import { getBlog, renameBlog } from "@/db/blogs";
import { updatePostLabels } from "@/db/labels";
import { Locale } from "@/locales/config";
import { getDictionary } from "@/locales/dictionaries";
import { usePathname } from "next/navigation";
import { isLocale } from "@/locales/config";
import { Dictionary, getDictionary } from "@/locales/dictionaries";

function Rename({ title, id, router, t, locale }: { title: string; id: number; router: AppRouterInstance; t: any; locale: Locale }) {
function Rename({
title,
id,
router,
t,
locale,
}: {
title: string;
id: number;
router: AppRouterInstance;
t: Dictionary["navigation"]["admin"]["editblog"];
locale: Locale;
}) {
return (
<Dialog>
<DialogTrigger asChild>
Expand Down Expand Up @@ -57,23 +67,33 @@ function Rename({ title, id, router, t, locale }: { title: string; id: number; r
);
}

function AddLabel({ getLabels, addRemoveLabel, dbLabels, t }: { getLabels: string[]; addRemoveLabel: (x: string) => void; dbLabels: string[]; t: any }) {
function AddLabel({
getLabels,
addRemoveLabel,
dbLabels,
t,
}: {
getLabels: string[];
addRemoveLabel: (x: string) => void;
dbLabels: string[];
t: Dictionary["navigation"]["admin"]["editblog"];
}) {
return (
<ManyComboBox
selected={getLabels}
addRemove={addRemoveLabel}
items={dbLabels}
vocab={{
title: t.labels.modifylabels,
selectorMessage: t.labels.selectlabels,
selectorMessage: t.labels.selectormessage,
empty: t.labels.empty,
}}
limit={6}
/>
);
}

function OpenSave({ saving, t }: { saving: boolean; t: any }) {
function OpenSave({ saving, t }: { saving: boolean; t: Dictionary["navigation"]["admin"]["editblog"] }) {
return (
<Dialog>
<DialogTrigger asChild>
Expand Down Expand Up @@ -116,8 +136,7 @@ interface ActionProps {
}

export function Actions({ setToBeChanged, content, value, title, id, dbLabels, blogLabels, locale }: ActionProps) {
const localepage = usePathname().split("/")[1] as Locale;
const t = getDictionary(localepage).navigation.admin.editblog;
const t = getDictionary(locale).navigation.admin.editblog;
const [getLabels, setLabels] = useState<string[]>(blogLabels);
const addRemoveLabel = (label: string) => {
var newLabels = getLabels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default async function EditBlog({ params: { postId, locale } }: LocalePos
<h1>{blog.title}</h1>
{blog.validated && <UnValidate locale={locale} id={id} />}
<QuillEditor
locale={blogLocale}
locale={locale}
id={id}
content={JSON.parse(blog.content)}
title={blog.title}
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/(blog)/(admin)/list-blog/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default async function Validation({ params: { locale }, validate }: PageP
<ResizablePanel defaultSize={100}>
<div className="p-10 h-full">
<DataTable
search_column={"title"}
search_column="title"
data={isAdmin ? allData : allData.filter(post => post.emails.includes(session?.email!))}
columns={columns}
filters={[]}
Expand Down
2 changes: 0 additions & 2 deletions src/app/[locale]/(blog)/(admin)/list-blog/select/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import { BtnLink, EmailBtn } from "@/components/telecom-etude/contact";
import { getUserName } from "@/lib/users";
import { Checkbox } from "@/components/ui/checkbox";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { Locale } from "@/locales/config";

function Delete({ row }: { row: Row<ValidationBlogType> }) {
const router = useRouter();
Expand Down
1 change: 0 additions & 1 deletion src/app/[locale]/(blog)/(client)/blog/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ function BlogsList({ posts, locale, t_none }: { t_none: string; posts: PostPrese
) : null} */}
</div>
<p className="italic text-gray text-sm">{post.displayedAuthors}</p>
<p>{post.authors}</p>
<div className="flex space-x-2 pt-2">
{Object.values(post.labels).map((label, i) => (
<p key={i} className="bg-muted rounded-full p-1 px-2">
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/create-blog/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export async function POST(request: Request) {
const { authorEmail, title, locale } = await request.json();
const session = await auth();
if (session?.user.email !== authorEmail) throw new Error("Email mismatch: Not allowed");
const blogId = await createBlog(authorEmail, title, locale, title + "_not_defined");
const blogIdTr = await createBlog(authorEmail, title + "_not_defined", locale === "fr" ? "en" : "fr", title);
const blogId = await createBlog(authorEmail, title, locale, title + "_not_translated");
const blogIdTr = await createBlog(authorEmail, title + "_not_translated", locale === "fr" ? "en" : "fr", title);
return NextResponse.json({ blogId });
} catch (error) {
console.error("[API Error] Failed to create blog:", error);
Expand Down
2 changes: 1 addition & 1 deletion src/db/blogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export async function renameBlog(id: number, title: string, locale: Locale) {
try {
await db.post.update({
where: { id: id },
data: { title: title },
data: { title },
});
} catch (e) {
console.error("[renameLocaleBlog] ", e);
Expand Down
3 changes: 3 additions & 0 deletions src/lib/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ export function getAuthors(authors: string[]) {
console.error("Error while fetching user data.");
return "";
} else if (!beforeLast) {
authors.push(last);
return last;
} else {
authors.push(beforeLast);
authors.push(last);
return authors.reduce((acc, author) => `${acc}${author}, `, "") + `${beforeLast} & ${last}`;
}
}
Expand Down
Loading