-
Notifications
You must be signed in to change notification settings - Fork 96
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
Dedupe saved themes #231
Dedupe saved themes #231
Changes from 4 commits
4185995
b860c7f
d1bf227
ea1e415
c86af7b
be71154
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { actions } from "../../lib/store"; | ||
import { actions, themesEqual } from "../../lib/store"; | ||
import { makeLog } from "../../lib/utils"; | ||
import { normalizeTheme } from "../../lib/themes"; | ||
|
||
|
@@ -17,16 +17,26 @@ const generateThemeKey = () => | |
`${Date.now()}-${Math.floor(Math.random() * 1000)}`; | ||
|
||
function putTheme(key, theme) { | ||
log("putTheme", key, theme); | ||
const storageKey = themeStorageKey(key); | ||
localStorage.setItem( | ||
storageKey, | ||
JSON.stringify({ | ||
theme, | ||
modified: Date.now() | ||
}) | ||
); | ||
notifySelfForStorage(storageKey); | ||
let isThemeDuplicate = checkDuplicateTheme(theme); | ||
if (!isThemeDuplicate) { | ||
log("putTheme", key, theme); | ||
const storageKey = themeStorageKey(key); | ||
localStorage.setItem( | ||
storageKey, | ||
JSON.stringify({ | ||
theme, | ||
modified: Date.now() | ||
}) | ||
); | ||
notifySelfForStorage(storageKey); | ||
} | ||
} | ||
|
||
function checkDuplicateTheme(theme) { | ||
const themesList = listThemes(); | ||
return Object.keys(listThemes()).some((key) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for being annoying... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, I missed that one. Thanks. Will push the changes. |
||
return themesEqual(theme, themesList[key].theme); | ||
}); | ||
} | ||
|
||
function deleteTheme(key) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semi-related, but do we need an
else
statement?Re-reading @johngruen's #166 (comment), it sounded like we may want to pop the newly saved duplicate theme to the front of the list if it was a duplicate. Not sure if the code is currently doing that and I'm just not reading it correctly, or if we need an
else
where we update themodified
date toDate.now()
and do whatever animations we wanted.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the functionality is the main focus here I did not make changes for animation effect. I need help with that. I'm still figuring out how to invoke the animation in
SavedThemeSelector
component when Save button is clicked. Could you please give a hint on how to proceed with that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we merge this code and open a new issue to include animation effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@csd713 I'm cool with doing the animation in a separate issue, you wanna open one up with a link to john's comment from #166 ?
Also this needs a rebase after some changes from this morning before I can merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @meandavejustice that sounds good.
While testing the changes after resolving the conflicts, I found that 'Save' button is disabled if there is no change from 'currentSaved' theme.
One case where this functionality (of checking duplicate saved themes) would be useful is when a user presses 'undo/redo' button and tries to save the same theme again.
So, would you still recommend to add this functionality?
Please let me know if I'm missing something here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdehaan @meandavejustice Could you please review if we still need to fix this issue?
If not, we can close this PR.