Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ const NotebookContentSections: FC<Props> = ({
}, [headings, headings.length]);

useEffect(() => {
if (headings.length) {
const notebookTitleElement = document.querySelector(`#${NOTEBOOK_TITLE}`);
setNotebookTitle(notebookTitleElement?.textContent);
}
}, [headings.length]);
}, []);

useEffect(() => {
const handleOnScroll = () => {
Expand Down
64 changes: 41 additions & 23 deletions front_end/src/app/(main)/notebooks/components/notebook_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { updateNotebook } from "@/app/(main)/questions/actions";
import MarkdownEditor from "@/components/markdown_editor";
import Button from "@/components/ui/button";
import { PostWithNotebook } from "@/types/post";
import Link from "next/link";
import { TournamentType } from "@/types/projects";

interface NotebookEditorProps {
postData: PostWithNotebook;
Expand All @@ -32,37 +34,53 @@ const NotebookEditor: React.FC<NotebookEditorProps> = ({

setIsEditing((prev) => !prev);
};

const defaultProject = postData.projects.default_project;
return (
<div>
<div>
<Button className="p-2" onClick={toggleEditMode}>
<div className="flex">
{[
TournamentType.Tournament,
TournamentType.GlobalLeaderboard,
TournamentType.QuestionSeries,
].includes(defaultProject.type) && (
<Link
className="inline-flex items-center justify-center gap-1 rounded-l rounded-r border-inherit bg-orange-100 p-1.5 text-sm font-medium leading-4 text-orange-900 no-underline hover:bg-orange-200 dark:bg-orange-100-dark dark:text-orange-900-dark hover:dark:bg-orange-200-dark"
href={`/tournament/${defaultProject.slug}`}
>
{defaultProject.name}
</Link>
)}
<Button className="ml-auto p-2" onClick={toggleEditMode}>
{isEditing ? "save" : "edit"}
</Button>
</div>

<div className={classNames("flex flex-col", { hidden: !isEditing })}>
<Field className="my-2 flex items-center gap-1">
<Label>{t("Title")}</Label>
<Input
name="title"
type="text"
className="w-full max-w-[600px] rounded-sm border border-blue-500 p-1 dark:border-blue-500-dark"
value={title}
onChange={(e) => setTitle(e.target.value)}
/>
</Field>
{isEditing && (
<div className={classNames("flex flex-col")}>
<Field className="my-2 flex items-center gap-1">
<Label>{t("Title")}</Label>
<Input
name="title"
type="text"
className="w-full max-w-[600px] rounded-sm border border-blue-500 p-1 dark:border-blue-500-dark"
value={title}
onChange={(e) => setTitle(e.target.value)}
/>
</Field>

<MarkdownEditor
mode="write"
markdown={markdown}
onChange={setMarkdown}
/>
</div>
<MarkdownEditor
mode="write"
markdown={markdown}
onChange={setMarkdown}
/>
</div>
)}

<div className={classNames({ hidden: isEditing })} id={contentId}>
<MarkdownEditor mode="read" markdown={markdown} />
</div>
{!isEditing && (
<div id={contentId}>
<MarkdownEditor mode="read" markdown={markdown} />
</div>
)}
</div>
);
};
Expand Down