Skip to content
This repository was archived by the owner on Oct 18, 2022. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 401d444

Browse files
committedApr 24, 2018
Move org rotation into a global plugin
1 parent 3abd5a1 commit 401d444

File tree

7 files changed

+27
-45
lines changed

7 files changed

+27
-45
lines changed
 

‎assets/js/helpers.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,6 @@ export function sendToMothership(data={}) {
8080
return postFormData('https://queue.fightforthefuture.org/action', data)
8181
}
8282

83-
export function getRandomOrg() {
84-
var coinToss = Math.random();
85-
if (coinToss < .20) {
86-
return 'fp';
87-
}
88-
else if (coinToss < .60) {
89-
return 'dp';
90-
}
91-
else {
92-
return 'fftf';
93-
}
94-
}
95-
9683
export function getDonateLink(org) {
9784
switch (org) {
9885
case 'fp':

‎components/Disclaimer.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
</template>
1717

1818
<script>
19+
import { mapState } from 'vuex'
20+
1921
export default {
20-
props: {
21-
org: {
22-
type: String,
23-
default: 'fftf'
24-
}
25-
}
22+
computed: mapState(['org'])
2623
}
2724
</script>

‎components/PetitionForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<span v-else>Write Congress</span>
127127
</button>
128128
<no-ssr>
129-
<disclaimer :org="org"></disclaimer>
129+
<disclaimer></disclaimer>
130130
</no-ssr>
131131
</form>
132132
<div class="petition-copy">

‎nuxt.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ module.exports = {
7373
// '~/plugins/org-rotation.js'
7474
'~/plugins/filters.js',
7575
'~/plugins/components.js',
76-
{ src: '~/plugins/analytics.js', ssr: false},
76+
{ src: '~/plugins/analytics.js', ssr: false },
77+
'~/plugins/org-rotation.js'
7778
]
7879
}

‎pages/index.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,8 @@ export default {
176176
177177
computed: {
178178
isCallPage() {
179-
return this.$router.currentRoute.name === 'call' || this.$router.currentRoute.query.call
179+
return this.$route.name === 'call' || this.$route.query.call
180180
}
181-
},
182-
183-
created() {
184-
const org = this.$router.currentRoute.query.org || getRandomOrg()
185-
this.$store.commit('setOrg', org)
186181
}
187182
}
188183
</script>

‎plugins/org-rotation.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
import Vue from 'vue'
2-
import VueOrgRotation from './vue-org-rotation'
1+
// fp = 20%, dp = 40%, fftf = 40%
2+
function getRandomOrg() {
3+
var coinToss = Math.random();
4+
if (coinToss < .20) {
5+
return 'fp';
6+
}
7+
else if (coinToss < .60) {
8+
return 'dp';
9+
}
10+
else {
11+
return 'fftf';
12+
}
13+
}
314

4-
Vue.use(VueOrgRotation)
15+
// set org on route change
16+
export default ({ app }) => {
17+
app.router.afterEach((to, from) => {
18+
const org = to.query.org || to.query.source || getRandomOrg()
19+
app.store.commit('setOrg', org)
20+
})
21+
}

‎plugins/vue-org-rotation.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)
This repository has been archived.