From 24bb531dfbf0e8f4dcc9b0386621f0fdc42816bb Mon Sep 17 00:00:00 2001
From: kilyabin <65072190+kilyabin@users.noreply.github.com>
Date: Wed, 26 Nov 2025 01:09:46 +0400
Subject: [PATCH] feat(ui): improve lesson cards and theme button, optimize
dependency checks
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
UI Improvements:
- Highlight classroom number in lesson cards using Badge component
* Applied to both mobile and desktop views
* Improved visual distinction for classroom information
- Fix theme switcher button layout on mobile
* Add "Тема" text label inside the button (visible on all devices)
* Remove redundant absolute positioned span below button
* Fix text overflow issues on mobile devices
* Improve button isolation to prevent text escaping
Performance Optimization:
- Optimize dependency installation check in deployment scripts
* Replace timestamp-based check with content hash comparison
* Use MD5 hash of package.json and lock files to detect real changes
* Save hash after successful installation for future comparisons
* Significantly reduce unnecessary npm install runs during updates
* Add .dependencies.hash to .gitignore
Files changed:
- src/widgets/schedule/lesson.tsx - Added Badge for classroom
- src/features/theme-switch/index.tsx - Added text label to button
- src/widgets/navbar/index.tsx - Improved button container structure
- src/pages/index.tsx - Removed redundant theme label span
- scripts/manage.sh - Optimized dependency check logic
- scripts/install.sh - Optimized dependency check logic
- .gitignore - Added .dependencies.hash exclusion
---
.gitignore | 5 +++-
scripts/install.sh | 44 +++++++++++++++++++---------
scripts/manage.sh | 45 ++++++++++++++++++++---------
src/features/theme-switch/index.tsx | 44 +++++++++++++++-------------
src/pages/index.tsx | 5 +---
src/widgets/navbar/index.tsx | 7 +++--
src/widgets/schedule/lesson.tsx | 10 +++++--
7 files changed, 102 insertions(+), 58 deletions(-)
diff --git a/.gitignore b/.gitignore
index 58f68bf..97e9c3c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,4 +35,7 @@ yarn-error.log*
next-env.d.ts
.vscode/
/.vscode
-.env
\ No newline at end of file
+.env
+
+# dependency hash (installation-specific)
+.dependencies.hash
\ No newline at end of file
diff --git a/scripts/install.sh b/scripts/install.sh
index 24835bc..ebcae3c 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -169,38 +169,54 @@ cd "$INSTALL_DIR"
# Check if node_modules exists and is up to date
NEED_INSTALL=true
LOCK_FILE=""
+DEPENDENCY_HASH_FILE="$INSTALL_DIR/.dependencies.hash"
+
if [ -f "package-lock.json" ]; then
LOCK_FILE="package-lock.json"
elif [ -f "pnpm-lock.yaml" ]; then
LOCK_FILE="pnpm-lock.yaml"
fi
-if [ -d "node_modules" ] && [ -n "$LOCK_FILE" ]; then
- # Check if package.json is newer than lock file
- if [ "package.json" -nt "$LOCK_FILE" ]; then
- echo -e "${YELLOW}package.json is newer than $LOCK_FILE, reinstalling...${NC}"
- NEED_INSTALL=true
- else
- # Check if all dependencies are installed by checking if node_modules/.bin exists and has entries
- if [ -d "node_modules/.bin" ] && [ "$(ls -A node_modules/.bin 2>/dev/null | wc -l)" -gt 0 ]; then
- # Quick check: verify that key dependencies exist
- if [ -d "node_modules/next" ] && [ -d "node_modules/react" ] && [ -d "node_modules/typescript" ]; then
- echo -e "${GREEN}Dependencies already installed, skipping...${NC}"
- NEED_INSTALL=false
+if [ -d "node_modules" ] && [ -n "$LOCK_FILE" ] && [ -f "package.json" ] && [ -f "$LOCK_FILE" ]; then
+ # Calculate hash of package files (content-based, not timestamp)
+ CURRENT_HASH=$(cat package.json "$LOCK_FILE" 2>/dev/null | md5sum | cut -d' ' -f1)
+
+ # Check if hash file exists and matches
+ if [ -f "$DEPENDENCY_HASH_FILE" ]; then
+ SAVED_HASH=$(cat "$DEPENDENCY_HASH_FILE" 2>/dev/null)
+ if [ "$CURRENT_HASH" = "$SAVED_HASH" ]; then
+ # Hash matches, check if key dependencies exist
+ if [ -d "node_modules/.bin" ] && [ "$(ls -A node_modules/.bin 2>/dev/null | wc -l)" -gt 0 ]; then
+ if [ -d "node_modules/next" ] && [ -d "node_modules/react" ] && [ -d "node_modules/typescript" ]; then
+ echo -e "${GREEN}Dependencies are up to date (content unchanged), skipping installation...${NC}"
+ NEED_INSTALL=false
+ else
+ echo -e "${YELLOW}Hash matches but some dependencies missing, reinstalling...${NC}"
+ NEED_INSTALL=true
+ fi
else
- echo -e "${YELLOW}Some dependencies missing, reinstalling...${NC}"
+ echo -e "${YELLOW}Hash matches but node_modules incomplete, reinstalling...${NC}"
NEED_INSTALL=true
fi
else
- echo -e "${YELLOW}node_modules appears incomplete, reinstalling...${NC}"
+ echo -e "${YELLOW}Dependency files changed (content differs), reinstalling...${NC}"
NEED_INSTALL=true
fi
+ else
+ echo -e "${YELLOW}No hash file found, need to install dependencies...${NC}"
+ NEED_INSTALL=true
fi
fi
if [ "$NEED_INSTALL" = true ]; then
echo -e "${YELLOW}Installing dependencies...${NC}"
npm ci --legacy-peer-deps --production=false
+
+ # Save hash after successful installation
+ if [ -n "$LOCK_FILE" ] && [ -f "package.json" ] && [ -f "$LOCK_FILE" ]; then
+ cat package.json "$LOCK_FILE" 2>/dev/null | md5sum | cut -d' ' -f1 > "$DEPENDENCY_HASH_FILE"
+ echo -e "${GREEN}Saved dependency hash for future checks${NC}"
+ fi
else
echo -e "${GREEN}Dependencies are up to date, skipping installation${NC}"
fi
diff --git a/scripts/manage.sh b/scripts/manage.sh
index 3509be2..8d3c76a 100755
--- a/scripts/manage.sh
+++ b/scripts/manage.sh
@@ -102,6 +102,7 @@ case "$1" in
--exclude='.env.test' \
--exclude='.env.test.local' \
--exclude='*.md' \
+ --exclude='.dependencies.hash' \
"$PROJECT_DIR/" "$INSTALL_DIR/"
# Handle .env file (preserve existing if present)
@@ -121,38 +122,54 @@ case "$1" in
# Check if node_modules exists and is up to date
NEED_INSTALL=true
LOCK_FILE=""
+ DEPENDENCY_HASH_FILE="$INSTALL_DIR/.dependencies.hash"
+
if [ -f "package-lock.json" ]; then
LOCK_FILE="package-lock.json"
elif [ -f "pnpm-lock.yaml" ]; then
LOCK_FILE="pnpm-lock.yaml"
fi
- if [ -d "node_modules" ] && [ -n "$LOCK_FILE" ]; then
- # Check if package.json is newer than lock file
- if [ "package.json" -nt "$LOCK_FILE" ]; then
- echo -e "${YELLOW}package.json is newer than $LOCK_FILE, reinstalling...${NC}"
- NEED_INSTALL=true
- else
- # Check if all dependencies are installed by checking if node_modules/.bin exists and has entries
- if [ -d "node_modules/.bin" ] && [ "$(ls -A node_modules/.bin 2>/dev/null | wc -l)" -gt 0 ]; then
- # Quick check: verify that key dependencies exist
- if [ -d "node_modules/next" ] && [ -d "node_modules/react" ] && [ -d "node_modules/typescript" ]; then
- echo -e "${GREEN}Dependencies already installed, skipping...${NC}"
- NEED_INSTALL=false
+ if [ -d "node_modules" ] && [ -n "$LOCK_FILE" ] && [ -f "package.json" ] && [ -f "$LOCK_FILE" ]; then
+ # Calculate hash of package files (content-based, not timestamp)
+ CURRENT_HASH=$(cat package.json "$LOCK_FILE" 2>/dev/null | md5sum | cut -d' ' -f1)
+
+ # Check if hash file exists and matches
+ if [ -f "$DEPENDENCY_HASH_FILE" ]; then
+ SAVED_HASH=$(cat "$DEPENDENCY_HASH_FILE" 2>/dev/null)
+ if [ "$CURRENT_HASH" = "$SAVED_HASH" ]; then
+ # Hash matches, check if key dependencies exist
+ if [ -d "node_modules/.bin" ] && [ "$(ls -A node_modules/.bin 2>/dev/null | wc -l)" -gt 0 ]; then
+ if [ -d "node_modules/next" ] && [ -d "node_modules/react" ] && [ -d "node_modules/typescript" ]; then
+ echo -e "${GREEN}Dependencies are up to date (content unchanged), skipping installation...${NC}"
+ NEED_INSTALL=false
+ else
+ echo -e "${YELLOW}Hash matches but some dependencies missing, reinstalling...${NC}"
+ NEED_INSTALL=true
+ fi
else
- echo -e "${YELLOW}Some dependencies missing, reinstalling...${NC}"
+ echo -e "${YELLOW}Hash matches but node_modules incomplete, reinstalling...${NC}"
NEED_INSTALL=true
fi
else
- echo -e "${YELLOW}node_modules appears incomplete, reinstalling...${NC}"
+ echo -e "${YELLOW}Dependency files changed (content differs), reinstalling...${NC}"
NEED_INSTALL=true
fi
+ else
+ echo -e "${YELLOW}No hash file found, need to install dependencies...${NC}"
+ NEED_INSTALL=true
fi
fi
if [ "$NEED_INSTALL" = true ]; then
echo -e "${YELLOW}Installing dependencies...${NC}"
npm ci --legacy-peer-deps --production=false
+
+ # Save hash after successful installation
+ if [ -n "$LOCK_FILE" ] && [ -f "package.json" ] && [ -f "$LOCK_FILE" ]; then
+ cat package.json "$LOCK_FILE" 2>/dev/null | md5sum | cut -d' ' -f1 > "$DEPENDENCY_HASH_FILE"
+ echo -e "${GREEN}Saved dependency hash for future checks${NC}"
+ fi
else
echo -e "${GREEN}Dependencies are up to date, skipping installation${NC}"
fi
diff --git a/src/features/theme-switch/index.tsx b/src/features/theme-switch/index.tsx
index d76d421..10d9c30 100644
--- a/src/features/theme-switch/index.tsx
+++ b/src/features/theme-switch/index.tsx
@@ -16,25 +16,29 @@ export function ThemeSwitcher() {
const { setTheme } = useTheme()
return (
-