Skip to content

Commit

Permalink
Merge pull request #58 from dxw/switch-to-biome
Browse files Browse the repository at this point in the history
Switch to Biome
  • Loading branch information
yndajas authored Feb 19, 2024
2 parents 69e1537 + 7c72f57 commit 1a7a0d8
Show file tree
Hide file tree
Showing 35 changed files with 2,064 additions and 774 deletions.
1 change: 1 addition & 0 deletions .adr-dir
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc/architecture/decisions
157 changes: 0 additions & 157 deletions .eslintrc.json

This file was deleted.

1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.11.1
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**
3 changes: 0 additions & 3 deletions .prettierrc

This file was deleted.

2 changes: 1 addition & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": ["stylelint-config-standard", "stylelint-config-clean-order"]
"extends": ["stylelint-config-standard", "stylelint-config-clean-order"]
}
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"biomejs.biome",
"ms-playwright.playwright",
"oven.bun-vscode",
"statelyai.stately-vscode"
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"editor.codeActionsOnSave": {
"quickfix.biome": "always",
"source.organizeImports.biome": "explicit"
},
"[javascript][typescript][json]": {
"editor.defaultFormatter": "biomejs.biome"
}
}
23 changes: 23 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"files": {
"ignore": ["**/*.typegen.ts"]
},
"linter": {
"enabled": true,
"rules": {
"all": true,
"nursery": {
"all": false
}
}
},
"organizeImports": {
"enabled": true
},
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
}
}
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[install.lockfile]
print = "yarn"
61 changes: 31 additions & 30 deletions client/index.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
import { io } from "socket.io-client";
import { NameFormElement } from "../server/@types/ui";
import { Player, Question } from "../server/@types/models";
import { NameFormElement } from "../server/@types/ui";
import { getElementById } from "./utils/getElementById";

const addPlayer = async (name: string): Promise<void> => {
socket.emit("players:post", { name });
socket.emit("players:post", { name });
};

const generateSocketUrl = (): string => {
const location = window.location;
const location = window.location;

return "//" + location.host + location.pathname;
return `//${location.host}${location.pathname}`;
};

const renderPlayerList = (): void => {
const html = players.map((name) => `<li>${name}</li>`);
playerListElement.innerHTML = html.join("\n");
const html = players.map((name) => `<li>${name}</li>`);
playerListElement.innerHTML = html.join("\n");
};

const renderPlayerName = (): void => {
const text = `Name: ${player.name}`;
playerNameElement.innerText = text;
const text = `Name: ${player.name}`;
playerNameElement.innerText = text;
};

// biome-ignore lint/style/useNamingConvention: the issue here is the consecutive upper case characters, but given it's due to using a single-character word, this doesn't feel invalid
const askAQuestion = (data: Question): void => {
const { question, number } = data;
const questionHtml = getElementById("question");
questionHtml.innerText = question;
const numberHtml = getElementById("number");
numberHtml.innerText = number.toString();
const { question, number } = data;
const questionHtml = getElementById("question");
questionHtml.innerText = question;
const numberHtml = getElementById("number");
numberHtml.innerText = number.toString();
};

const derenderNameForm = (): void => {
getElementById("name-form").remove();
getElementById("name-form").remove();
};

const startButton = getElementById("start-button");

const showStartButton = (): void => {
startButton.style.display = "block";
startButton.style.display = "block";
};

startButton.addEventListener("click", () => {
socket.emit("round:start");
socket.emit("round:start");
});

const connectionStatusIconElement = getElementById("connection-status-icon");
Expand All @@ -51,39 +52,39 @@ const playerListElement = getElementById("player-list");
const playerNameElement = getElementById("player-name");

let player: Player;
let players: Array<Player> = [];
let players: Player[] = [];

const socket = io(generateSocketUrl());

socket.on("connect", () => {
connectionStatusIconElement.innerText = "Connected 🟢";
connectionStatusIconElement.innerText = "Connected 🟢";
});

socket.on("disconnect", () => {
connectionStatusIconElement.innerText = "Disconnected 🔴";
connectionStatusIconElement.innerText = "Disconnected 🔴";
});

socket.on("players:get", (data) => {
players = data.players;
renderPlayerList();
players = data.players;
renderPlayerList();
});

socket.on("player:set", (data) => {
player = data.player;
renderPlayerName();
derenderNameForm();
player = data.player;
renderPlayerName();
derenderNameForm();
});

socket.on("question:get", (data) => {
askAQuestion(data.question);
askAQuestion(data.question);
});

socket.on("game:startable", () => {
showStartButton();
showStartButton();
});

nameFormElement.addEventListener("submit", function (e) {
e.preventDefault();
addPlayer(nameFormElement.elements.name.value);
nameFormElement.elements.name.value = "";
nameFormElement.addEventListener("submit", (e) => {
e.preventDefault();
addPlayer(nameFormElement.elements.name.value);
nameFormElement.elements.name.value = "";
});
10 changes: 5 additions & 5 deletions client/utils/getElementById.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const getElementById = (id: HTMLElement["id"]): HTMLElement => {
const element = document.getElementById(id);
const element = document.getElementById(id);

if (!element) {
throw new Error(`No element found with ID: ${id}`);
}
if (!element) {
throw new Error(`No element found with ID: ${id}`);
}

return element;
return element;
};
19 changes: 19 additions & 0 deletions doc/architecture/decisions/0001-record-architecture-decisions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 1. Record architecture decisions

Date: 2023-10-24

## Status

Accepted

## Context

We need to record the architectural decisions made on this project.

## Decision

We will use Architecture Decision Records, as [described by Michael Nygard](http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions).

## Consequences

See Michael Nygard's article, linked above. For a lightweight ADR toolset, see Nat Pryce's [adr-tools](https://github.com/npryce/adr-tools).
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 1. Use Bun
# 2. Use Bun

Date: 2023-10-24

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 1. Use Game class to interact with state machine
# 3. Use Game class to interact with state machine

Date: 2023-11-20

Expand Down
Loading

0 comments on commit 1a7a0d8

Please sign in to comment.