Skip to content
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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 107 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/client/VZCodeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ export type VZCodeContextValue = {
sidebarRef: React.RefObject<HTMLDivElement>;

codeEditorRef: React.RefObject<HTMLDivElement>;
savingStatus: string;
setSavingStatus: (status: string) => void;

connected: boolean;

Expand Down Expand Up @@ -355,6 +357,9 @@ export const VZCodeProvider = ({
const [hoveredItemId, setHoveredItemId] =
useState<ItemId | null>(null);

// Implement the saving/saved status
const [savingStatus, setSavingStatus] = useState('All changes saved');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [savingStatus, setSavingStatus] = useState('All changes saved');
const savingStatus = useSavingStatus({shareDBDoc});

where useSavingStatus is pretty much the same as usePending from the old example.


// The value provided by this context.
const value: VZCodeContextValue = {
content,
Expand Down Expand Up @@ -426,6 +431,8 @@ export const VZCodeProvider = ({
codeEditorRef,

connected,
savingStatus,
setSavingStatus,

hoveredItemId,
setHoveredItemId,
Expand Down
60 changes: 60 additions & 0 deletions src/client/VZSidebar/VZCodeContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { createContext, useState, useEffect, useRef } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
);
};
Loading