Skip to content

Commit

Permalink
Add HeroBanner for Election depending on the current state of the ballot
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeden committed Nov 30, 2023
1 parent 15466de commit 595f48e
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/components/election/CandidateCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const store = useStore();
const session = useSession();
const isVotingOpen = computed(() => store.getters['ballot/isVotingOpen']);
const isVotingClosed = computed(() => store.getters['ballot/isVotingClosed']);
const router = useRouter();
const route = useRoute();
Expand Down
77 changes: 77 additions & 0 deletions src/components/hero/ElectionHero.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<script setup>
import { computed } from 'vue';
import { useStore } from 'vuex';
import CandidateCard from '@/components/election/CandidateCard.vue';
const store = useStore();
const isNominationOpen = computed(
() => store.getters['ballot/isNominationOpen']
);
const isVotingOpen = computed(() => store.getters['ballot/isVotingOpen']);
const isVotingClosed = computed(() => store.getters['ballot/isVotingClosed']);
const candidatesSorted = computed(
() => store.getters['ballot/candidatesSorted']
);
const content = {
isNominationOpen: {
headline: 'Nominate Now!',
subline: 'Engage in WAX governance by nominating your top candidate.'
},
isVotingOpen: {
headline: 'Cast Your Vote!',
subline:
'Shape the future of WAX through blockchain governance. Your voice matters!'
},
isVotingClosed: {
headline: 'Winner Announced!',
subline: 'The election has concluded. A new IG has been elected - Exciting times ahead!'
}
};
</script>

<template>
<div class="container">
<div class="container grid grid-cols-5 gap-12 bg-primary-50 py-12 sm:py-16">
<div class="col-span-3">
<template v-if="isNominationOpen">
<h2 class="text-2xl font-bold tracking-tight text-primary">
{{ content.isNominationOpen.headline }}
</h2>
<p
class="mt-4 text-md max-w-2xl leading-8"
v-html="content.isNominationOpen.subline"
></p>
</template>
<template v-if="isVotingOpen">
<h2 class="text-2xl font-bold tracking-tight text-primary">
{{ content.isVotingOpen.headline }}
</h2>
<p
class="mt-4 text-md max-w-2xl leading-8"
v-html="content.isVotingOpen.subline"
></p>
</template>
<template v-if="isVotingClosed">
<h2 class="text-2xl font-bold tracking-tight text-primary">
{{ content.isVotingClosed.headline }}
</h2>
<p
class="mt-4 text-md max-w-2xl leading-8"
v-html="content.isVotingClosed.subline"
></p>
</template>
</div>
<div v-if="isVotingClosed" class="col-span-2">
<template v-if="isVotingClosed && candidatesSorted.length">
<CandidateCard
class="transform rotate-[5deg] max-w-[250px]"
:candidate="candidatesSorted[0]"
/>
</template>
</div>
</div>
</div>
</template>
6 changes: 5 additions & 1 deletion src/store/modules/ballot.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const getters = {
candidates: (state) => {
return state.candidates;
},
candidatesSorted: (state) => {
return state.candidates.sort((a, b) => b.votesRaw - a.votesRaw);
},
ballots: (state) => {
return state.ballots;
},
Expand Down Expand Up @@ -77,11 +80,12 @@ const actions = {
votingBallots.forEach((votes) => {
let voteToCurrency = parseFloat(votes.value.split(' ')[0])
.toFixed(2)
.replace(/\d(?=(\d{3})+\.)/g, '$&,')
.replace(/\d(?=(\d{3})+\.)/g, '$&,');

if (votes.key === candidate.owner) {
candidatesWithVotes.push({
...candidate,
votesRaw: parseInt(votes.value.split(' ')[0]),
votes: voteToCurrency + ' WAX'
});
}
Expand Down
8 changes: 2 additions & 6 deletions src/views/ElectionView.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<script setup>
import { TabGroup, TabList, Tab, TabPanels, TabPanel } from '@headlessui/vue';
import SimpleHero from '../components/hero/SimpleHero.vue';
import ElectionHero from '../components/hero/ElectionHero.vue';
import { shallowRef, defineAsyncComponent } from 'vue';
import { RouterView } from 'vue-router';
const headline = 'Cast your Vote!';
const subline =
'Cast your vote and get engaged in blockchain governance. Have your voice heard in shaping the future of WAX.';
const tabs = shallowRef({
Election: defineAsyncComponent(() =>
import('../components/election/BallotView.vue')
Expand All @@ -19,7 +15,7 @@ const tabs = shallowRef({
</script>

<template>
<SimpleHero :title="headline" :desc="subline" />
<ElectionHero />

<div class="container pt-12 pb-16">
<TabGroup>
Expand Down

0 comments on commit 595f48e

Please sign in to comment.