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

added fullscreen button for notes and snippets #602

Closed
wants to merge 14 commits into from
Closed

added fullscreen button for notes and snippets #602

wants to merge 14 commits into from

Conversation

nadr0
Copy link
Contributor

@nadr0 nadr0 commented May 28, 2017

(#547)

allows user to hide the sidebars for fullscreen editing, there is an expand button next to the trash ca., You press it to expand to fullscreen and go back to your old view. Images added below.

I have never used this stack before so I don't quite fully understand react+redux so the code falls back to the dom to edit the divs.

Anyone point me in the right direction to clean the handleFullScreenButton() call?

I would want a hide() function on certain react components? For I could just call those like

handleFullScreenButton (e) {
// somehow have access to these objects?
if(this.state.fullScreen.status) {
    noteDetail.hide()
    mainBody.hide()
    sliderRight.hide()
    slider.hide()
else {
    noteDetail.show()
    mainBody.show()
    sliderRight.show()
    slider.show()
}
}

before
after

Copy link
Contributor

@asmsuechan asmsuechan left a comment

Choose a reason for hiding this comment

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

Thank you for your great PR! 😄
To begin with, could you fix some pointed by eslint?

const noteDetail = document.querySelector(".NoteDetail")
const mainBody = document.querySelector(".Main__body___browser-main-")
const sliderRight = document.querySelector(".Main__slider-right___browser-main-")
const slider = document.querySelector(".Main__slider___browser-main-")
Copy link
Contributor

Choose a reason for hiding this comment

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

Those class names such as .Main__slider___browser-main- depends on the specification of webpack, so could you name any other one to them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to give them Ids because they don't have any other classes on them

status: false,
oldState: {
nd : 0,
mb : 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you change the names? It's hard to understand.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can simply change to them.

fullScreen: false,
widthOfNoteDetail: 0,
widthOfMainBody: 0

<button styleName='control-fullScreenButton'
onMouseDown={(e) => this.handleFullScreenButton(e)}
>
<i className={'fa fa-arrows-alt'} styleName='fullScreen-button' />
Copy link
Contributor

@asmsuechan asmsuechan May 28, 2017

Choose a reason for hiding this comment

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

Probably, you can simply use 'fa fa-arrows-alt'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

err, you still have to leave the fa in the front.

Copy link
Contributor

@asmsuechan asmsuechan May 28, 2017

Choose a reason for hiding this comment

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

Sorry, could you explain the reason more clearly? It works fine at least in my environment (MacOS).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha totally tunnel visioned what you said and didn't realize you mean take off the {}

Copy link
Contributor

Choose a reason for hiding this comment

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

you mean take off the {}

Yes 🙋‍♀️

status: false,
oldState: {
nd : 0,
mb : 0
Copy link
Contributor

Choose a reason for hiding this comment

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

You can simply change to them.

fullScreen: false,
widthOfNoteDetail: 0,
widthOfMainBody: 0

@@ -230,6 +237,34 @@ class MarkdownNoteDetail extends React.Component {
}
}

handleFullScreenButton (e) {

this.state.fullScreen.status = !this.state.fullScreen.status
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use this.state.setState().

const currentScreenState = Object.assign(this.state.fullScreen, {status: !this.state.fullScreen.status})
this.setState({ fullScreen: currentScreenScreen })

@nadr0
Copy link
Contributor Author

nadr0 commented May 28, 2017

eslint is now passing but for some reason a linux test case is now failing when it didn't before.

@@ -230,6 +233,30 @@ class MarkdownNoteDetail extends React.Component {
}
}

handleFullScreenButton (e) {
const currentScreenState = !Object.assign({}, this.state).fullScreen
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that you don't have to use Object.assign (I commented that before I offer you to change the structure of the state).
You can simply write this.setState({ fullScreen: !this.state.fullScreen }).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gotcha, I ended up having to wrap the show/hide code inside the callback of the setState. It wasn't being updated properly so I read the react docs and found " React does not guarantee that the state changes are applied immediately.".

fullScreen: false,
widthOfNoteDetail: 0,
widthOfMainBody: 0

Copy link
Contributor

Choose a reason for hiding this comment

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

extra line 😎

@asmsuechan
Copy link
Contributor

The test occasionally fails 😨

isLocked: false,
fullScreen: false,
widthOfNoteDetail: 0,
widthOfMainBody: 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Alright, let's move on to the architectural review!
First of all, these states should not be placed the component because they're out of the role of it.
I think browser/main/Main.js should manage them rather than MarkdownNoteDetail because those states are overall states for Boostnote, and you'll have to use eventEmitter to call handleFullScreenButton() from MarkdownNoteDetail.
I believe this PR (https://github.com/BoostIO/Boostnote/pull/283/files) is helpful for you!

Copy link
Contributor

@asmsuechan asmsuechan May 29, 2017

Choose a reason for hiding this comment

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

If you don't make out what I say (my English), feel free to ask me anything 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I was concerned about that from the start. I ended up moving the logic/event into browser/main/Main.js like you suggested. I just have emit's inside the MarkdownNoteDetail and the snippet file. I tried to follow the code from the PR you recommend.

Also, thanks for all the help!

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

}

this.fullScreenEditorCode = () => this.handleFullScreenButton()
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer this.toggleFullScreen to this name.

sliderLeft.style.display = 'block'
}
})
}
Copy link
Contributor

