Skip to content
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

fix: revert back to old collapse logic #539

Merged
merged 2 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions src/defaultTheme/components/molecules/AsideNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
:key="link.to"
:title="link.title"
:docs="link.children"
:collapse="link.collapse === true"
:collapse="link.collapse"
@toggle="toggleLinks(link)"
/>
<AsideNavigationItem v-else :key="link.to" :docs="[link]" />
Expand All @@ -83,8 +83,10 @@ export default defineComponent({
setup() {
const { $docus } = useContext()

// Replicate currentNav locally
const links = ref($docus.currentNav.value.links)

// Watch updates on currentNav
watch(
$docus.currentNav,
newVal => {
Expand All @@ -93,22 +95,38 @@ export default defineComponent({
{ deep: true }
)

function toggleLinks(link) {
const newLinks = $docus.currentNav.value.links.map(l => {
l = { ...l }
// Uncollapse current category on first navigation
watch(
links,
newVal => {
newVal.forEach(link => {
if (link.children && link.children.length > 0) {
const isCategoryActive = link.children.some(document => $docus.isLinkActive(document.to))

if (isCategoryActive) {
link.collapse = false
}
}
})
},
{ immediate: true }
)

if (link.slug === l.slug) {
l.collapse = !link.collapse
// Toggle a link
const toggleLinks = link => {
links.value = links.value.map(l => {
if (l.slug === link.slug) {
l.collapse = !l.collapse
}

return l
})

links.value = newLinks
}

// Get parent
const parent = computed(() => $docus.currentNav.value.parent)

// Get last release value
const lastRelease = computed(() => $docus.lastRelease?.value)

return { toggleLinks, links, parent, lastRelease }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</template>

<script>
import { computed, defineComponent, ref, useContext } from '@nuxtjs/composition-api'
import { computed, watch, defineComponent, ref, useContext } from '@nuxtjs/composition-api'

export default defineComponent({
props: {
Expand Down