-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic additional donations support
- Loading branch information
Showing
13 changed files
with
235 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"key": { | ||
"type": "string" | ||
}, | ||
"active": { | ||
"type": "boolean" | ||
} | ||
}, | ||
"required": [ | ||
"key", | ||
"active" | ||
] | ||
}, | ||
"default": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/dashboard/additional-donations-control/components/Donation.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<template> | ||
<div class="d-flex"> | ||
{{ donation.description }} - ${{ donation.amount }} | ||
- <v-checkbox class="ma-0 pa-0 ml-1" v-model="toggle" /> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import MediaCard from '@esa-layouts/dashboard/_misc/components/MediaCard.vue'; | ||
import { Component, Prop, Vue } from 'vue-property-decorator'; | ||
import { storeModule } from '../store'; | ||
@Component({ | ||
components: { | ||
MediaCard, | ||
}, | ||
}) | ||
export default class extends Vue { | ||
@Prop({ type: Object, required: true }) readonly donation!: { | ||
key: string, | ||
description: string, | ||
amount: number, | ||
active: boolean, | ||
}; | ||
get toggle(): boolean { | ||
return this.donation.active; | ||
} | ||
set toggle(val: boolean) { | ||
storeModule.toggleItem({ key: this.donation.key, active: val }); | ||
nodecg.sendMessage('additionalDonationToggle', { key: this.donation.key, active: val }); | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* eslint no-new: off, @typescript-eslint/explicit-function-return-type: off */ | ||
|
||
import { setUpReplicants } from '@esa-layouts/browser_shared/replicant_store'; | ||
import vuetify from '@esa-layouts/_misc/vuetify'; | ||
import Vue from 'vue'; | ||
import App from './main.vue'; | ||
import store from './store'; | ||
|
||
setUpReplicants(store).then(() => { | ||
new Vue({ | ||
vuetify, | ||
store, | ||
el: '#App', | ||
render: (h) => h(App), | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<template> | ||
<v-app> | ||
<div class="mb-2"> | ||
<donation | ||
v-for="donation of additionalDonationsMapped" | ||
:key="donation.key" | ||
:donation="donation" | ||
/> | ||
</div> | ||
</v-app> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { replicantNS } from '@esa-layouts/browser_shared/replicant_store'; | ||
import { AdditionalDonations } from '@esa-layouts/types/schemas'; | ||
import { Component, Vue } from 'vue-property-decorator'; | ||
import Donation from './components/Donation.vue'; | ||
@Component({ | ||
components: { | ||
Donation, | ||
}, | ||
}) | ||
export default class extends Vue { | ||
@replicantNS.State( | ||
(s) => s.reps.additionalDonations, | ||
) readonly additionalDonations!: AdditionalDonations; | ||
additionalDonationsCfg = nodecg.bundleConfig.additionalDonations; | ||
formatAmount(val: number): string { | ||
return val.toLocaleString('en-US', { maximumFractionDigits: 0 }); | ||
} | ||
get additionalDonationsMapped() { | ||
return this.additionalDonationsCfg.map((d) => ({ | ||
key: d.key, | ||
description: d.description, | ||
amount: d.amount, | ||
active: this.additionalDonations.find((a) => a.key === d.key)?.active ?? false, | ||
})); | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { replicantModule, ReplicantModule, ReplicantTypes } from '@esa-layouts/browser_shared/replicant_store'; | ||
import clone from 'clone'; | ||
import Vue from 'vue'; | ||
import Vuex, { Store } from 'vuex'; | ||
import { getModule, Module, Mutation, VuexModule } from 'vuex-module-decorators'; | ||
|
||
Vue.use(Vuex); | ||
|
||
@Module({ name: 'OurModule' }) | ||
class OurModule extends VuexModule { | ||
// Helper getter to return all replicants. | ||
get reps(): ReplicantTypes { | ||
return this.context.rootState.ReplicantModule.reps; | ||
} | ||
|
||
@Mutation | ||
toggleItem({ key, active }: { key: string, active: boolean }): void { | ||
const donations = clone(replicantModule.repsTyped.additionalDonations); | ||
const donationIndex = donations.findIndex((d) => d.key === key); | ||
if (donationIndex >= 0) { | ||
donations[donationIndex].active = active; | ||
} else { | ||
donations.push({ key, active }); | ||
} | ||
replicantModule.setReplicant({ name: 'additionalDonations', val: donations }); | ||
} | ||
} | ||
|
||
const store = new Store({ | ||
strict: process.env.NODE_ENV !== 'production', | ||
state: {}, | ||
modules: { ReplicantModule, OurModule }, | ||
}); | ||
export default store; | ||
export const storeModule = getModule(OurModule, store); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-disable */ | ||
/** | ||
* This file was automatically generated by json-schema-to-typescript. | ||
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, | ||
* and run json-schema-to-typescript to regenerate this file. | ||
*/ | ||
|
||
export type AdditionalDonations = { | ||
key: string; | ||
active: boolean; | ||
}[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters