Update highlights on cache change
This commit is contained in:
parent
7932b65895
commit
4f72c9564d
|
|
@ -24,7 +24,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { defineAsyncComponent, ref, computed, onMounted } from 'vue';
|
import { defineAsyncComponent, ref, computed, onMounted, watch } from 'vue';
|
||||||
import { useStore } from 'vuex';
|
import { useStore } from 'vuex';
|
||||||
import { constructContentComponentBookmarkMutation } from '@/helpers/update-content-bookmark-mutation';
|
import { constructContentComponentBookmarkMutation } from '@/helpers/update-content-bookmark-mutation';
|
||||||
import { useMutation } from '@vue/apollo-composable';
|
import { useMutation } from '@vue/apollo-composable';
|
||||||
|
|
@ -144,6 +144,21 @@ const componentClass = computed(() => {
|
||||||
}
|
}
|
||||||
return classes;
|
return classes;
|
||||||
});
|
});
|
||||||
|
const paragraphs = computed(() =>
|
||||||
|
contentComponentDiv.value ? contentComponentDiv.value.getElementsByTagName('p') : []
|
||||||
|
);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => filteredHighlights.value.length,
|
||||||
|
() => {
|
||||||
|
for (const paragraph of paragraphs.value) {
|
||||||
|
console.log(paragraph);
|
||||||
|
const instance = new Mark(paragraph);
|
||||||
|
instance.unmark();
|
||||||
|
}
|
||||||
|
markHighlights();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const addNote = (id: string) => {
|
const addNote = (id: string) => {
|
||||||
const type = Object.prototype.hasOwnProperty.call(props.parent, '__typename')
|
const type = Object.prototype.hasOwnProperty.call(props.parent, '__typename')
|
||||||
|
|
@ -179,33 +194,28 @@ const bookmarkContent = (bookmarked: boolean) => {
|
||||||
bookmarked,
|
bookmarked,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
console.log(newVars);
|
|
||||||
mutateBookmarkContent(newVars);
|
mutateBookmarkContent(newVars);
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
const markHighlights = () => {
|
||||||
setTimeout(() => {
|
for (const highlight of filteredHighlights.value) {
|
||||||
if (contentComponentDiv.value) {
|
const element = paragraphs.value[highlight.paragraphIndex];
|
||||||
const paragraphs = contentComponentDiv.value.getElementsByTagName('p');
|
const instance = new Mark(element);
|
||||||
for (const highlight of filteredHighlights.value) {
|
const ranges: Mark.Range[] = [
|
||||||
console.log(paragraphs);
|
{
|
||||||
console.log(highlight);
|
start: highlight.startPosition,
|
||||||
|
length: highlight.selectionLength,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
instance.markRanges(ranges, {
|
||||||
|
className: `highlight highlight--${highlight.color}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const element = paragraphs[highlight.paragraphIndex];
|
onMounted(() => {
|
||||||
console.log(element);
|
console.log('onMounted ContentComponent called');
|
||||||
const instance = new Mark(element);
|
setTimeout(markHighlights, 500);
|
||||||
console.log(instance);
|
|
||||||
const ranges: Mark.Range[] = [
|
|
||||||
{
|
|
||||||
start: highlight.startPosition,
|
|
||||||
length: highlight.startPosition,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
console.log(ranges);
|
|
||||||
instance.markRanges(ranges);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 2000);
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue