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

feature/#313 autosave local storage step 1 #350

Merged
merged 11 commits into from
Mar 25, 2024

Conversation

AlbertoSSC
Copy link
Collaborator

Closed #313

const { filename, setFilename, setLoadSample } =
useCanvasViewSettingsContext();

const INTERVAL = 6000;
Copy link
Member

Choose a reason for hiding this comment

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

Interval should be at least 60000 (60 seconds)

}
};

return { stopAutosave };
Copy link
Member

Choose a reason for hiding this comment

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

Missing startAutosave stopAutoSave

const stopAutosave = () => {
if (timerRef.current) {
clearInterval(timerRef.current);
timerRef.current = null;
Copy link
Member

Choose a reason for hiding this comment

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

Missing trying to save on close

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is this possible? what I think is happening is that stopAutosave will be executed when component has already been unmounted, so it doesn't have access to canvasSchema to save it

Copy link
Member

Choose a reason for hiding this comment

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

That's my doubt, well the provider is created at App level, I think it would be a good idea to give a try and check what happens

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved to App level, and still unable to get it to work


export const CanvasPod: React.FC = () => {
const { stopAutosave } = useAutosave();
Copy link
Member

Choose a reason for hiding this comment

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

const { startAutosave, stopAutoSave} = useAutosave();

By doing this we have granular control when we start (component mounted) and stop


React.useEffect(() => {
return stopAutosave;
}, []);
Copy link
Member

Choose a reason for hiding this comment

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

  React.useEffect(() => {
+  startAutosave();
    return stopAutosave;
  }, []);

console.error('File retrieve error', error);
localStorage.removeItem(key);
localStorage.setItem(
'autoSaveFile',
Copy link
Member

Choose a reason for hiding this comment

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

Magic string found, I think we where using a const somewhere?

filename: '',
canvasSchema: createDefaultDatabaseSchemaVm(),
})
);
Copy link
Member

Choose a reason for hiding this comment

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

I think we should remove this code here, if it fails because of error on local storage, it will likely again and it can throw another error, rather to swallow on first instance and that's all

@AlbertoSSC AlbertoSSC closed this Feb 24, 2024
@AlbertoSSC AlbertoSSC reopened this Feb 24, 2024
@AlbertoSSC
Copy link
Collaborator Author

-I can't make the auto save when closing the tab.

+Moved useAutoSave to App level.
+Now we have granular control with starAutosave, stopAutosave and retrieveAutosave.
+if auto save fails twice, it stops
+The modal-dialog is shown when we have more than one autosave in localStorage, and we can choose different actions to do

@brauliodiez brauliodiez merged commit 9425e0c into vnext Mar 25, 2024
1 check passed
@brauliodiez brauliodiez deleted the feature/#313_autosave_localstorage branch March 25, 2024 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autosave local storage, step-1
3 participants