Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added docker support and debounce logic on door open button #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMPOSE_PROJECT_NAME=space-initlab
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a new line at the end of the file.

20 changes: 20 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:18-alpine

RUN apk add --no-cache make gcc g++ bash git python3 py3-pip

WORKDIR /etc/app

COPY package.json package.json
COPY yarn.lock .
RUN yarn

# copy files
COPY src .
COPY public .
COPY index.html .
COPY vite.config.js .
COPY .env.development .

# RUN bash bin/build.sh

CMD ["yarn", "dev"]
31 changes: 31 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: '3'
networks:
lan:
external: true
internal:
external: false
services:
app:
build:
context: ../
dockerfile: ./docker/Dockerfile
volumes:
- '../src:/etc/app/src'
- '../public:/etc/app/public'
- '../index.html:/etc/app/index.html'
- '../vite.config.js:/etc/app/vite.config'
- '../.env.development:/etc/app/.env.development'
networks:
- internal
- lan
# ports:
# - '1234:1234'
labels:
- traefik.enable=true
- traefik.http.routers.space-initlab.rule=Host(`space.initlab.lan`)
- traefik.http.routers.space-initlab.service=dashboard
- traefik.http.services.space-initlab.loadbalancer.server.port=5173
- traefik.http.routers.space-initlab-secure.rule=Host(`space.initlab.lan`)
- traefik.http.routers.space-initlab-secure.service=space-initlab
- traefik.http.routers.space-initlab-secure.entrypoints=websecure
- traefik.http.routers.space-initlab-secure.tls
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --no-open --host 0.0.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move these parameters to Dockerfile CMD line

"build": "vite build",
"preview": "vite preview",
"lint": "eslint --ext .js,.jsx src/"
Expand All @@ -17,6 +17,7 @@
"bootstrap": "^5.3.1",
"bootswatch": "^5.3.1",
"date-fns": "^2.30.0",
"debounce": "^2.0.0",
"i18next": "^23.5.1",
"i18next-http-backend": "^2.2.2",
"js-pkce": "^1.3.0",
Expand Down
15 changes: 10 additions & 5 deletions src/widgets/DeviceActionButton/DeviceActionButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import './DeviceActionButton.scss';
import { useDeviceActionMutation } from '../../features/apiSlice.js';
import RedirectToLogin from '../RedirectToLogin.jsx';
import { sleep } from '../../utils/time.js';
import debounce from 'debounce';

const types = {
open: {
Expand Down Expand Up @@ -50,15 +51,19 @@ const DeviceActionButton = ({
icon: '',
};

const openDoor = debounce(execute, 2000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the timeout at 3000, since the door mechanisms are open for at least 3 seconds and there is no reason to request opening again. Also this is a generic function that is used for both doors and lights (and other things in the future) so please either use a more generic name like executeDelayed or limit debouncing to just the door device type.


async function handleClick() {
setDisabled(true);

await execute({
deviceId,
action,
});
// await execute({
// deviceId,
// action,
// });
Comment on lines +59 to +62
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the old code, it can be easily recovered from the Git history.


openDoor({deviceId, action});

await sleep(3000);
// await sleep(3000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

setDisabled(false);
}

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3065,6 +3065,11 @@ date-fns@^2.30.0:
dependencies:
"@babel/runtime" "^7.21.0"

debounce@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/debounce/-/debounce-2.0.0.tgz#b2f914518a1481466f4edaee0b063e4d473ad549"
integrity sha512-xRetU6gL1VJbs85Mc4FoEGSjQxzpdxRyFhe3lmWFyy2EzydIcD4xzUvRJMD+NPDfMwKNhxa3PvsIOU32luIWeA==

debug@^3.2.7:
version "3.2.7"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a"
Expand Down