Editor is working

This commit is contained in:
Nate Kelley 2025-08-07 13:34:35 -06:00
parent 409af5e02e
commit 7e40fbd769
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
3 changed files with 22 additions and 4 deletions

View File

@ -42,7 +42,6 @@ export type EditorProps = PlateContentProps & VariantProps<typeof editorVariants
export const Editor = React.forwardRef<HTMLDivElement, EditorProps>(
({ className, disabled, focused, variant, ...props }, ref) => {
console.log('Editor', { className, disabled, focused, variant, ...props });
return (
<PlateContent
ref={ref}

View File

@ -5,7 +5,7 @@ import { EditorContainer } from './EditorContainer';
import { Editor } from './Editor';
import { useReportEditor } from './useReportEditor';
import { useMemoizedFn } from '@/hooks';
import { ReportElements } from '@buster/server-shared/reports';
import { ReportElements, type ReportElement } from '@buster/server-shared/reports';
import { cn } from '@/lib/utils';
import { ThemeWrapper } from './ThemeWrapper/ThemeWrapper';
@ -62,7 +62,7 @@ export const ReportEditor = React.memo(
const onValueChangePreflight = useMemoizedFn(
({ value, editor }: { value: Value; editor: TPlateEditor<Value, AnyPluginConfig> }) => {
onValueChange?.(value as ReportElements);
onValueChange?.(cleanValueToReportElements(value));
}
);
@ -92,3 +92,22 @@ export const ReportEditor = React.memo(
);
ReportEditor.displayName = 'ReportEditor';
const cleanValueToReportElements = (value: Value): ReportElements => {
const filteredElements: ReportElements = value
.filter((element) => element.type !== 'slash_input')
.map<ReportElement>((element) => {
// If the element has a children array, filter its children as well
if (Array.isArray(element.children)) {
return {
...element,
children: element.children.filter((child) => {
return child.type !== 'slash_input';
})
} as ReportElement;
}
return element as ReportElement;
});
return filteredElements;
};

View File

@ -26,7 +26,7 @@ export const ReportPageController: React.FC<{
updateReport({ reportId, name });
});
const { run: debouncedUpdateReport } = useDebounceFn(updateReport, { wait: 300 });
const { run: debouncedUpdateReport } = useDebounceFn(updateReport, { wait: 650 });
const onChangeContent = useMemoizedFn((content: ReportElements) => {
debouncedUpdateReport({ reportId, content });