table of contents, an letting og of expand/colapse chapters

This commit is contained in:
كارل مبارك 2021-07-15 16:29:16 +02:00
parent 537494b1aa
commit fea4990406
3 changed files with 43 additions and 30 deletions

View file

@ -46,14 +46,16 @@ export default {
} }
}) })
this.$router.afterEach((to) => { this.$router.afterEach((to, from) => {
this.$store.commit("setTopics", []); if (to.path !== from.path) {
this.$store.commit("setRules", []); this.$store.commit("setTopics", []);
this.$store.commit("setCurStream", to.path.replace("/", "")); this.$store.commit("setRules", []);
if (this.currentStream != "" this.$store.commit("setCurStream", to.path.replace("/", ""));
&& this.streams.find(s => s.name == this.currentStream) if (this.currentStream != ""
) { && this.streams.find(s => s.name == this.currentStream)
this.setUpDoc(this.currentStream); ) {
this.setUpDoc(this.currentStream);
}
} }
}); });
}, },

View file

@ -1,10 +1,9 @@
<template> <template>
<div :class="['body', topic.title]"> <div class="body">
<h3 @click="desiresContent = !desiresContent" class="header"> <h2 class="header">
<span class="expandToggle" v-html="toggleSymbol"></span>
<span>{{ topic.title }}</span> <span>{{ topic.title }}</span>
</h3> </h2>
<div v-if="desiresContent || print"> <div>
<span v-for="message in messagesToShow" :key="message.id"> <span v-for="message in messagesToShow" :key="message.id">
<Message :message="message" :show_message_data="show_message_data" /> <Message :message="message" :show_message_data="show_message_data" />
<span>&nbsp;</span> <span>&nbsp;</span>
@ -25,18 +24,10 @@ export default {
}, },
data() { data() {
return { return {
desiresContent: false, }
};
}, },
props: ["topic", "print", "show_message_data"], props: ["topic", "show_message_data"],
computed: { computed: {
toggleSymbol() {
let r = "";
if (!this.print) {
r = this.desiresContent ? "▼ " : "► ";
}
return r;
},
messagesToShow() { messagesToShow() {
return this.topic.messages return this.topic.messages
.filter(m => !m.responseTo) .filter(m => !m.responseTo)

View file

@ -1,9 +1,24 @@
<template> <template>
<section id="content"> <section>
<h1 class="title">{{ title }}</h1> <h1 class="title">{{ title }}</h1>
<ul>
<li
v-for="topic in sortedTopics"
:key="topic.title"
>
<router-link
:to="`#${toValidID(topic.title)}`"
@click.stop="goTo(`#${toValidID(topic.title)}`)"
>
{{ topic.title }}
</router-link>
</li>
</ul>
<div style="float: none"><div style="page-break-after: always"></div></div>
<Chapter <Chapter
v-for="topic in sortedTopics" v-for="topic in sortedTopics"
:key="topic.title" :key="topic.title"
:id="toValidID(topic.title)"
:topic="topic" :topic="topic"
:print="print" :print="print"
:show_message_data="show_message_data" :show_message_data="show_message_data"
@ -20,6 +35,7 @@ export default {
components: { components: {
Chapter, Chapter,
}, },
props: ["print", "show_message_data"],
computed: { computed: {
...mapState(["currentStream", "streams"]), ...mapState(["currentStream", "streams"]),
...mapGetters(["sortedTopics"]), ...mapGetters(["sortedTopics"]),
@ -29,16 +45,20 @@ export default {
} }
}, },
methods: {}, methods: {
props: ["print", "show_message_data"], toValidID(string) { return (
encodeURIComponent('ch-' + string)
.toLowerCase()
.replace(/\.|%[0-9a-z]{2}/gi, '')
)},
goTo(id) {
document.querySelector(`.${this.currentStream} ${id}`).scrollIntoView()
}
},
}; };
</script> </script>
<style scoped> <style scoped>
#content {
/* max-width: 700px; */
/* background: unset; */
}
@media print { @media print {
.title { .title {
/* display: none; */ /* display: none; */