Skip to content

Commit a598d54

Browse files
committed
feat: close nav modal on nav link click and resize above small
1 parent 9cd2759 commit a598d54

File tree

4 files changed

+49
-24
lines changed

4 files changed

+49
-24
lines changed

components/navbar.vue

+3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ const props = defineProps({
3232
}
3333
})
3434
35+
const instance = getCurrentInstance()
36+
3537
// ===================================================================== Methods
3638
const scrollToSection = async (el) => {
39+
instance.parent.exposed.handleNavClick()
3740
const id = el.replaceAll('#', '')
3841
const section = document.getElementById(id)
3942
if (section) {

components/site-header.vue

+31-3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ const GithubIcon = resolveComponent('icon/github-icon')
9696
const SlackIcon = resolveComponent('icon/slack-icon')
9797
9898
// ======================================================================== Data
99+
const breakpointSmall = ref(false)
100+
const headerResizeEventListener = ref(null)
99101
const generalStore = useGeneralStore()
100102
const { navigationOpen } = storeToRefs(generalStore)
101103
@@ -118,9 +120,30 @@ watch(navigationOpen, (val) => {
118120
}
119121
})
120122
123+
watch(breakpointSmall, () => {
124+
if (navigationOpen.value) { toggleNav() }
125+
})
126+
121127
// ======================================================================= Hooks
122-
// onMounted(() => {
123-
// })
128+
onMounted(() => {
129+
headerResizeEventListener.value = useThrottle(() => {
130+
if (window.matchMedia('(max-width: 53.125rem)').matches) {
131+
if (!breakpointSmall.value) {
132+
breakpointSmall.value = true
133+
}
134+
} else {
135+
if (breakpointSmall.value) {
136+
breakpointSmall.value = false
137+
}
138+
}
139+
})
140+
headerResizeEventListener.value()
141+
window.addEventListener('resize', headerResizeEventListener.value)
142+
})
143+
144+
onBeforeUnmount(() => {
145+
window.removeEventListener('resize', headerResizeEventListener.value)
146+
})
124147
125148
// ===================================================================== Methods
126149
/**
@@ -138,9 +161,14 @@ const getCtaComponent = (icon) => {
138161
case 'slack' : return SlackIcon;
139162
default : return 'span'
140163
}
141-
142164
}
143165
166+
const handleNavClick = () => {
167+
if (navigationOpen.value) { toggleNav() }
168+
}
169+
170+
defineExpose({ handleNavClick })
171+
144172
</script>
145173

146174
<style lang="scss" scoped>

content/core/index.json

+1-6
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,7 @@
504504
"borderGradientAngle": "45deg",
505505
"title": "<img src='/images/topography-graphic-with-border.svg' />Keep up<br>with Singularity",
506506
"subheading": "Your feedback can shape our next big release. <br>Join us on <a href='https://github.com/data-preservation-programs/singularity' target='_blank'>Github</a> and <a href='https://filecoinproject.slack.com/archives/C05JABREATH' target='_blank'>Slack</a>",
507-
"description": "<span class='weight-500'>Sign up to keep up.</span> We're passionate about keeping you in the loop with our latest features and updates, but we're even more committed to respecting your inbox.",
508-
"cta": {
509-
"tag": "a",
510-
"to": "https://example.com",
511-
"text": "Keep Up"
512-
}
507+
"description": "<span class='weight-500'>Sign up to keep up.</span> We're passionate about keeping you in the loop with our latest features and updates, but we're even more committed to respecting your inbox."
513508
}
514509
}
515510
]

stores/general.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ///////////////////////////////////////////////////////////////////// Imports
22
// -----------------------------------------------------------------------------
33
import { ref } from '#imports'
4-
import GeneralSiteData from '@/content/core/general.json'
4+
// import GeneralSiteData from '@/content/core/general.json'
55

66
// /////////////////////////////////////////////////////////////////////// State
77
// -----------------------------------------------------------------------------
@@ -18,19 +18,18 @@ const clearStore = () => {
1818
}
1919

2020
// /////////////////////////////////////////////////////////////// getBaseData
21-
const getBaseData = async (payload) => {
22-
console.log('hit')
23-
const key = typeof payload === 'string' ? payload : payload.key
24-
let data = false
25-
switch (key) {
26-
case 'general': data = GeneralSiteData; break
27-
default : data = payload.data; break
28-
}
29-
if (data) {
30-
siteContent.value[key] = data
31-
console.log(siteContent)
32-
}
33-
}
21+
// const getBaseData = async (payload) => {
22+
// const key = typeof payload === 'string' ? payload : payload.key
23+
// let data = false
24+
// switch (key) {
25+
// case 'general': data = GeneralSiteData; break
26+
// default : data = payload.data; break
27+
// }
28+
// if (data) {
29+
// siteContent.value[key] = data
30+
// console.log(siteContent)
31+
// }
32+
// }
3433

3534
// //////////////////////////////////////////////////////////////////// setTheme
3635
const setTheme = (newTheme) => {
@@ -54,7 +53,7 @@ export const useGeneralStore = defineStore('general', () => ({
5453
navigationOpen,
5554
// ----- actions
5655
clearStore,
57-
getBaseData,
56+
// getBaseData,
5857
setTheme,
5958
setNavigationOpen
6059
}))

0 commit comments

Comments
 (0)