Skip to content

Commit 04a722f

Browse files
committed
persist language changes to the db
1 parent 75dfb95 commit 04a722f

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

frontend/src/api/collaboration.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,28 @@ export const updateSession = async (
7272
return resp.json();
7373
};
7474

75+
export const updateSessionLanguage = async (
76+
collabid: string,
77+
language: string
78+
): Promise<SessionFull> => {
79+
const url = `${COLLABORATION_SERVICE}/${collabid}/updateLanguage`;
80+
const resp = await fetch(url, {
81+
method: "POST",
82+
headers: {
83+
"Content-Type": "application/json",
84+
},
85+
body: JSON.stringify({
86+
language: language
87+
}),
88+
});
89+
90+
if (!resp.ok) {
91+
throw new Error("Failed to update the session");
92+
}
93+
94+
return resp.json();
95+
};
96+
7597
export const deleteSessionById = async (
7698
collabid: string
7799
): Promise<SessionFull> => {

frontend/src/app/(user)/dashboard/components/DashboardDataTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const columns: ColumnDef<TCombinedSession>[] = [
6464
},
6565
{
6666
accessorKey: "language",
67-
header: () => <Cell>Language</Cell>,
67+
header: () => <Cell>Matched Language</Cell>,
6868
cell: ({ row }) => {
6969
const language = row.getValue("language") as string;
7070
return (

frontend/src/app/collaboration/components/editor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ function Collaboration({ room, language, code, setLanguage }: Readonly<Props>) {
178178
theme={editorTheme}
179179
setTheme={setEditorTheme}
180180
saving={saving}
181+
room={room}
181182
/>
182183
<div className="w-full h-[1px] mx-auto my-2"></div>
183184
<Editor

frontend/src/app/collaboration/components/toolbar.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import MoonLoader from "react-spinners/MoonLoader";
77
import React from 'react';
88
import Select, { OptionProps } from 'react-select';
99
import { CSSObject } from '@emotion/react';
10+
import { updateSessionLanguage } from "@/api/collaboration";
1011

1112
type Props = {
1213
editor: editor.IStandaloneCodeEditor;
@@ -15,6 +16,7 @@ type Props = {
1516
setLanguage: (language: string) => void;
1617
theme: string;
1718
setTheme: (theme: string) => void;
19+
room: string;
1820
};
1921

2022
type LanguageOption = {
@@ -27,7 +29,7 @@ type ThemeOption = {
2729
label: string;
2830
}
2931

30-
export function Toolbar({ editor, language, saving, setLanguage, theme, setTheme }: Props) {
32+
export function Toolbar({ editor, language, saving, setLanguage, theme, setTheme, room }: Props) {
3133
const languages: LanguageOption[] = [
3234
{ value: 'javascript', label: 'JavaScript' },
3335
{ value: 'python', label: 'Python' },
@@ -36,6 +38,7 @@ export function Toolbar({ editor, language, saving, setLanguage, theme, setTheme
3638
const handleLanguageChange = (selectedOption: LanguageOption | null) => {
3739
if (selectedOption) {
3840
setLanguage(selectedOption.value);
41+
updateSessionLanguage(room, selectedOption.value);
3942
}
4043
};
4144

0 commit comments

Comments
 (0)