@asmsuechan asmsuechan May 30, 2017

Choose a reason for hiding this comment

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

This is the last step (probably 😉). Let's change some codes in order to easy to maintain. To begin with, you can remove variables. I assume slideRight and slideLeft is not required, only noteDetail and mainBody is needed in this method.
Next, you can separate this method into 3, show, hide, and handleFullScreenButton.

  handleFullScreenButton (e) {
    const noteDetail = document.querySelector('.NoteDetail')
    const mainBody = document.querySelector('#main-body')

    this.setState({ fullScreen: !this.state.fullScreen }, () => {
      if (this.state.fullScreen) {
        this.hideLeftLists(noteDetail, mainBody)
      } else {
        this.showLeftLists(noteDetail, mainBody)
      }
    })
  }

  hideLeftLists(noteDetail, mainBody) {
    this.state.noteDetailWidth = noteDetail.style.left
    this.state.mainBodyWidth = mainBody.style.left
    noteDetail.style.left = '0px'
    mainBody.style.left = '0px'
  }

  showLeftLists(noteDetail, mainBody) {
    noteDetail.style.left = this.state.noteDetailWidth
    mainBody.style.left = this.state.mainBodyWidth
  }

And I would like to have your opinion. Do you think the names of each method proper? I think they're not the best.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sliderRight and sliderLeft are important because if you are in the editor mode, the slider bars to move the lists appear through the editor. You would be able to drag those sliders which is not good. I need to turn those off or display none them while you are in fullscreen.

I do like how you separated the code into 3 functions. I do not like the name leftLists, it is not descriptive. I do not quite know what to call them. If they have different names we should use them? I just called them lists because I don't know what else to call them.

Copy link
Contributor

Choose a reason for hiding this comment

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

I cannot reproduce the behavior. Could you tell me more detail?
7402fd6264e5b2d1d41a5df2268b813b

How about showListColumns() and hideListColumns()?

Copy link
Contributor Author

@nadr0 nadr0 May 31, 2017

Choose a reason for hiding this comment

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

If you scan your mouse left to right very slowly in the edit mode. You should be able to find the vertical sliders that allow you to move the lists left and right. That is if you turned off the slider code, so that is why I did display: none.

sample

I think those names are better, columns make more sense.

Copy link
Contributor

@asmsuechan asmsuechan May 31, 2017

Choose a reason for hiding this comment

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

I got it. I think the problem is solved by css. z-index might be helpful. You can apply z-index to those sliders and NoteDetail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you saying edit the CSS files or do it dynamically in the javascript? I can do this tomorrow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please edit the CSS 😄
Thank you so much!

@asmsuechan
Copy link
Contributor

@nadr0 I fixt the broken test, so can you rebase the current master branch?

@nadr0
Copy link
Contributor Author

nadr0 commented Jun 4, 2017

I don't think the rebase ended up working?

@asmsuechan
Copy link
Contributor

asmsuechan commented Jun 5, 2017

@nadr0 Please rebase upstream/master into this branch.

$ git remote set-url upstream git@github.com:BoostIO/Boostnote.git # if you don't set
$ git fetch upstream
$ git checkout master
$ git rebase upstream/master
$ git push -f origin HEAD

@asmsuechan
Copy link
Contributor

@nadr0 You have to delete the merge commit.

$ git branch -b master-backup # just in case
$ git checkout master
$ git reset --hard HEAD^
$ git push -f origin HEAD

@nadr0
Copy link
Contributor Author

nadr0 commented Jun 10, 2017

my git skills aren't up to par 😓

@asmsuechan
Copy link
Contributor

@nadr0 Leave it to me.

@asmsuechan asmsuechan mentioned this pull request Jun 12, 2017
@asmsuechan
Copy link
Contributor

@nadr0 Finally, I decided to handle by using cherry-pick. So I close this PR.
#632

@asmsuechan asmsuechan closed this Jun 12, 2017
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.

2 participants