import { HashedObject } from '@hyper-hyper-space/core'; import { useObjectState } from '@hyper-hyper-space/react'; import { Button, Paper, Stack, TextField, Typography } from '@mui/material'; import { useEffect, useState, Fragment } from 'react'; import { TextSpace } from '../../../model/text/TextSpace'; import { styled } from '@mui/material'; const FullHeightTextField = styled(TextField)` .MuiInputBase-multiline { height: 100%; } `; function TextSpacePage(props: {entryPoint: TextSpace}) { const [initialized, setInitialized] = useState(false); const [text, setText] = useState(''); const author = props.entryPoint.getAuthor(); const canEdit = author === undefined || author.hasKeyPair(); const textState = useObjectState(props.entryPoint.content); const handleTextChange = (event: React.ChangeEvent) => { setText(event.target.value); }; const saveText = () => { const content = props.entryPoint.content; if (content !== undefined) { content.setValue(text).then(() => { content.saveQueuedOps(); console.log('SAVED') }); } }; useEffect(() => { props.entryPoint.startSync().then(() => { setInitialized(true); }); }, [props.entryPoint]); useEffect(() => { const newText = textState?.value?._value; console.log('got new value for the text: ' + newText) if (newText !== undefined) { setText(newText); } }, [textState]) return { !initialized && Loading... } { initialized && {canEdit && } {(!canEdit && author!==undefined) && Only {author.info?.name || 'its owner'} can edit this file.} } ; } export default TextSpacePage;