|
12 | 12 | getTranslatedCountryNameFromAlpha3Code, |
13 | 13 | sortTranslatedCountries |
14 | 14 | } from '$lib/utils/nationTranslationHelper.svelte'; |
| 15 | + import { calculateMajority } from '$lib/utils/majorities'; |
15 | 16 |
|
16 | 17 | interface Props { |
17 | 18 | active: boolean; |
|
30 | 31 | .filter((member) => member.present && member.representation?.type === 'DELEGATION') |
31 | 32 | .sort((a, b) => sortTranslatedCountries(a.representation!, b.representation!)); |
32 | 33 |
|
| 34 | + let chairSettings = liveQuery(() => localDB.committeeSettings.get(committee.id)); |
| 35 | + let rollCallVotingAbstain = $derived($chairSettings?.rollCallVotingAbstain ?? []); |
| 36 | + let rollCallVotingPro = $derived($chairSettings?.rollCallVotingPro ?? []); |
| 37 | + let rollCallVotingCon = $derived($chairSettings?.rollCallVotingCon ?? []); |
| 38 | +
|
33 | 39 | let majorityAmount = $derived.by(() => { |
34 | 40 | switch (majority) { |
35 | 41 | case 'SIMPLE': |
| 42 | + return calculateMajority( |
| 43 | + (committee?.totalPresent ?? 0) - (rollCallVotingAbstain?.length ?? 0), |
| 44 | + 'simple' |
| 45 | + ); |
| 46 | + case 'ABSOLUTE': |
36 | 47 | return committee?.simpleMajority ?? 0; |
37 | 48 | case 'TWO_THIRDS': |
38 | 49 | return committee?.twoThirdsMajority ?? 0; |
|
41 | 52 | } |
42 | 53 | }); |
43 | 54 |
|
44 | | - let chairSettings = liveQuery(() => localDB.committeeSettings.get(committee.id)); |
45 | | - let rollCallVotingAbstain = $derived($chairSettings?.rollCallVotingAbstain ?? []); |
46 | | - let rollCallVotingPro = $derived($chairSettings?.rollCallVotingPro ?? []); |
47 | | - let rollCallVotingCon = $derived($chairSettings?.rollCallVotingCon ?? []); |
48 | | -
|
49 | 55 | let scrollingListIcons = $derived.by(() => { |
50 | 56 | return members.map((member) => { |
51 | 57 | let icon: string = ''; |
|
126 | 132 | } |
127 | 133 | }; |
128 | 134 |
|
| 135 | + $effect(() => { |
| 136 | + if (active) { |
| 137 | + localDB.committeeSettings.update(committee.id, { |
| 138 | + votingMajorityAmount: majorityAmount |
| 139 | + }); |
| 140 | + } |
| 141 | + }); |
| 142 | +
|
129 | 143 | $effect(() => { |
130 | 144 | if (active) { |
131 | 145 | hotkeys('j, k, l, esc', 'rollCallVote', (event, handler) => { |
|
169 | 183 | rollCallVotingPro: [], |
170 | 184 | rollCallVotingCon: [], |
171 | 185 | rollCallVotingAbstain: [], |
172 | | - votingWithAbstentions: withAbstentions, |
173 | | - votingMajorityAmount: majorityAmount |
| 186 | + votingWithAbstentions: withAbstentions |
174 | 187 | }); |
175 | 188 | } else { |
176 | 189 | localDB.committeeSettings.update(committee.id, { |
|
0 commit comments