-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTableOfContents.vue
57 lines (47 loc) · 1.12 KB
/
TableOfContents.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<template>
<div v-if="loading">Loading...</div>
<div v-else-if="error">Error: {{ error.message }}</div>
<ul>
<li v-for="chapter of chapters" :key="chapter.id">
<a @click="updateCurrentSection(chapter.id)">
{{
chapter.number ? `${chapter.number}. ${chapter.title}` : chapter.title
}}
</a>
</li>
</ul>
<SectionList :id="currentSection" />
</template>
<script>
import { useQuery, useResult } from '@vue/apollo-composable'
import { gql } from '@apollo/client/core'
import { ref } from 'vue'
import SectionList from './SectionList.vue'
const PREFACE_ID = -2
export default {
name: 'TableOfContents',
components: {
SectionList
},
setup() {
const currentSection = ref(PREFACE_ID)
const { result, loading, error } = useQuery(gql`
query ChapterList {
chapters {
id
number
title
}
}
`)
const chapters = useResult(result, [])
return {
loading,
error,
chapters,
currentSection,
updateCurrentSection: newSection => (currentSection.value = newSection)
}
}
}
</script>