(props: { project: Project; onSaveAs: () => void })
| 4 | import { ChildSetMutation, NodeMutation, Project, ProjectMutation, globalMutationDispatcher } from '@splootcode/core' |
| 5 | |
| 6 | export function EditorBanner(props: { project: Project; onSaveAs: () => void }) { |
| 7 | const { project, onSaveAs } = props |
| 8 | const [mutationCount, setMutationCount] = useState(0) |
| 9 | const [dismissed, setDismissed] = useState(false) |
| 10 | |
| 11 | useEffect(() => { |
| 12 | if (!dismissed) { |
| 13 | const mutationObserver = { |
| 14 | handleNodeMutation: (mutation: NodeMutation) => { |
| 15 | setMutationCount((count) => count + 1) |
| 16 | }, |
| 17 | handleChildSetMutation: (mutation: ChildSetMutation) => { |
| 18 | setMutationCount((count) => count + 1) |
| 19 | }, |
| 20 | handleProjectMutation: (mutation: ProjectMutation) => { |
| 21 | setMutationCount((count) => count + 1) |
| 22 | }, |
| 23 | } |
| 24 | globalMutationDispatcher.registerChildSetObserver(mutationObserver) |
| 25 | globalMutationDispatcher.registerNodeObserver(mutationObserver) |
| 26 | globalMutationDispatcher.registerProjectObserver(mutationObserver) |
| 27 | const cleanup = () => { |
| 28 | globalMutationDispatcher.deregisterNodeObserver(mutationObserver) |
| 29 | globalMutationDispatcher.deregisterChildSetObserver(mutationObserver) |
| 30 | globalMutationDispatcher.deregisterProjectObserver(mutationObserver) |
| 31 | } |
| 32 | return cleanup |
| 33 | } |
| 34 | }, [project, dismissed]) |
| 35 | |
| 36 | if (mutationCount < 3 || dismissed) { |
| 37 | return null |
| 38 | } |
| 39 | |
| 40 | return ( |
| 41 | <Flex bgColor={'blue.900'} justifyContent="center" alignItems={'baseline'}> |
| 42 | <Text mx={1}>This is an example, make a copy to save your progress.</Text> |
| 43 | <Button onClick={() => onSaveAs()} variant="solid" colorScheme={'blue'} size="sm" m={1} px={3}> |
| 44 | Save |
| 45 | </Button>{' '} |
| 46 | <Button onClick={() => setDismissed(true)} size="sm" m={1}> |
| 47 | Dismiss |
| 48 | </Button> |
| 49 | </Flex> |
| 50 | ) |
| 51 | } |
nothing calls this directly
no test coverage detected