forked from quic-issues/427e7578-d7bf-49c8-aee9-2dd999e25316
- remove unnecessary / deprecated code
This commit is contained in:
33
src/app.ts
33
src/app.ts
@@ -2,10 +2,9 @@ import { getUserId } from "./identity";
|
||||
import {
|
||||
addOption,
|
||||
toggleVote,
|
||||
deleteOption,
|
||||
setDeadline,
|
||||
clearDeadline,
|
||||
createViewModel,
|
||||
getDeadline,
|
||||
} from "./state";
|
||||
import { initSync } from "./sync";
|
||||
import { StatusBar } from "./components/StatusBar";
|
||||
@@ -48,18 +47,13 @@ export function initApp(container: HTMLElement): () => void {
|
||||
|
||||
const actions = {
|
||||
addOption: (label: string) => {
|
||||
const vm = createViewModel(getViewModelParams());
|
||||
if (vm.votingClosed) return;
|
||||
if (isVotingClosed()) return;
|
||||
return addOption(sync.options, label, userId);
|
||||
},
|
||||
toggleVote: (optionId: string) => {
|
||||
const vm = createViewModel(getViewModelParams());
|
||||
if (vm.votingClosed) return;
|
||||
if (isVotingClosed()) return;
|
||||
toggleVote(sync.votes, userId, optionId);
|
||||
},
|
||||
deleteOption: (optionId: string) => {
|
||||
deleteOption(sync.options, sync.votes, optionId);
|
||||
},
|
||||
startDeadline: (durationMs: number) => {
|
||||
setDeadline(sync.deadlineMap, durationMs);
|
||||
},
|
||||
@@ -68,18 +62,10 @@ export function initApp(container: HTMLElement): () => void {
|
||||
},
|
||||
};
|
||||
|
||||
function getViewModelParams() {
|
||||
return {
|
||||
yTitle: sync.yTitle,
|
||||
options: sync.options,
|
||||
votes: sync.votes,
|
||||
deadlineMap: sync.deadlineMap,
|
||||
roomId,
|
||||
shareUrl,
|
||||
connectionStatus: sync.getConnectionStatus(),
|
||||
peerCount: sync.getPeerCount(),
|
||||
userId,
|
||||
};
|
||||
function isVotingClosed() {
|
||||
const deadline = getDeadline(sync.deadlineMap);
|
||||
const votingClosed = deadline !== null && Date.now() >= deadline;
|
||||
return votingClosed;
|
||||
}
|
||||
|
||||
// --- Build UI ---
|
||||
@@ -112,10 +98,7 @@ export function initApp(container: HTMLElement): () => void {
|
||||
if (result && !result.ok) return result.error;
|
||||
return null;
|
||||
});
|
||||
const pollList = PollList(sync.options, sync.votes, userId, () => {
|
||||
const vm = createViewModel(getViewModelParams());
|
||||
return vm.votingClosed;
|
||||
}, actions.toggleVote, actions.deleteOption);
|
||||
const pollList = PollList(sync.options, sync.votes, userId, isVotingClosed, actions.toggleVote);
|
||||
const deadlineTimer = DeadlineTimer(
|
||||
sync.deadlineMap,
|
||||
actions.startDeadline,
|
||||
|
||||
Reference in New Issue
Block a user