mirror of
https://github.com/jcreek/EstimationPoker.git
synced 2026-07-12 18:43:47 +00:00
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:
@@ -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>
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let values: number[] = [1, 2, 3, 5, 8, 13, 21];
|
export let values: Array<number | string> = [1, 2, 3, 5, 8, 13, 21, '?'];
|
||||||
export let onEstimateClick: (value: number) => void;
|
export let onEstimateClick: (value: number | string) => void;
|
||||||
export let disableEstimates: boolean = false;
|
export let disableEstimates: boolean = false;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import UsersList from '../../../components/UsersList.svelte';
|
import UsersList from '../../../components/UsersList.svelte';
|
||||||
import EstimateGroupsList from '../../../components/EstimateGroupsList.svelte';
|
import EstimateGroupsList from '../../../components/EstimateGroupsList.svelte';
|
||||||
import AverageEstimate from '../../../components/AverageEstimate.svelte';
|
|
||||||
import Modal from '../../../components/Modal.svelte';
|
import Modal from '../../../components/Modal.svelte';
|
||||||
import Estimates from '../../../components/Estimates.svelte';
|
import Estimates from '../../../components/Estimates.svelte';
|
||||||
|
|
||||||
@@ -31,9 +30,9 @@
|
|||||||
type: string;
|
type: string;
|
||||||
roomId: string;
|
roomId: string;
|
||||||
userId: 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.type = 'select-estimate';
|
||||||
this.roomId = roomId;
|
this.roomId = roomId;
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
@@ -57,7 +56,6 @@
|
|||||||
let showModal = true;
|
let showModal = true;
|
||||||
const userId = generateId();
|
const userId = generateId();
|
||||||
let users: Array<User> = [];
|
let users: Array<User> = [];
|
||||||
let average: number;
|
|
||||||
let estimateGroups: { [key: number]: string[] } = {};
|
let estimateGroups: { [key: number]: string[] } = {};
|
||||||
let showRestartButton = false;
|
let showRestartButton = false;
|
||||||
let showEstimates = 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));
|
sendMessage(socket, new SelectEstimateMessage(data.roomId, userId, estimate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +120,6 @@
|
|||||||
} else if (message.type === 'user-left') {
|
} else if (message.type === 'user-left') {
|
||||||
users = users.filter((user) => user.userId !== message.userId);
|
users = users.filter((user) => user.userId !== message.userId);
|
||||||
} else if (message.type === 'estimation-closed') {
|
} else if (message.type === 'estimation-closed') {
|
||||||
average = message.average;
|
|
||||||
estimateGroups = message.groupedEstimates;
|
estimateGroups = message.groupedEstimates;
|
||||||
showRestartButton = true;
|
showRestartButton = true;
|
||||||
showEstimates = true;
|
showEstimates = true;
|
||||||
@@ -191,7 +188,6 @@
|
|||||||
|
|
||||||
{#if Object.keys(estimateGroups).length > 0}
|
{#if Object.keys(estimateGroups).length > 0}
|
||||||
<EstimateGroupsList {estimateGroups} />
|
<EstimateGroupsList {estimateGroups} />
|
||||||
<AverageEstimate {average} />
|
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export class Room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAllEstimates() {
|
getAllEstimates() {
|
||||||
const estimates = new Map<string, number>();
|
const estimates = new Map<string, number | string>();
|
||||||
this.users.forEach((user) => {
|
this.users.forEach((user) => {
|
||||||
if (user.estimate !== null) {
|
if (user.estimate !== null) {
|
||||||
estimates.set(user.name, user.estimate);
|
estimates.set(user.name, user.estimate);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export class User {
|
export class User {
|
||||||
userId: string;
|
userId: string;
|
||||||
name: string;
|
name: string;
|
||||||
estimate: number | null;
|
estimate: number | string | null;
|
||||||
|
|
||||||
constructor(userId: string, name: string) {
|
constructor(userId: string, name: string) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ export class SelectEstimateMessage {
|
|||||||
type: string;
|
type: string;
|
||||||
roomId: string;
|
roomId: string;
|
||||||
userId: 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.type = 'select-estimate';
|
||||||
this.roomId = roomId;
|
this.roomId = roomId;
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
|
|||||||
+1
-13
@@ -17,18 +17,8 @@ function onSocketPostError(e: Error) {
|
|||||||
console.log(e);
|
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>) {
|
function groupEstimates(users: Array<User>) {
|
||||||
let estimateGroups: { [key: number]: string[] } = {};
|
let estimateGroups: { [key: number | string]: string[] } = {};
|
||||||
users.forEach((user) => {
|
users.forEach((user) => {
|
||||||
if (user.estimate !== null) {
|
if (user.estimate !== null) {
|
||||||
if (estimateGroups[user.estimate]) {
|
if (estimateGroups[user.estimate]) {
|
||||||
@@ -109,10 +99,8 @@ wss.on('connection', (ws: WebSocket, req) => {
|
|||||||
const allEstimates = room.getAllEstimates();
|
const allEstimates = room.getAllEstimates();
|
||||||
if (allEstimates.size === room.getUsers().length) {
|
if (allEstimates.size === room.getUsers().length) {
|
||||||
const users = room.getUsers();
|
const users = room.getUsers();
|
||||||
const average = calculateAverageEstimate(users);
|
|
||||||
broadcastToRoom(room.id, {
|
broadcastToRoom(room.id, {
|
||||||
type: 'estimation-closed',
|
type: 'estimation-closed',
|
||||||
average,
|
|
||||||
groupedEstimates: groupEstimates(users)
|
groupedEstimates: groupEstimates(users)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user