Dev #7
@@ -165,17 +165,28 @@ export const DocumentEditor: React.FC<DocumentEditorProps> = ({
|
|||||||
const [showFolderMenu, setShowFolderMenu] = useState<boolean>(false);
|
const [showFolderMenu, setShowFolderMenu] = useState<boolean>(false);
|
||||||
const [zoomedBlockId, setZoomedBlockId] = useState<string | null>(null);
|
const [zoomedBlockId, setZoomedBlockId] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const titleInputRef = useRef<HTMLInputElement | null>(null);
|
||||||
|
const titleDebounceRef = useRef<number | null>(null);
|
||||||
|
const docRef = useRef<Document | null>(doc);
|
||||||
|
docRef.current = doc;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (autoFocusTitle || (doc?.title === 'Neue Notiz' && !doc?.markdownCache)) {
|
if (!loading && (autoFocusTitle || (doc?.title === 'Neue Notiz' && (!doc?.blocks || doc?.blocks.length <= 1)))) {
|
||||||
const timer = setTimeout(() => {
|
const focusTitle = () => {
|
||||||
if (titleInputRef.current) {
|
if (titleInputRef.current) {
|
||||||
titleInputRef.current.focus();
|
titleInputRef.current.focus();
|
||||||
titleInputRef.current.select();
|
titleInputRef.current.select();
|
||||||
}
|
}
|
||||||
}, 60);
|
};
|
||||||
return () => clearTimeout(timer);
|
focusTitle();
|
||||||
|
const t1 = setTimeout(focusTitle, 50);
|
||||||
|
const t2 = setTimeout(focusTitle, 150);
|
||||||
|
return () => {
|
||||||
|
clearTimeout(t1);
|
||||||
|
clearTimeout(t2);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}, [autoFocusTitle]);
|
}, [loading, autoFocusTitle, doc?.id]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (zoomedBlockId && !blocks.some((b) => b.id === zoomedBlockId)) {
|
if (zoomedBlockId && !blocks.some((b) => b.id === zoomedBlockId)) {
|
||||||
@@ -191,11 +202,6 @@ export const DocumentEditor: React.FC<DocumentEditorProps> = ({
|
|||||||
return computeBreadcrumbs(title || doc?.title || 'Dokument', blocks, zoomedBlockId);
|
return computeBreadcrumbs(title || doc?.title || 'Dokument', blocks, zoomedBlockId);
|
||||||
}, [title, doc?.title, blocks, zoomedBlockId]);
|
}, [title, doc?.title, blocks, zoomedBlockId]);
|
||||||
|
|
||||||
const titleInputRef = useRef<HTMLInputElement | null>(null);
|
|
||||||
const titleDebounceRef = useRef<number | null>(null);
|
|
||||||
const docRef = useRef<Document | null>(doc);
|
|
||||||
docRef.current = doc;
|
|
||||||
|
|
||||||
// Crucial fix: Collaborator with write permission can edit!
|
// Crucial fix: Collaborator with write permission can edit!
|
||||||
const canEdit = useMemo(() => {
|
const canEdit = useMemo(() => {
|
||||||
if (!doc) return true;
|
if (!doc) return true;
|
||||||
@@ -342,7 +348,9 @@ export const DocumentEditor: React.FC<DocumentEditorProps> = ({
|
|||||||
// Fetch isolated document state on mount
|
// Fetch isolated document state on mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let isCancelled = false;
|
let isCancelled = false;
|
||||||
setLoading(true);
|
if (!initialDoc) {
|
||||||
|
setLoading(true);
|
||||||
|
}
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
api
|
api
|
||||||
@@ -989,6 +997,7 @@ export const DocumentEditor: React.FC<DocumentEditorProps> = ({
|
|||||||
type="text"
|
type="text"
|
||||||
value={title}
|
value={title}
|
||||||
readOnly={!canEdit}
|
readOnly={!canEdit}
|
||||||
|
autoFocus={autoFocusTitle}
|
||||||
onChange={handleTitleChange}
|
onChange={handleTitleChange}
|
||||||
onBlur={handleTitleBlur}
|
onBlur={handleTitleBlur}
|
||||||
placeholder="Titel der Notiz…"
|
placeholder="Titel der Notiz…"
|
||||||
|
|||||||
Reference in new issue
Block a user