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

Unify new and edit pages #1423

Closed
wants to merge 78 commits into from
Closed

Conversation

G-Ambatte
Copy link
Collaborator

@G-Ambatte G-Ambatte commented Jul 3, 2021

Draft PR for the unification of the newPage and editPage files. At this point, the code appears to be completely functional and all newPage files have been removed.

CHECKLIST:

  • /new saves to and loads from local storage automatically
  • clicking save on /new redirects to /edit and wipes local storage
  • importing from a Share ID via /new/:id works
  • saving on /edit works locally
  • transfer to/from Google Drive works
  • other functionality that I've currently forgotten about

Notes:
Transfer to/from Google Drive: should work, but testing is required.

Copy link
Member

@calculuschild calculuschild left a comment

Choose a reason for hiding this comment

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

I know this is a lot, so please ask if you disagree with any of it or have questions; this is super awesome work so far and I think it's getting close.

G-Ambatte and others added 12 commits July 4, 2021 17:40
Change to ternary operator for `<NewBrewNavItem />`.

Co-authored-by: Trevor Buckner <calculuschild@gmail.com>
Correcting `saveGoogle` behaviour.

Co-authored-by: Trevor Buckner <calculuschild@gmail.com>
Remove unnecessary `editType` validation checks.

Co-authored-by: Trevor Buckner <calculuschild@gmail.com>
Remove unnecessary default settings for `this.brew`.

Co-authored-by: Trevor Buckner <calculuschild@gmail.com>
Co-authored-by: Trevor Buckner <calculuschild@gmail.com>
@G-Ambatte G-Ambatte requested a review from calculuschild July 7, 2021 09:11

if(this.isNew()) {
console.log('is new');
if((!brew.text && localStorage.getItem(BREWKEY)) && (!brew.style && localStorage.getItem(STYLEKEY))){
Copy link
Member

Choose a reason for hiding this comment

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

This is requiring that the brew must have both empty text and style, and also that both localStorages must be full. If a user only adds text to the localstorage but not the style, this will not load anything from localstorage.

Suggested change
if((!brew.text && localStorage.getItem(BREWKEY)) && (!brew.style && localStorage.getItem(STYLEKEY))){
if(!brew.text || !brew.style){

This way when a new page is loaded, if the brew has any empty tab it will check the localstorage.

Comment on lines 173 to 177
//console.log(this.state.brew.text);
localStorage.setItem(BREWKEY, this.state.brew.text);
localStorage.setItem(STYLEKEY, this.state.brew.style);
this.debounceSave.cancel();
}
Copy link
Member

Choose a reason for hiding this comment

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

Can this all be moved to save()?

trySave() shouldn't have any actual save logic. It's only meant to insert a delay between saves.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It can be moved; save() is called by the Save button click handler but also this automatic save function, so those two states will need to be disambiguated.

Copy link
Member

@calculuschild calculuschild Jul 9, 2021

Choose a reason for hiding this comment

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

trySave() should trigger automatically when a user types (or edits metadata, or changes google Drive status) and we detect that the content has changed. This just sets a timer for SAVE_TIMEOUT miliseconds and ignores any other save requests until that time is up, at which point it calls save(). If the user undoes their change before that happens, the save will not trigger if I remember right.

We can keep the save button calling save() directly since I don't think users want to click and nothing happens for 3 seconds, but otherwise everything else should use trySave() so every little edit doesn't send data to the server. Saving to localStorage can also happen in save() since I don't think there's any real benefit to rewriting the localStorage with every single keystroke.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, absolutely; what I meant is that because save() is called by clicking the SAVE button, it causes the Brew to be saved to the appropriate HB/Google storage and redirects to the /edit page, whereas this automatic saving from /new only saves to localStorage. So if we put it in the save(), we'll need a way to identify that this should be saved to localStorage, not MongoDB or Google Drive.

We could also create a new function, e.g. saveLocal(), and drop the three lines of code into that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm now wondering about a this.saveLocation variable with possible values of Homebrewery, GoogleDrive, BrowserCache, which direct the save() logic. It would be more extensible than just using the single this.saveGoogle boolean.

Probably outside the scope of this PR, though. Maybe in a refactor PR.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I understand now. Yes that sounds like a good approach. I don't mind if you want to add that in so you can move the local storage saving to the save function.

Copy link
Member

@calculuschild calculuschild Jul 9, 2021

Choose a reason for hiding this comment

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

Although you are right it might not be that straightforward. If we set saveLocation to local storage, we'd have to have another check to switch back to googleDrive when the user manually clicks save on the new page.

Could also be a parameter we pass into the save function.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe if saving comes from TrySave, pass a "autosave" parameter to the Save function and then we can handle it in there depending if it's true or false.

@calculuschild calculuschild added the P1 - high priority Obvious bug or popular features label Oct 7, 2021
@calculuschild calculuschild changed the base branch from master to PRODUCTION October 8, 2021 03:24
@calculuschild calculuschild changed the base branch from PRODUCTION to master October 8, 2021 03:24
@calculuschild
Copy link
Member

calculuschild commented Oct 8, 2021

@G-Ambatte What stage is this at now? I know this is a pretty huge task, but unfortunately that makes it easy to fall out of date with the current master branch. Would it be better to break this up into a series of smaller PRs focused on refactoring just one section or function at a time? I think it might be easier to manage (and for me to review).

For instance, take the saving function (or something smaller) that we need to kind of meld two versions together. Update that function on both /new and /edit with the only difference being a flag at the top (if page == "edit") that determines how the function runs. Start copying over bits from /new that need to be in the combined version over to /edit, and vice-versa, even if they aren't going to be used on those pages right now. And slowly make the two pages closer and closer to identical until we can just delete one, and it will all be in sync with the latest and greatest on the Master.

@G-Ambatte
Copy link
Collaborator Author

Superceded by #1799.

@calculuschild
Copy link
Member

Superseded by #1801

@calculuschild calculuschild mentioned this pull request Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 - high priority Obvious bug or popular features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants