-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MultipleVote): new poll dialog card that used to do multiple votes
- Loading branch information
Yaskur
committed
Mar 12, 2024
1 parent
c07aed9
commit d4eb6d7
Showing
13 changed files
with
404 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import PollCard from './PollCard'; | ||
import {LocaleTimezone, PollState, Voter} from '../helpers/interfaces'; | ||
import {chat_v1 as chatV1} from '@googleapis/chat'; | ||
import {progressBarText} from '../helpers/vote'; | ||
|
||
export default class PollDialogCard extends PollCard { | ||
private readonly voter: Voter; | ||
private userVotes: number[] | undefined; | ||
|
||
constructor(state: PollState, timezone: LocaleTimezone, voter: Voter) { | ||
super(state, timezone); | ||
this.voter = voter; | ||
} | ||
create() { | ||
this.buildHeader(); | ||
this.buildSections(); | ||
this.buildButtons(); | ||
this.buildFooter(); | ||
this.card.name = this.getSerializedState(); | ||
return this.card; | ||
} | ||
|
||
getUserVotes(): number[] { | ||
if (this.state.votes === undefined) { | ||
return []; | ||
} | ||
const votes = []; | ||
const voter = this.voter; | ||
for (let i = 0; i < this.state.choices.length; i++) { | ||
if (this.state.votes[i] !== undefined && this.state.votes[i].findIndex((x) => x.uid === voter.uid) > -1) { | ||
votes.push(i); | ||
} | ||
} | ||
return votes; | ||
} | ||
choice(index: number, text: string, voteCount: number, totalVotes: number): chatV1.Schema$GoogleAppsCardV1Widget { | ||
this.userVotes = this.getUserVotes(); | ||
|
||
const progressBar = progressBarText(voteCount, totalVotes); | ||
|
||
const voteSwitch: chatV1.Schema$GoogleAppsCardV1SwitchControl = { | ||
'controlType': 'SWITCH', | ||
'name': 'mySwitchControl', | ||
'value': 'myValue', | ||
'selected': this.userVotes.includes(index), | ||
'onChangeAction': { | ||
'function': 'switch_vote', | ||
'parameters': [ | ||
{ | ||
key: 'index', | ||
value: index.toString(10), | ||
}, | ||
], | ||
}, | ||
}; | ||
return { | ||
decoratedText: { | ||
'bottomLabel': `${progressBar} ${voteCount}`, | ||
'text': text, | ||
'switchControl': voteSwitch, | ||
}, | ||
}; | ||
} | ||
} |
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,6 @@ | ||
export const mockCreatePollDialogCard = jest.fn(() => 'card'); | ||
export default jest.fn(() => { | ||
return { | ||
create: mockCreatePollDialogCard, | ||
}; | ||
}); |
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
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
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
Oops, something went wrong.