-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Saved status #812
base: main
Are you sure you want to change the base?
Saved status #812
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { createContext, useState, useEffect, useRef } from 'react'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please delete this file. |
||
|
||
export let VZCodeContext: React.Context<unknown>; | ||
// @ts-ignore | ||
VZCodeContext = createContext(); | ||
|
||
export const VZCodeProvider = ({ children }) => { | ||
const [files, setFiles] = useState(null); | ||
const [openTab, setOpenTab] = useState(null); | ||
const [isSettingsOpen, setIsSettingsOpen] = useState(false); | ||
const [isDocOpen, setIsDocOpen] = useState(false); | ||
const [isSearchOpen, setIsSearchOpen] = useState(false); | ||
const [connected, setConnected] = useState(true); | ||
const [enableAutoFollow, setEnableAutoFollow] = useState(false); | ||
const [savingStatus, setSavingStatus] = useState('saved'); // New state for saving status | ||
const sidebarRef = useRef(null); | ||
|
||
// Mock function to simulate saving process | ||
const saveChanges = () => { | ||
setSavingStatus('Saving...'); | ||
setTimeout(() => { | ||
setSavingStatus('Saved'); | ||
}, 2000); | ||
}; | ||
|
||
// Mock effect to simulate connection status check | ||
useEffect(() => { | ||
const interval = setInterval(() => { | ||
// Simulate connection check | ||
setConnected(navigator.onLine); | ||
}, 5000); | ||
|
||
return () => clearInterval(interval); | ||
}, []); | ||
|
||
return ( | ||
<VZCodeContext.Provider | ||
value={{ | ||
files, | ||
openTab, | ||
setOpenTab, | ||
isSettingsOpen, | ||
setIsSettingsOpen, | ||
isDocOpen, | ||
setIsDocOpen, | ||
isSearchOpen, | ||
setIsSearchOpen, | ||
connected, | ||
sidebarRef, | ||
enableAutoFollow, | ||
setEnableAutoFollow, | ||
toggleAutoFollow: () => setEnableAutoFollow(prev => !prev), | ||
savingStatus, // Expose saving status in the context | ||
saveChanges, // Expose the save function in the context | ||
}} | ||
> | ||
{children} | ||
</VZCodeContext.Provider> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where
useSavingStatus
is pretty much the same asusePending
from the old example.