Skip to content

Commit 85e2cb0

Browse files
committed
changed the watch to watcheffect for navigating to the specific version
1 parent 22ccc27 commit 85e2cb0

File tree

2 files changed

+44
-49
lines changed

2 files changed

+44
-49
lines changed

app/components/Changelog/Markdown.vue

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,26 @@ const { data, error } = await useFetch(
1212
)
1313
1414
if (import.meta.client) {
15-
watch(
16-
[() => data.value?.toc, () => requestedVersion?.toLowerCase(), () => route.hash],
17-
([toc, rv, hash]) => {
18-
if (toc && hash) {
19-
navigateTo(hash)
20-
return
21-
}
15+
// doing this server side can make it that we go to the homepage
16+
watchEffect(() => {
17+
const toc = data.value?.toc
2218
23-
if (!toc || !rv || hash) {
19+
if (toc && route.hash) {
20+
navigateTo(route.hash)
21+
return
22+
}
23+
if (!toc || !requestedVersion || route.hash) {
24+
return
25+
}
26+
// lc = lower case
27+
const lcRequestedVersion = requestedVersion.toLowerCase()
28+
for (const item of toc) {
29+
if (item.text.toLowerCase().includes(lcRequestedVersion)) {
30+
navigateTo(`#${item.id}`)
2431
return
2532
}
26-
27-
for (const item of toc) {
28-
if (item.text.toLowerCase().includes(rv)) {
29-
navigateTo(`#${item.id}`)
30-
return
31-
}
32-
}
33-
},
34-
{
35-
immediate: true,
36-
},
37-
)
33+
}
34+
})
3835
}
3936
</script>
4037
<template>

app/components/Changelog/Releases.vue

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,45 @@ const route = useRoute()
1515
1616
const matchingDateReleases = computed(() => {
1717
if (!requestedDate || !releases.value) {
18-
return
18+
return []
1919
}
2020
2121
return releases.value.filter(release => {
2222
if (!release.publishedAt) {
2323
return
2424
}
25-
const date = new Date(release.publishedAt).toISOString().split('T')[0]
26-
27-
return date === requestedDate
25+
return requestedDate === toIsoDate(new Date(release.publishedAt))
2826
})
2927
})
3028
3129
if (import.meta.client) {
32-
watch(
33-
[() => route.hash, () => requestedDate?.toLowerCase(), releases, () => requestedVersion],
34-
([hash, date, uReleases, uRequestedVersion]) => {
35-
if (hash && uReleases) {
36-
// ensures the user is scrolled to the hash
37-
navigateTo(hash, { replace: true })
38-
return
39-
}
40-
if (hash || !date || !uReleases) {
41-
return
42-
}
43-
if (uRequestedVersion) {
44-
for (const match of matchingDateReleases.value ?? []) {
45-
if (match.title.toLowerCase().includes(uRequestedVersion)) {
46-
navigateTo(`#release-${slugify(match.title)}`, { replace: true })
47-
return
48-
}
30+
// doing this server side can make it that we go to the homepage
31+
watchEffect(() => {
32+
const uReleases = releases.value
33+
if (route.hash && uReleases) {
34+
navigateTo(route.hash, { replace: true })
35+
return
36+
}
37+
const date = requestedDate?.toLowerCase()
38+
if (route.hash || !date || !uReleases) {
39+
return
40+
}
41+
const uMatchingDateReleases = matchingDateReleases.value
42+
if (uMatchingDateReleases?.length < 1) {
43+
// if no releases have matched the requested version publish date then most likely no release note has been made
44+
return
45+
}
46+
47+
if (requestedVersion) {
48+
for (const match of uMatchingDateReleases) {
49+
if (match.title.toLowerCase().includes(requestedVersion)) {
50+
navigateTo(`#release-${slugify(match.title)}`, { replace: true })
51+
return
4952
}
5053
}
51-
52-
navigateTo(`#date-${date}`, { replace: true })
53-
},
54-
{
55-
immediate: true,
56-
flush: 'post',
57-
},
58-
)
54+
}
55+
navigateTo(`#date-${date}`, { replace: true })
56+
})
5957
}
6058
</script>
6159
<template>

0 commit comments

Comments
 (0)