From 7c3541d14e344fff93f17e574b09d34e339d5abf Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 20 Jun 2024 18:14:58 +0300 Subject: [PATCH 1/4] FM-33: edit .eslintrc config for prettier errors, update git hook --- .eslintrc | 2 +- .husky/commit-msg | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.eslintrc b/.eslintrc index 46ce070..d44b2ee 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,7 +11,7 @@ "plugins": ["@typescript-eslint"], "rules": { - "prettier/prettier": 1, + "prettier/prettier": 2, "no-console": 1, "no-unused-vars": 0, "@typescript-eslint/no-unused-vars": 0, diff --git a/.husky/commit-msg b/.husky/commit-msg index 73bd03a..4b772b7 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,5 +1,9 @@ #! /usr/bin/env bash +# Task +# Minimal checking if our commit message pattern locally and our branch name pattern are equal + +# Logs colors in termainal about seccess or failure WHITE='\033[0;37m' RED='\033[0;31m' B_RED='\033[1;31m' @@ -7,19 +11,30 @@ GREEN='\033[0;32m' NO_COLOR='\033[0m' YELLOW='\033[0;33m' -current_branch_name=$(git symbolic-ref --short HEAD) # TDE-1 -branch_name_len=${#current_branch_name} # 5 +# Find your current working branch name. Ex: TDE-1 +current_branch_name=$(git symbolic-ref --short HEAD) + +# Find branch name length. Ex: 5 +branch_name_len=${#current_branch_name} + +# Find path to last commit message file. Ex: path/to/commit/msg/file +path_to_commit="$(pwd)/.git/COMMIT_EDITMSG" + +# Find last commit massage from file. Ex: TDE-1: add something +commit_msg=$(cat $path_to_commit) -path_to_commit="$(pwd)/.git/COMMIT_EDITMSG" # path/to/commit/msg/file -commit_msg=$(cat $path_to_commit) # TDE-1: add something -prefix_commit_msg=${commit_msg:0:$branch_name_len} # TDE-1 +# Match string with length from start of commit message. Ex: TDE-1 +prefix_commit_msg=${commit_msg:0:$branch_name_len} +# Compare and and handle it with tips if [[ "$current_branch_name" != "$prefix_commit_msg" ]]; then - printf "${RED}[ERROR-1]: ${B_RED}Incorrect commit message!${NO_COLOR}\n\ + # Failure + printf "${RED}✘ ${B_RED}Incorrect commit message!${NO_COLOR}\n\ ${YELLOW}Need help? You should print commit message like this:\n${YELLOW}Template:${NO_COLOR} \ ${WHITE}git commit -m \"branchName-taskNumber: your commit message here\"${NO_COLOR}\n\ -${YELLOW}Example:${NO_COLOR} ${WHITE}git commit -m \"TDE-123: minor bug fixes\"${NO_COLOR}\n" +${YELLOW}Example:${NO_COLOR} ${WHITE}git commit -m \"TDE-123: some fixes\"${NO_COLOR}\n" exit 1 else + # Success printf "${GREEN}✔${NO_COLOR} Success! Commit message approved.\n" fi \ No newline at end of file From 501db3cc0fa39906dbfaf08fd2a0ff7d049f7484 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 20 Jun 2024 19:01:36 +0300 Subject: [PATCH 2/4] FM-33: fix navbar appearance when click anywhere --- src/components/NavBar/NavBar.tsx | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/NavBar/NavBar.tsx b/src/components/NavBar/NavBar.tsx index c3c4d32..2955e64 100644 --- a/src/components/NavBar/NavBar.tsx +++ b/src/components/NavBar/NavBar.tsx @@ -1,6 +1,6 @@ 'use client' -import { useEffect, useState } from 'react' +import { useEffect, useRef, useState } from 'react' import c from 'classnames' import { usePathname } from 'next/navigation' import { navLinks } from './helpers/navLinks' @@ -12,13 +12,31 @@ import style from './NavBar.module.scss' const NavBar = () => { const [toggleMenu, setToggleMenu] = useState(false) const pathname = usePathname() + const ref = useRef(null) + + useEffect(() => { + if (toggleMenu) { + window.addEventListener('click', hasParent) + } else { + removeEventListener('click', hasParent) + } + }, [toggleMenu]) useEffect(() => { setToggleMenu(false) }, [pathname]) + const hasParent = (e: MouseEvent) => { + const clickedElem = e.target as HTMLElement + const nav = ref.current as HTMLDivElement + if (!nav.contains(clickedElem)) { + removeEventListener('click', hasParent) + setToggleMenu(false) + } + } + return ( -
+