fix: properly migrate from note.colors to note.color

This commit is contained in:
thecodrr
2020-12-07 12:27:51 +05:00
parent 8ef6bab12f
commit bf5eff4cb7
6 changed files with 22 additions and 13 deletions

View File

@@ -7,7 +7,7 @@ import { Flex } from "rebass";
import useMobile from "../../utils/use-mobile";
function Colors(props) {
const { id, colors } = props.data;
const { id, color } = props.data;
const setColor = useStore((store) => store.setColor);
const isMobile = useMobile();
return (
@@ -27,7 +27,7 @@ function Colors(props) {
strokeWidth={0}
data-test-id={`menuitem-colors-${label}`}
/>
{colors.includes(label) && (
{color === label && (
<Icon.Checkmark
data-test-id={`menuitem-colors-${label}-check`}
sx={{

View File

@@ -221,6 +221,6 @@ export default React.memo(Note, function (prevProps, nextProps) {
prevItem.title === nextItem.title &&
prevItem.locked === nextItem.locked &&
prevItem.conflicted === nextItem.conflicted &&
JSON.stringify(prevItem.colors) === JSON.stringify(nextItem.colors)
prevItem.color === nextItem.color
);
});

View File

@@ -24,7 +24,7 @@ const tools = [
function Properties() {
const [notebook, setNotebook] = useState();
const colors = useStore((store) => store.session.colors);
const color = useStore((store) => store.session.color);
const toggleLocked = useStore((store) => store.toggleLocked);
const tags = useStore((store) => store.session.tags);
const sessionId = useStore((store) => store.session.id);
@@ -178,7 +178,7 @@ function Properties() {
{toTitleCase(label)}
</Text>
</Flex>
{colors.includes(label) && (
{color === label && (
<Icon.Checkmark
color="primary"
size={20}

View File

@@ -19,7 +19,7 @@ const DEFAULT_SESSION = {
locked: false,
tags: [],
context: undefined,
colors: [],
color: undefined,
dateEdited: 0,
totalWords: 0,
content: {
@@ -104,7 +104,7 @@ class EditorStore extends BaseStore {
if (oldSession.tags.length !== this.get().session.tags.length)
tagStore.refresh();
if (oldSession.colors.length !== this.get().session.colors.length)
if (oldSession.color !== this.get().session.color)
appStore.refreshColors();
if (!oldSession.context) break storeSync;

View File

@@ -112,13 +112,10 @@ class NoteStore extends BaseStore {
setColor = async (id, color) => {
let note = db.notes.note(id);
if (!note) return;
const shouldUncolor = note.data.colors.indexOf(color) > -1;
for (var c of note.data.colors) {
await note.uncolor(c);
}
const shouldUncolor = note.data.color === color;
if (!shouldUncolor) await db.notes.note(id).color(color);
appStore.refreshColors();
if (!this._syncEditor(note.id, "colors", db.notes.note(id).data.colors)) {
if (!this._syncEditor(note.id, "color", db.notes.note(id).data.color)) {
this.refresh();
}
};

View File

@@ -8962,9 +8962,21 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-3.3.0.tgz#b2e1c4dc4f7c6d57743df733a4f5978d18650559"
integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==
notes-core@../notes-core/:
version "4.0.0"
dependencies:
fast-sort "^2.0.1"
fuzzysearch "^1.0.3"
jshashes "^1.0.8"
no-internet "^1.5.2"
qclone "^1.0.4"
quill-delta-to-html "^0.12.0"
quill-delta-to-markdown "https://github.com/streetwriters/quill-delta-to-markdown"
transfun "^1.0.2"
"notes-core@git+ssh://git@github.com:streetwriters/notesnook-core.git":
version "4.0.0"
resolved "git+ssh://git@github.com:streetwriters/notesnook-core.git#202bfdcc24c347455857c0a8b5e804df68a8b9e2"
resolved "git+ssh://git@github.com:streetwriters/notesnook-core.git#1692099ea401ec66ec6ff7d445c730915eb8b800"
dependencies:
fast-sort "^2.0.1"
fuzzysearch "^1.0.3"