Skip to content

Commit

Permalink
refactor(popup): Avoid rendering "flash" when an entry is continued
Browse files Browse the repository at this point in the history
The "New Entry" message path still caused a window reload. This also refactors the React components to do a nice update instead of deleting the entire DOM and re-mounting the components
  • Loading branch information
tcrammond authored and shantanuraj committed Apr 8, 2019
1 parent d3977d4 commit 026a8d6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/html/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@
</li>
<div id="root-timer"></div>
<div id="root-summary"></div>
<li class="entries-list"></li>
<li class="entries-list">
<div id="root-time-entries-list"></div>
</li>
</ul>


Expand Down
11 changes: 1 addition & 10 deletions src/scripts/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ window.PopUp = {

renderTimer: function () {
const rootElement = document.getElementById('root-timer');
ReactDOM.unmountComponentAtNode(rootElement);
const entry = TogglButton.$curEntry;
ReactDOM.render(<Timer entry={entry} />, rootElement);
},
Expand Down Expand Up @@ -140,7 +139,7 @@ window.PopUp = {
PopUp.renderTimer();
PopUp.renderEntriesList();
PopUp.renderSummary();
} else if (response.type === 'list-continue') {
} else if (response.type === 'list-continue' || response.type === 'New Entry') {
PopUp.renderTimer();
PopUp.renderEntriesList();
} else {
Expand All @@ -165,7 +164,6 @@ window.PopUp = {
},

renderEntriesList: function () {
const html = document.createElement('div');
const entries = TogglButton.$user.time_entries;
if (!entries || entries.length < 1) {
return;
Expand Down Expand Up @@ -211,14 +209,7 @@ window.PopUp = {
return;
}

// Remove old html
while (PopUp.$entries.firstChild) {
PopUp.$entries.removeChild(PopUp.$entries.firstChild);
}

// Render react tree
html.id = 'root-time-entries-list';
PopUp.$entries.appendChild(html);
ReactDOM.render(<TimeEntriesList timeEntries={listEntries} projects={projects} />, document.getElementById('root-time-entries-list'));
},

Expand Down

0 comments on commit 026a8d6

Please sign in to comment.