Skip to content

Commit

Permalink
The marathon header so that it spans the page
Browse files Browse the repository at this point in the history
Removes the name from the sidebar
When sidebar collapses, it joins the name in the header

Related to Issue #44
  • Loading branch information
BobChao87 committed Dec 29, 2021
1 parent 6decf1d commit cfc1790
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 62 deletions.
99 changes: 99 additions & 0 deletions components/marathon/Header.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<template>
<div class="box">
<div class="main-header">
<h3 class="title is-3">
{{ marathonName }}
</h3>
<button v-if="collapsed" class="button navbar-burger" :class="buttonClass" @click="toggleSidebar">
<span />
<span />
<span />
</button>
</div>

<div v-if="collapsed" class="menu-sections">
<MarathonSidebarOverview :marathon-id="marathonId" collapsed />
<MarathonSidebarTracker :marathon-id="marathonId" collapsed />
<MarathonSidebarAdmin :marathon-id="marathonId" collapsed />
</div>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import { mapActions } from 'vuex';
import { FullMarathon, MarathonState } from '~/types/api/marathon';
import { IsActive } from '~/types/components/is-active';
export default Vue.extend({
props: {
marathonId: {
type: String,
default: '',
},
collapsed: {
type: Boolean,
default: true,
},
},
async fetch(): Promise<void> {
await Promise.allSettled([
this.getMarathon(this.marathonId),
]);
},
computed: {
marathon(): FullMarathon|undefined {
return (this.$store.state.api.marathon as MarathonState).marathons[this.marathonId];
},
marathonName(): string {
let marathonName = '';
if (this.marathon) {
marathonName = this.marathon.name;
}
if (!marathonName && this.marathonId) {
const frontPage = (this.$store.state.api.marathon as MarathonState).frontPage;
if (frontPage) {
marathonName = [ ...frontPage.live, ...frontPage.next, ...frontPage.open ].find(marathon => marathon.id === this.marathonId)?.name ?? marathonName;
}
}
return marathonName;
},
buttonClass(): IsActive {
return {
'is-active': !this.collapsed,
};
},
},
methods: {
toggleSidebar(): void {
this.$emit('update:collapsed', !this.collapsed);
},
...mapActions({
getMarathon: 'api/marathon/get',
}),
},
});
</script>

<style lang="scss" scoped>
.main-header {
display: grid;
grid-template-columns: auto min-content;
column-gap: var(--spacing);
// Force this element to always display, Bulma wants to hide it by default
@media (min-width: 1024px) {
.navbar-burger {
display: block;
}
}
}
.menu-sections {
display: flex;
flex-wrap: wrap;
}
</style>
76 changes: 19 additions & 57 deletions components/marathon/sidebar/Sidebar.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<template>
<nav class="menu box" :class="{ collapsed }">
<div class="sidebar-header">
<h3 class="title is-3">
{{ marathonName }}
</h3>
<button class="button navbar-burger" :class="isActiveClass" @click="toggleSidebar">
<span />
<span />
<span />
</button>
</div>
<button class="button navbar-burger" :class="isActiveClass" @click="toggleSidebar">
<span />
<span />
<span />
</button>

<div class="menu-sections">
<MarathonSidebarOverview :marathon-id="marathonId" :collapsed="collapsed" class="menu-section" />
Expand All @@ -23,8 +18,6 @@

<script lang="ts">
import Vue from 'vue';
import { mapActions } from 'vuex';
import { FullMarathon, MarathonState } from '~/types/api/marathon';
import { IsActive } from '~/types/components/is-active';
export default Vue.extend({
Expand All @@ -39,29 +32,7 @@ export default Vue.extend({
},
},
async fetch(): Promise<void> {
await Promise.allSettled([
this.getMarathon(this.marathonId),
]);
},
computed: {
marathon(): FullMarathon|undefined {
return (this.$store.state.api.marathon as MarathonState).marathons[this.marathonId];
},
marathonName(): string {
let marathonName = '';
if (this.marathon) {
marathonName = this.marathon.name;
}
if (!marathonName && this.marathonId) {
const frontPage = (this.$store.state.api.marathon as MarathonState).frontPage;
if (frontPage) {
marathonName = [ ...frontPage.live, ...frontPage.next, ...frontPage.open ].find(marathon => marathon.id === this.marathonId)?.name ?? marathonName;
}
}
return marathonName;
},
isActiveClass(): IsActive {
return {
'is-active': !this.collapsed,
Expand All @@ -73,36 +44,27 @@ export default Vue.extend({
toggleSidebar(): void {
this.$emit('update:collapsed', !this.collapsed);
},
...mapActions({
getMarathon: 'api/marathon/get',
}),
},
});
</script>

<style lang="scss" scoped>
.sidebar-header {
display: grid;
grid-template-columns: auto min-content;
column-gap: var(--spacing);
// Force this element to always display, Bulma wants to hide it by default
@media (min-width: 1024px) {
.navbar-burger {
display: block;
}
}
// Force this element to always display, Bulma wants to hide it by default
@media (min-width: 1024px) {
.navbar-burger {
display: block;
}
}
// This mimicks the Bulma styling, but with our components
.menu:not(.collapsed) .menu-section:not(:first-child) {
margin-block-start: 1em;
}
// This mimicks the Bulma styling, but with our components
.menu:not(.collapsed) .menu-section:not(:first-child) {
margin-block-start: 1em;
}
.collapsed {
.menu-sections {
display: flex;
flex-wrap: wrap;
}
.collapsed {
.menu-sections {
display: flex;
flex-wrap: wrap;
}
}
</style>
25 changes: 20 additions & 5 deletions pages/marathon/_marathon.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div class="marathon-container" :class="{ collapsed }">
<MarathonSidebar class="marathon-sidebar" :marathon-id="marathonId" :collapsed.sync="collapsed" />
<MarathonHeader class="marathon-header" :marathon-id="marathonId" :collapsed.sync="collapsed" />
<MarathonSidebar v-show="!collapsed" class="marathon-sidebar" :marathon-id="marathonId" :collapsed.sync="collapsed" />
<NuxtChild class="marathon-view" />
</div>
</template>
Expand Down Expand Up @@ -64,24 +65,38 @@ export default Vue.extend({
<style lang="scss" scoped>
.marathon-container {
width: 100%;
display: flex;
align-items: flex-start;
align-items: start;
display: grid;
grid-template-columns: auto 1fr;
grid-template-rows: auto 1fr;
grid-template-areas:
'sidebar header'
'sidebar view';
gap: var(--spacing);
}
.marathon-header {
grid-area: header;
}
.marathon-sidebar {
grid-area: sidebar;
min-width: min(300px, 100%);
}
.marathon-view {
grid-area: view;
width: 100%;
flex-grow: 5;
}
@media (max-width: 1023px) {
.marathon-container {
flex-direction: column;
grid-template-columns: 1fr;
grid-template-rows: auto auto 1fr;
grid-template-areas:
'header'
'sidebar'
'view';
}
.marathon-sidebar {
Expand Down

0 comments on commit cfc1790

Please sign in to comment.