Skip to content

Commit

Permalink
Merge pull request #1897 from Camc314/fix-prevent-reload
Browse files Browse the repository at this point in the history
Fix Message Appearing on Page Reload
  • Loading branch information
dkanada committed Sep 3, 2020
2 parents c5223cb + f452173 commit 40ba77b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 32 deletions.
10 changes: 2 additions & 8 deletions src/controllers/user/display/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ import autoFocuser from 'autoFocuser';
const UserSettings = userSettings.UserSettings;

export default function (view, params) {
function onBeforeUnload(e) {
if (hasChanges) {
e.returnValue = 'You currently have unsaved changes. Are you sure you wish to leave?';
}
}

let settingsInstance;
let hasChanges;

const userId = params.userId || ApiClient.getCurrentUserId();
const currentSettings = userId === ApiClient.getCurrentUserId() ? userSettings : new UserSettings();
view.addEventListener('viewshow', function () {
window.addEventListener('beforeunload', onBeforeUnload);

view.addEventListener('viewshow', function () {
if (settingsInstance) {
settingsInstance.loadData();
} else {
Expand Down
10 changes: 2 additions & 8 deletions src/controllers/user/home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@ import 'listViewStyle';
const UserSettings = userSettings.UserSettings;

export default function (view, params) {
function onBeforeUnload(e) {
if (hasChanges) {
e.returnValue = 'You currently have unsaved changes. Are you sure you wish to leave?';
}
}

let homescreenSettingsInstance;
let hasChanges;

const userId = params.userId || ApiClient.getCurrentUserId();
const currentSettings = userId === ApiClient.getCurrentUserId() ? userSettings : new UserSettings();
view.addEventListener('viewshow', function () {
window.addEventListener('beforeunload', onBeforeUnload);

view.addEventListener('viewshow', function () {
if (homescreenSettingsInstance) {
homescreenSettingsInstance.loadData();
} else {
Expand Down
10 changes: 2 additions & 8 deletions src/controllers/user/playback/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@ import 'listViewStyle';
const UserSettings = userSettings.UserSettings;

export default function (view, params) {
function onBeforeUnload(e) {
if (hasChanges) {
e.returnValue = 'You currently have unsaved changes. Are you sure you wish to leave?';
}
}

let settingsInstance;
let hasChanges;

const userId = params.userId || ApiClient.getCurrentUserId();
const currentSettings = userId === ApiClient.getCurrentUserId() ? userSettings : new UserSettings();
view.addEventListener('viewshow', function () {
window.addEventListener('beforeunload', onBeforeUnload);

view.addEventListener('viewshow', function () {
if (settingsInstance) {
settingsInstance.loadData();
} else {
Expand Down
10 changes: 2 additions & 8 deletions src/controllers/user/subtitles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ import autoFocuser from 'autoFocuser';
const UserSettings = userSettings.UserSettings;

export default function (view, params) {
function onBeforeUnload(e) {
if (hasChanges) {
e.returnValue = 'You currently have unsaved changes. Are you sure you wish to leave?';
}
}

let subtitleSettingsInstance;
let hasChanges;

const userId = params.userId || ApiClient.getCurrentUserId();
const currentSettings = userId === ApiClient.getCurrentUserId() ? userSettings : new UserSettings();
view.addEventListener('viewshow', function () {
window.addEventListener('beforeunload', onBeforeUnload);

view.addEventListener('viewshow', function () {
if (subtitleSettingsInstance) {
subtitleSettingsInstance.loadData();
} else {
Expand Down

0 comments on commit 40ba77b

Please sign in to comment.