Skip to content
Snippets Groups Projects
Commit dd30da7b authored by Simon Künzel's avatar Simon Künzel
Browse files

ts: add semester support to EmbeddedOMFieldComponent

parent fa9c57ef
No related branches found
No related tags found
No related merge requests found
import { useLoaderData } from "react-router-dom";
import { useBackendContext } from "./BackendProvider";
import { semesterToHuman } from "@/misc/Formatting";
import Link from "next/link";
import { Backend } from "@/api/Backend";
import {
......@@ -62,7 +61,15 @@ function ListingHeader({ course }: { course: GetCourseResponse }) {
<tbody>
<tr>
<td>Semester:</td>
<td>{semesterToHuman(course.semester, true)}</td>
<td>
<EmbeddedOMFieldComponent
object_type="course"
object_id={course.id!}
field_id="semester"
field_type="semester_string"
configValue={course.semester}
/>
</td>
</tr>
<tr>
<td>Veranstalter:</td>
......
......@@ -4,7 +4,7 @@ import Modal from "react-bootstrap/Modal";
import { useReloadBoundary } from "./ReloadBoundary";
import { useDebounceUpdateData } from "@/misc/PromiseHelpers";
import { LockEditMode, useEditMode } from "./EditModeProvider";
import { stringToStyledHtml, datetimeToString } from "@/misc/Formatting";
import { stringToStyledHtml, datetimeToString, semesterToHuman } from "@/misc/Formatting";
import { useLanguage } from "./LanguageProvider";
import { basePath } from "../../basepath";
import { showError, showErrorToast } from "@/misc/ErrorHandlers";
......@@ -142,7 +142,7 @@ export function EmbeddedOMFieldComponent({
object_type: string;
object_id: int;
field_id: string;
field_type: "boolean" | "string" | "datetime";
field_type: "boolean" | "string" | "datetime" | "semester_string";
configValue: any;
allowMarkdown?: boolean;
className?: string;
......@@ -160,7 +160,7 @@ export function EmbeddedOMFieldComponent({
const [isEditing, setIsEditing] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
const [field, setField] = useState<field_value | undefined>(undefined);
//We need an additional references since a state is not updated immediately and sometimes the API call fails
//We need an additional references since a state is not updated immediately and sometimes the API call would fail
// due to an unexpected current value. (Only using a ref does not work, since the rendering needs this to indicate
// if changes have been made)
const fieldValueRef = useRef<field_value | undefined>(undefined);
......@@ -275,6 +275,9 @@ export function EmbeddedOMFieldComponent({
case "datetime":
formatted = datetimeToString(value);
break;
case "semester_string":
formatted = semesterToHuman(value, true);
break;
}
return (
<span
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment