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 all 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
62 changes: 26 additions & 36 deletions src/client/VZSidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {
import React, {
useCallback,
useContext,
useMemo,
useState,
} from 'react';
useMemo } from 'react';
import {
FileId,
FileTree,
Expand All @@ -29,28 +27,17 @@ import { Listing } from './Listing';
import { useDragAndDrop } from './useDragAndDrop';
import './styles.scss';

// TODO turn this UI back on when we are actually detecting
// the connection status.
// See https://github.com/vizhub-core/vzcode/issues/456
const enableConnectionStatus = true;

export const VZSidebar = ({
createFileTooltipText = 'New File',
createDirTooltipText = 'New Directory',
openSettingsTooltipText = 'Open Settings',
openKeyboardShortcuts = 'Keyboard Shortcuts',
reportBugTooltipText = 'Report Bug',
searchToolTipText = 'Search',
filesToolTipText = 'Files',
}: {
createFileTooltipText?: string;
createDirTooltipText?: string;
openSettingsTooltipText?: string;
reportBugTooltipText?: string;
openKeyboardShortcuts?: string;
searchToolTipText?: string;
filesToolTipText?: string;
}) => {
createFileTooltipText = 'New File',
Copy link
Contributor

Choose a reason for hiding this comment

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

Please run npm run prettier to format the files. Thanks!

createDirTooltipText = 'New Directory',
openSettingsTooltipText = 'Open Settings',
openKeyboardShortcuts = 'Keyboard Shortcuts',
reportBugTooltipText = 'Report Bug',
searchToolTipText = 'Search',
filesToolTipText = 'Files',
}) => {
const {
files,
openTab,
Expand All @@ -64,15 +51,18 @@ export const VZSidebar = ({
sidebarRef,
enableAutoFollow,
toggleAutoFollow,
savingStatus,
} = useContext(VZCodeContext);

const fileTree = useMemo(
() => (files ? sortFileTree(getFileTree(files)) : null),
[files],
);

const handleQuestionMarkClick = useCallback(() => {
setIsDocOpen(true);
}, []);

const handleSettingsClick = useCallback(() => {
setIsSettingsOpen(true);
}, []);
Expand All @@ -81,23 +71,20 @@ export const VZSidebar = ({
SplitPaneResizeContext,
);

// On single-click, open the file in a transient tab.
const handleFileClick = useCallback(
(fileId: FileId) => {
openTab({ fileId, isTransient: true });
},
[openTab],
);

// On double-click, open the file in a persistent tab.
const handleFileDoubleClick = useCallback(
(fileId: FileId) => {
openTab({ fileId, isTransient: false });
},
[openTab],
);

// True if files exist.
const filesExist =
fileTree &&
fileTree.children &&
Expand Down Expand Up @@ -225,7 +212,6 @@ export const VZSidebar = ({
</i>
</OverlayTrigger>

{/*Directory Rename*/}
<OverlayTrigger
placement="right"
overlay={
Expand All @@ -242,7 +228,6 @@ export const VZSidebar = ({
</i>
</OverlayTrigger>

{/*Toggle Follow*/}
<OverlayTrigger
placement="right"
overlay={
Expand Down Expand Up @@ -310,14 +295,19 @@ export const VZSidebar = ({
</div>

{enableConnectionStatus && (
<div className="connection-status">
{connected ? 'Connected' : 'Connection Lost'}
<div className="connection">
<div
className={`connection-status-indicator ${
connected ? 'connected' : 'disconnected'
}`}
/>
<div className="status-bar">
<div className="connection-status">
{connected ? 'Connected' : 'Connection Lost'}
<div className="connection">
<div
className={`connection-status-indicator ${
connected ? 'connected' : 'disconnected'
}`}
/>
</div>
</div>
<div className="saving-status">
{savingStatus}
</div>
</div>
)}
Expand Down
25 changes: 25 additions & 0 deletions src/client/VZSidebar/saveChanges.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// DRAFT: DO NOT USE
// Some file handling component
// import { useContext } from 'react';
// import { VZCodeContext } from '../VZCodeContext';
//
// const FileEditor = () => {
// const { saveChanges } = useContext(VZCodeContext);
//
// const handleFileChange = (newContent) => {
// // Handle file content change logic...
// saveChanges(); // Trigger saving process
// };
//
// return (
// <div className="file-editor">
// <textarea
// value={useContext}
// onChange={saveChanges}
// className="file-editor-textarea"
// />
// </div>
// );
// };
//
// export default FileEditor;
Loading