Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions client/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@ document.querySelector("#start").addEventListener("submit", e => {
document.querySelector(".container").classList.add("ready");
});

const receivedOnField = (message) => {
const result = JSON.parse(message?.['data'])

if (result['type'] === 'place')
drawer.putArray(result['payload']['place']);
}

const main = apiKey => {
const ws = connect(apiKey);
ws.addEventListener("message", console.log);
ws.addEventListener("message", receivedOnField);

timeout.next = new Date();
drawer.onClick = (x, y) => {
drawer.put(x, y, picker.color);
ws.send(JSON.stringify({
type: "click",
payload: {x, y, color: picker.color}
}));
};
};

Expand Down
14 changes: 2 additions & 12 deletions client/picker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const setAttributes = (element, object) => {
};

const drawPalette = async () => {
const colors = hardcodedColors;
const reply = await fetch("/api/getColors");
const colors = await reply.json();
pickedColor = colors[0];
const palette = document.querySelector("#palette");
const fragment = document.createDocumentFragment();
Expand Down Expand Up @@ -37,17 +38,6 @@ const drawPalette = async () => {
palette.appendChild(fragment);
};

const hardcodedColors = [
"#140c1c",
"#30346d",
"#854c30",
"#d04648",
"#597dce",
"#8595a1",
"#d2aa99",
"#dad45e",
];

let pickedColor = null;

drawPalette().catch(console.error);
Expand Down
Loading