Merge pull request #7 from jcreek/1-add-estimate-option-for-not-choosing-a-number-eg

feat(#1): Add estimate option for not choosing a number
This commit is contained in:
Josh Creek
2023-07-13 21:01:44 +01:00
committed by GitHub
7 changed files with 10 additions and 34 deletions
-8
View File
@@ -1,8 +0,0 @@
<script lang="ts">
export let average: string | number;
</script>
<div id="average-estimate">
<h2>Average Estimate</h2>
<p>{average}</p>
</div>
+2 -2
View File
@@ -1,6 +1,6 @@
<script lang="ts">
export let values: number[] = [1, 2, 3, 5, 8, 13, 21];
export let onEstimateClick: (value: number) => void;
export let values: Array<number | string> = [1, 2, 3, 5, 8, 13, 21, '?'];
export let onEstimateClick: (value: number | string) => void;
export let disableEstimates: boolean = false;
</script>
+3 -7
View File
@@ -7,7 +7,6 @@
import { onMount } from 'svelte';
import UsersList from '../../../components/UsersList.svelte';
import EstimateGroupsList from '../../../components/EstimateGroupsList.svelte';
import AverageEstimate from '../../../components/AverageEstimate.svelte';
import Modal from '../../../components/Modal.svelte';
import Estimates from '../../../components/Estimates.svelte';
@@ -31,9 +30,9 @@
type: string;
roomId: string;
userId: string;
estimate: number;
estimate: number | string;
constructor(roomId: string, userId: string, estimate: number) {
constructor(roomId: string, userId: string, estimate: number | string) {
this.type = 'select-estimate';
this.roomId = roomId;
this.userId = userId;
@@ -57,7 +56,6 @@
let showModal = true;
const userId = generateId();
let users: Array<User> = [];
let average: number;
let estimateGroups: { [key: number]: string[] } = {};
let showRestartButton = false;
let showEstimates = false;
@@ -85,7 +83,7 @@
}
}
function handleEstimateClick(estimate: number) {
function handleEstimateClick(estimate: number | string) {
sendMessage(socket, new SelectEstimateMessage(data.roomId, userId, estimate));
}
@@ -122,7 +120,6 @@
} else if (message.type === 'user-left') {
users = users.filter((user) => user.userId !== message.userId);
} else if (message.type === 'estimation-closed') {
average = message.average;
estimateGroups = message.groupedEstimates;
showRestartButton = true;
showEstimates = true;
@@ -191,7 +188,6 @@
{#if Object.keys(estimateGroups).length > 0}
<EstimateGroupsList {estimateGroups} />
<AverageEstimate {average} />
{/if}
<style>
+1 -1
View File
@@ -35,7 +35,7 @@ export class Room {
}
getAllEstimates() {
const estimates = new Map<string, number>();
const estimates = new Map<string, number | string>();
this.users.forEach((user) => {
if (user.estimate !== null) {
estimates.set(user.name, user.estimate);
+1 -1
View File
@@ -1,7 +1,7 @@
export class User {
userId: string;
name: string;
estimate: number | null;
estimate: number | string | null;
constructor(userId: string, name: string) {
this.userId = userId;
@@ -2,9 +2,9 @@ export class SelectEstimateMessage {
type: string;
roomId: string;
userId: string;
estimate: number;
estimate: number | string;
constructor(roomId: string, userId: string, estimate: number) {
constructor(roomId: string, userId: string, estimate: number | string) {
this.type = 'select-estimate';
this.roomId = roomId;
this.userId = userId;
+1 -13
View File
@@ -17,18 +17,8 @@ function onSocketPostError(e: Error) {
console.log(e);
}
function calculateAverageEstimate(users: Array<User>) {
let total = 0;
users.forEach((user) => {
if (user.estimate !== null) {
total += user.estimate;
}
});
return total / users.length;
}
function groupEstimates(users: Array<User>) {
let estimateGroups: { [key: number]: string[] } = {};
let estimateGroups: { [key: number | string]: string[] } = {};
users.forEach((user) => {
if (user.estimate !== null) {
if (estimateGroups[user.estimate]) {
@@ -109,10 +99,8 @@ wss.on('connection', (ws: WebSocket, req) => {
const allEstimates = room.getAllEstimates();
if (allEstimates.size === room.getUsers().length) {
const users = room.getUsers();
const average = calculateAverageEstimate(users);
broadcastToRoom(room.id, {
type: 'estimation-closed',
average,
groupedEstimates: groupEstimates(users)
});
}