Skip to content

Commit 275db03

Browse files
authored
refactor: extract responsive breakpoint widths into constants (#5018)
* refactor: extract responsive breakpoint widths into constants - Add BREAKPOINT_TABLET (768px) and BREAKPOINT_MOBILE (600px) constants - Replace 5 hardcoded breakpoint values with named constants - Improves code maintainability and prevents magic numbers Affected lines: 769, 776, 787, 794, 856 in js/activity.js * changing to a much verbose variable name
1 parent b4fa9db commit 275db03

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

js/activity.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ const _THIS_IS_TURTLE_BLOCKS_ = !_THIS_IS_MUSIC_BLOCKS_;
5454
const _ERRORMSGTIMEOUT_ = 15000;
5555
const _MSGTIMEOUT_ = 60000;
5656

57+
// Responsive breakpoint constants
58+
const RESPONSIVE_BREAKPOINT_TABLET = 768;
59+
const RESPONSIVE_BREAKPOINT_MOBILE = 600;
60+
5761
let MYDEFINES = [
5862
"utils/platformstyle",
5963
"easeljs.min",
@@ -765,14 +769,20 @@ class Activity {
765769
};
766770
}
767771

768-
if (canvasWidth < 768 && !referenceBlock.beforeMobilePosition) {
772+
if (
773+
canvasWidth < RESPONSIVE_BREAKPOINT_TABLET &&
774+
!referenceBlock.beforeMobilePosition
775+
) {
769776
referenceBlock.beforeMobilePosition = {
770777
x: referenceBlock.container.x,
771778
y: referenceBlock.container.y
772779
};
773780
}
774781

775-
if (canvasWidth >= 768 && referenceBlock.beforeMobilePosition) {
782+
if (
783+
canvasWidth >= RESPONSIVE_BREAKPOINT_TABLET &&
784+
referenceBlock.beforeMobilePosition
785+
) {
776786
const dx = referenceBlock.beforeMobilePosition.x - referenceBlock.container.x;
777787
const dy = referenceBlock.beforeMobilePosition.y - referenceBlock.container.y;
778788
group.forEach(blockId => {
@@ -784,14 +794,20 @@ class Activity {
784794
//this prevents old groups from affecting new calculations.
785795
}
786796

787-
if (canvasWidth < 600 && !referenceBlock.before600pxPosition) {
797+
if (
798+
canvasWidth < RESPONSIVE_BREAKPOINT_MOBILE &&
799+
!referenceBlock.before600pxPosition
800+
) {
788801
referenceBlock.before600pxPosition = {
789802
x: referenceBlock.container.x,
790803
y: referenceBlock.container.y
791804
};
792805
}
793806

794-
if (canvasWidth >= 600 && referenceBlock.before600pxPosition) {
807+
if (
808+
canvasWidth >= RESPONSIVE_BREAKPOINT_MOBILE &&
809+
referenceBlock.before600pxPosition
810+
) {
795811
const dx = referenceBlock.before600pxPosition.x - referenceBlock.container.x;
796812
const dy = referenceBlock.before600pxPosition.y - referenceBlock.container.y;
797813

@@ -855,7 +871,7 @@ class Activity {
855871
this.blocksContainer.y = 0;
856872

857873
const screenWidth = window.innerWidth;
858-
const isNarrowScreen = screenWidth < 600;
874+
const isNarrowScreen = screenWidth < RESPONSIVE_BREAKPOINT_MOBILE;
859875
const minColumnWidth = 400;
860876
const numColumns = isNarrowScreen ? 1 : Math.floor(screenWidth / minColumnWidth);
861877

0 commit comments

Comments
 (0)