fix: use editable workaround for blocks

This commit is contained in:
swve 2024-01-07 18:15:32 +01:00
parent a05b298c91
commit 21f1f2fd94
10 changed files with 36 additions and 14 deletions

View file

@ -7,6 +7,7 @@ import { getActivityWithAuthHeader } from "@services/courses/activities";
import { getAccessTokenFromRefreshTokenCookie, getNewAccessTokenUsingRefreshTokenServer } from "@services/auth/auth"; import { getAccessTokenFromRefreshTokenCookie, getNewAccessTokenUsingRefreshTokenServer } from "@services/auth/auth";
import { getOrganizationContextInfo, getOrganizationContextInfoWithId } from "@services/organizations/orgs"; import { getOrganizationContextInfo, getOrganizationContextInfoWithId } from "@services/organizations/orgs";
import SessionProvider from "@components/Contexts/SessionContext"; import SessionProvider from "@components/Contexts/SessionContext";
import EditorOptionsProvider from "@components/Contexts/Editor/EditorContext";
type MetadataProps = { type MetadataProps = {
params: { orgslug: string, courseid: string, activityid: string }; params: { orgslug: string, courseid: string, activityid: string };
@ -38,11 +39,11 @@ const EditActivity = async (params: any) => {
console.log('courseInfo', courseInfo) console.log('courseInfo', courseInfo)
return ( return (
<div> <EditorOptionsProvider options={{ isEditable: true }}>
<SessionProvider> <SessionProvider>
<EditorWrapper org={org} course={courseInfo} activity={activity} content={activity.content}></EditorWrapper> <EditorWrapper org={org} course={courseInfo} activity={activity} content={activity.content}></EditorWrapper>
</SessionProvider> </SessionProvider>
</div> </EditorOptionsProvider>
); );
} }

View file

@ -1,3 +1,4 @@
'use client';
import React, { useState } from 'react' import React, { useState } from 'react'

View file

@ -1,13 +1,17 @@
import { useEditorProvider } from "@components/Contexts/Editor/EditorContext";
import { NodeViewContent, NodeViewWrapper } from "@tiptap/react"; import { NodeViewContent, NodeViewWrapper } from "@tiptap/react";
import { AlertCircle } from "lucide-react"; import { AlertCircle } from "lucide-react";
import React from "react"; import React from "react";
import styled from "styled-components"; import styled from "styled-components";
function InfoCalloutComponent(props: any) { function InfoCalloutComponent(props: any) {
const editorState = useEditorProvider() as any;
const isEditable = editorState.isEditable;
return ( return (
<NodeViewWrapper> <NodeViewWrapper>
<InfoCalloutWrapper className="flex space-x-2 items-center bg-blue-200 rounded-lg text-blue-900 px-3 shadow-inner" contentEditable={props.extension.options.editable}> <InfoCalloutWrapper className="flex space-x-2 items-center bg-blue-200 rounded-lg text-blue-900 px-3 shadow-inner" contentEditable={isEditable}>
<AlertCircle /> <NodeViewContent contentEditable={props.extension.options.editable} className="content" /> <AlertCircle /> <NodeViewContent contentEditable={isEditable} className="content" />
</InfoCalloutWrapper> </InfoCalloutWrapper>
</NodeViewWrapper> </NodeViewWrapper>
); );

View file

@ -8,8 +8,6 @@ export default Node.create({
group: "block", group: "block",
draggable: true, draggable: true,
content: "text*", content: "text*",
marks: "",
defining: true,
// TODO : multi line support // TODO : multi line support

View file

@ -1,13 +1,17 @@
import { useEditorProvider } from "@components/Contexts/Editor/EditorContext";
import { NodeViewContent, NodeViewWrapper } from "@tiptap/react"; import { NodeViewContent, NodeViewWrapper } from "@tiptap/react";
import { AlertTriangle } from "lucide-react"; import { AlertTriangle } from "lucide-react";
import React from "react"; import React from "react";
import styled from "styled-components"; import styled from "styled-components";
function WarningCalloutComponent(props: any) { function WarningCalloutComponent(props: any) {
const editorState = useEditorProvider() as any;
const isEditable = editorState.isEditable;
return ( return (
<NodeViewWrapper> <NodeViewWrapper>
<CalloutWrapper className="flex space-x-2 items-center bg-yellow-200 rounded-lg text-yellow-900 px-3 shadow-inner" contentEditable={props.extension.options.editable}> <CalloutWrapper className="flex space-x-2 items-center bg-yellow-200 rounded-lg text-yellow-900 px-3 shadow-inner" contentEditable={isEditable}>
<AlertTriangle /> <NodeViewContent contentEditable={props.extension.options.editable} className="content" /> <AlertTriangle /> <NodeViewContent contentEditable={isEditable} className="content" />
</CalloutWrapper> </CalloutWrapper>
</NodeViewWrapper> </NodeViewWrapper>
); );

View file

@ -8,10 +8,14 @@ import { UploadIcon } from "@radix-ui/react-icons";
import { getActivityBlockMediaDirectory } from "@services/media/media"; import { getActivityBlockMediaDirectory } from "@services/media/media";
import { useOrg } from "@components/Contexts/OrgContext"; import { useOrg } from "@components/Contexts/OrgContext";
import { useCourse } from "@components/Contexts/CourseContext"; import { useCourse } from "@components/Contexts/CourseContext";
import { useEditorProvider } from "@components/Contexts/Editor/EditorContext";
function ImageBlockComponent(props: any) { function ImageBlockComponent(props: any) {
const org = useOrg() as any; const org = useOrg() as any;
const course = useCourse() as any; const course = useCourse() as any;
const editorState = useEditorProvider() as any;
const isEditable = editorState.isEditable;
const [image, setImage] = React.useState(null); const [image, setImage] = React.useState(null);
const [isLoading, setIsLoading] = React.useState(false); const [isLoading, setIsLoading] = React.useState(false);
const [blockObject, setblockObject] = React.useState(props.node.attrs.blockObject); const [blockObject, setblockObject] = React.useState(props.node.attrs.blockObject);
@ -39,8 +43,8 @@ function ImageBlockComponent(props: any) {
return ( return (
<NodeViewWrapper className="block-image"> <NodeViewWrapper className="block-image">
{!blockObject && props.extension.options.editable && ( {!blockObject && isEditable && (
<BlockImageWrapper className="flex items-center space-x-3 py-7 bg-gray-50 rounded-xl text-gray-900 px-3 border-dashed border-gray-150 border-2" contentEditable={props.extension.options.editable}> <BlockImageWrapper className="flex items-center space-x-3 py-7 bg-gray-50 rounded-xl text-gray-900 px-3 border-dashed border-gray-150 border-2" contentEditable={isEditable}>
{isLoading ? ( {isLoading ? (
<Loader className="animate-spin animate-pulse text-gray-200" size={50} /> <Loader className="animate-spin animate-pulse text-gray-200" size={50} />
) : ( ) : (

View file

@ -5,11 +5,13 @@ import "katex/dist/katex.min.css";
import { InlineMath, BlockMath } from "react-katex"; import { InlineMath, BlockMath } from "react-katex";
import { Edit, Save } from "lucide-react"; import { Edit, Save } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import { useEditorProvider } from "@components/Contexts/Editor/EditorContext";
function MathEquationBlockComponent(props: any) { function MathEquationBlockComponent(props: any) {
const [equation, setEquation] = React.useState(props.node.attrs.math_equation); const [equation, setEquation] = React.useState(props.node.attrs.math_equation);
const [isEditing, setIsEditing] = React.useState(true); const [isEditing, setIsEditing] = React.useState(true);
const isEditable = props.extension.options.editable; const editorState = useEditorProvider() as any;
const isEditable = editorState.isEditable;
const handleEquationChange = (event: React.ChangeEvent<any>) => { const handleEquationChange = (event: React.ChangeEvent<any>) => {
setEquation(event.target.value); setEquation(event.target.value);

View file

@ -8,6 +8,7 @@ import { UploadIcon } from "@radix-ui/react-icons";
import { getActivityBlockMediaDirectory } from "@services/media/media"; import { getActivityBlockMediaDirectory } from "@services/media/media";
import { useOrg } from "@components/Contexts/OrgContext"; import { useOrg } from "@components/Contexts/OrgContext";
import { useCourse } from "@components/Contexts/CourseContext"; import { useCourse } from "@components/Contexts/CourseContext";
import { useEditorProvider } from "@components/Contexts/Editor/EditorContext";
function PDFBlockComponent(props: any) { function PDFBlockComponent(props: any) {
const org = useOrg() as any; const org = useOrg() as any;
@ -16,6 +17,8 @@ function PDFBlockComponent(props: any) {
const [isLoading, setIsLoading] = React.useState(false); const [isLoading, setIsLoading] = React.useState(false);
const [blockObject, setblockObject] = React.useState(props.node.attrs.blockObject); const [blockObject, setblockObject] = React.useState(props.node.attrs.blockObject);
const fileId = blockObject ? `${blockObject.content.file_id}.${blockObject.content.file_format}` : null; const fileId = blockObject ? `${blockObject.content.file_id}.${blockObject.content.file_format}` : null;
const editorState = useEditorProvider() as any;
const isEditable = editorState.isEditable;
const handlePDFChange = (event: React.ChangeEvent<any>) => { const handlePDFChange = (event: React.ChangeEvent<any>) => {
setPDF(event.target.files[0]); setPDF(event.target.files[0]);
@ -39,7 +42,7 @@ function PDFBlockComponent(props: any) {
return ( return (
<NodeViewWrapper className="block-pdf"> <NodeViewWrapper className="block-pdf">
{!blockObject && ( {!blockObject && (
<BlockPDFWrapper className="flex items-center space-x-3 py-7 bg-gray-50 rounded-xl text-gray-900 px-3 border-dashed border-gray-150 border-2" contentEditable={props.extension.options.editable}> <BlockPDFWrapper className="flex items-center space-x-3 py-7 bg-gray-50 rounded-xl text-gray-900 px-3 border-dashed border-gray-150 border-2" contentEditable={isEditable}>
{isLoading ? ( {isLoading ? (
<Loader className="animate-spin animate-pulse text-gray-200" size={50} /> <Loader className="animate-spin animate-pulse text-gray-200" size={50} />
) : ( ) : (

View file

@ -4,6 +4,7 @@ import { twJoin, twMerge } from 'tailwind-merge'
import React from "react"; import React from "react";
import { BadgeHelp, Check, Info, Minus, MoreVertical, Plus, RefreshCcw, X } from "lucide-react"; import { BadgeHelp, Check, Info, Minus, MoreVertical, Plus, RefreshCcw, X } from "lucide-react";
import ReactConfetti from "react-confetti"; import ReactConfetti from "react-confetti";
import { useEditorProvider } from "@components/Contexts/Editor/EditorContext";
interface Answer { interface Answer {
answer_id: string; answer_id: string;
@ -22,7 +23,8 @@ function QuizBlockComponent(props: any) {
const [userAnswers, setUserAnswers] = React.useState([]) as [any[], any]; const [userAnswers, setUserAnswers] = React.useState([]) as [any[], any];
const [submitted, setSubmitted] = React.useState(false) as [boolean, any]; const [submitted, setSubmitted] = React.useState(false) as [boolean, any];
const [submissionMessage, setSubmissionMessage] = React.useState("") as [string, any]; const [submissionMessage, setSubmissionMessage] = React.useState("") as [string, any];
const isEditable = props.extension.options.editable; const editorState = useEditorProvider() as any;
const isEditable = editorState.isEditable;
const handleAnswerClick = (question_id: string, answer_id: string) => { const handleAnswerClick = (question_id: string, answer_id: string) => {
// if the quiz is submitted, do nothing // if the quiz is submitted, do nothing

View file

@ -8,10 +8,13 @@ import { getActivityBlockMediaDirectory } from "@services/media/media";
import { UploadIcon } from "@radix-ui/react-icons"; import { UploadIcon } from "@radix-ui/react-icons";
import { useOrg } from "@components/Contexts/OrgContext"; import { useOrg } from "@components/Contexts/OrgContext";
import { useCourse } from "@components/Contexts/CourseContext"; import { useCourse } from "@components/Contexts/CourseContext";
import { useEditorProvider } from "@components/Contexts/Editor/EditorContext";
function VideoBlockComponents(props: any) { function VideoBlockComponents(props: any) {
const org = useOrg() as any; const org = useOrg() as any;
const course = useCourse() as any; const course = useCourse() as any;
const editorState = useEditorProvider() as any;
const isEditable = editorState.isEditable;
const [video, setVideo] = React.useState(null); const [video, setVideo] = React.useState(null);
const [isLoading, setIsLoading] = React.useState(false); const [isLoading, setIsLoading] = React.useState(false);
const [blockObject, setblockObject] = React.useState(props.node.attrs.blockObject); const [blockObject, setblockObject] = React.useState(props.node.attrs.blockObject);
@ -39,7 +42,7 @@ function VideoBlockComponents(props: any) {
return ( return (
<NodeViewWrapper className="block-video"> <NodeViewWrapper className="block-video">
{!blockObject && ( {!blockObject && (
<BlockVideoWrapper className="flex items-center space-x-3 py-7 bg-gray-50 rounded-xl text-gray-900 px-3 border-dashed border-gray-150 border-2" contentEditable={props.extension.options.editable}> <BlockVideoWrapper className="flex items-center space-x-3 py-7 bg-gray-50 rounded-xl text-gray-900 px-3 border-dashed border-gray-150 border-2" contentEditable={isEditable}>
{isLoading ? ( {isLoading ? (
<Loader className="animate-spin animate-pulse text-gray-200" size={50} /> <Loader className="animate-spin animate-pulse text-gray-200" size={50} />
) : ( ) : (