MCPcopy Create free account
hub / github.com/SplootCode/splootcode / EditorBanner

Function EditorBanner

packages/editor/src/components/editor_banner.tsx:6–51  ·  view source on GitHub ↗
(props: { project: Project; onSaveAs: () => void })

Source from the content-addressed store, hash-verified

4import { ChildSetMutation, NodeMutation, Project, ProjectMutation, globalMutationDispatcher } from '@splootcode/core'
5
6export 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}

Callers

nothing calls this directly

Calls 3

registerNodeObserverMethod · 0.80

Tested by

no test coverage detected