forked from mattermost-community/focalboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mattermost-communityGH-314] Persist and reapply users settings in ma…
…c app Relates to: mattermost-community#314
- Loading branch information
Showing
5 changed files
with
118 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
const keys = ['language', 'theme', 'lastBoardId', 'lastViewId', 'emoji-mart.last', 'emoji-mart.frequently'] | ||
|
||
export function exportUserSettings(): string { | ||
const settings = Object.fromEntries(keys.map((key) => [key, localStorage.getItem(key)])) | ||
settings.timestamp = `${Date.now()}` | ||
return JSON.stringify(settings) | ||
} | ||
|
||
export function importUserSettings(json: string): boolean { | ||
const settings = parseUserSettings(json) | ||
const timestamp = settings.timestamp | ||
const lastTimestamp = localStorage.getItem('timestamp') | ||
if (!timestamp || (lastTimestamp && Number(timestamp) <= Number(lastTimestamp))) { | ||
return false | ||
} | ||
for (const [key, value] of Object.entries(settings)) { | ||
localStorage.setItem(key, value as string) | ||
} | ||
location.reload() | ||
return true | ||
} | ||
|
||
function parseUserSettings(json: string): any { | ||
try { | ||
return JSON.parse(json) | ||
} catch (e) { | ||
return {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters