Skip to content

Commit

Permalink
fix(master-detail): improve the detection when we have to switch betw…
Browse files Browse the repository at this point in the history
…een the master and detail view (by intercepting React updates)

style(master-detail): rename "master/details" to "master/detail" to better match the names used by Facebook
docs: update version number and changelog
  • Loading branch information
Sylvain2703 committed Nov 12, 2019
1 parent 12823f4 commit 28898d3
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 158 deletions.
12 changes: 6 additions & 6 deletions Messenger UWP/CSS/cards.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@ along with Messenger UWP. If not, see <https://www.gnu.org/licenses/>. */


/* Fix cards width on chatbots */
@media all and (max-width: 950px) {
@media (max-width: 950px) {
._3idt {
width: 450px !important;
}
}

@media all and (max-width: 900px) {
@media (max-width: 900px) {
._3idt {
width: 400px !important;
}
}

@media all and (max-width: 850px) {
@media (max-width: 850px) {
._3idt {
width: 350px !important;
}
}

@media all and (max-width: 800px) {
@media (max-width: 800px) {
._3idt {
width: 300px !important;
}
}

@media all and (max-width: 750px) {
@media (max-width: 750px) {
._3idt {
width: 250px !important;
}
}

@media all and (max-width: 400px) {
@media (max-width: 400px) {
._3idt {
width: 200px !important;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License
along with Messenger UWP. If not, see <https://www.gnu.org/licenses/>. */


/* Master/details container */
/* Master/detail container */
._4sp8 {
min-width: auto;
}
Expand All @@ -28,8 +28,8 @@ along with Messenger UWP. If not, see <https://www.gnu.org/licenses/>. */
/* max-height: 100%; TODO: Usefull on v1? */
}

/* Details view only */
._4sp8.details ._1enh {
/* Detail view only */
._4sp8.detail ._1enh {
display: none;
}

Expand All @@ -38,12 +38,12 @@ along with Messenger UWP. If not, see <https://www.gnu.org/licenses/>. */
max-width: 100%;
}

/* Remove separator between Master and details view */
._4sp8.details ._1t2u {
/* Remove separator between Master and detail view */
._4sp8.detail ._1t2u {
border-left: none;
}

/* Fix details view height when master view isn't displayed */
/* Fix detail view height when master view isn't displayed */
._51l0, ._605a, ._2sdm, ._li, ._4sp8 {
height: 100%;
}
27 changes: 27 additions & 0 deletions Messenger UWP/CSS/picture-info.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* This file is part of Messenger UWP.
Copyright (C) 2019 Sylvain Bruyère
Messenger UWP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3.
Messenger UWP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Messenger UWP. If not, see <https://www.gnu.org/licenses/>. */


/* Property item */
._2zn1 {
line-height: normal !important;
height: auto !important;
padding: 8px 0px;
}

/* Property item content (title, details) */
._2zn1 > * {
margin: 3px 0px;
}
4 changes: 1 addition & 3 deletions Messenger UWP/JavaScript/messenger-pwa/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

MessengerPWA.Selectors = {
ROOT_CONTAINER: "_li",
MASTER_DETAILS_CONTAINER: "_4sp8",
MASTER_DETAIL_CONTAINER: "_4sp8",

MASTER_VIEW: "_1enh",
MASTER_VIEW_V2: "_7q1s",
CHAT_ITEM: "_1ht1",
SEARCH_RESULT_ITEM: "._29hk ._225b + ._29hl ._5l37",

INFO_PANEL: "_4_j5",
INFO_PANEL_CONTENT: "_4_j9",
Expand Down
40 changes: 0 additions & 40 deletions Messenger UWP/JavaScript/messenger-pwa/views/chat-list.js

This file was deleted.

114 changes: 114 additions & 0 deletions Messenger UWP/JavaScript/messenger-pwa/views/master-detail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// This file is part of Messenger UWP.
// Copyright (C) 2019 Sylvain Bruyère
//
// Messenger UWP is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.
//
// Messenger UWP is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Messenger UWP. If not, see <https://www.gnu.org/licenses/>.


MessengerPWA.Views.MasterDetail = (function () {
var self = {};

var container = DOM.getByClass(MessengerPWA.Selectors.MASTER_DETAIL_CONTAINER);
var root = DOM.getByClass(MessengerPWA.Selectors.ROOT_CONTAINER);
var rootComponent = null;

/**
* Gets if the detail view has content or not.
*/
self.hasDetailView = function () {
return rootComponent.state.reasonState.detailView != null;
};

/**
* Clears the detail view content.
* Based on a similar code for removing a conversation.
*/
function clearDetailView() {
rootComponent.setState(function (prevState) {
prevState.reasonState.activeThreadID = null;
prevState.reasonState.detailView = null;
prevState.reasonState.serverThreadID = null;
return prevState;
}, function () {
var url = getUrlWithoutThread();
window.history.pushState(url, "", url);
updateViews();
});
}

/**
* Gets the current URL without the thread name, if existing.
*/
function getUrlWithoutThread() {
var url = window.location.href;
var index = url.indexOf("/t/");
if (index > -1)
url = url.substring(0, index) + "/" + window.location.search;
return url;
}

/**
* Updates the displayed views.
*/
function updateViews() {
if (window.innerWidth < 700) {
if (self.hasDetailView()) {
container.classList.remove("master");
container.classList.add("detail");
}
else {
container.classList.add("master");
container.classList.remove("detail");
}
}
else {
container.classList.remove("master");
container.classList.remove("detail");
}
}

/**
* Triggered after the "MessengerReact" component update.
*/
function componentDidUpdate(prevProps, prevState) {
// If the detail view content appears.
if (prevState.reasonState.detailView == null && this.state.reasonState.detailView != null) {
// Ensures the info panel is closed and updates views.
MessengerPWA.Views.InfoPanel.hide();
updateViews();

Navigation.pushToStack(clearDetailView);
}
// If the detail view content disappears.
else if (prevState.reasonState.detailView != null && this.state.reasonState.detailView == null) {
Navigation.popFromStack();
}
}

if (root && container) {
// Gets the root "MessengerReact" component.
rootComponent = ReactInternal.findClosestComponent(root);

// Intercepts the componentDidUpdate calls to know when the state changes.
var originalComponentDidUpdate = rootComponent.componentDidUpdate.bind(rootComponent);
rootComponent.componentDidUpdate = function (prevProps, prevState, snapshot) {
originalComponentDidUpdate(prevProps, prevState, snapshot);
componentDidUpdate.call(rootComponent, prevProps, prevState);
};

clearDetailView();

window.addEventListener("resize", updateViews, false);
}

return self;
})();
93 changes: 0 additions & 93 deletions Messenger UWP/JavaScript/messenger-pwa/views/master-details.js

This file was deleted.

6 changes: 3 additions & 3 deletions Messenger UWP/Messenger UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,17 @@
<None Include="JavaScript\helpers\navigation.js" />
<None Include="JavaScript\helpers\polyfill.js" />
<None Include="JavaScript\helpers\react-internal.js" />
<None Include="JavaScript\messenger-pwa\views\chat-list.js" />
<None Include="JavaScript\messenger-pwa\views\info-panel.js" />
<None Include="JavaScript\messenger-pwa\views\master-details.js" />
<None Include="JavaScript\messenger-pwa\views\master-detail.js" />
<None Include="JavaScript\messenger-pwa\index.js" />
<None Include="JavaScript\messenger-pwa\selectors.js" />
<None Include="JavaScript\messenger-pwa\version.js" />
<None Include="CSS\cancel-media-queries.css" />
<None Include="CSS\cards.css" />
<None Include="CSS\dialogs.css" />
<None Include="CSS\info-panel.css" />
<None Include="CSS\master-details.css" />
<None Include="CSS\master-detail.css" />
<None Include="CSS\picture-info.css" />
<None Include="CSS\settings-panel.css" />
<Compile Include="UserAgent\FakeUserAgent.cs" />
<Compile Include="UserAgent\UserAgentHelper.cs" />
Expand Down

0 comments on commit 28898d3

Please sign in to comment.