Skip to content

Commit

Permalink
Remove console.logs, add useDebounce hook, update HeaderSearch to new…
Browse files Browse the repository at this point in the history
… TextInput
  • Loading branch information
VanyaMate committed Oct 13, 2024
1 parent eb33a6c commit 5c32ec0
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export const useDialoguesStoreUpdaterByNotifications = function () {
}, []);

useLayoutEffect(() => {
console.log('here', dialogues, notification);

if (dialogues) {
const onPrivateMessageIn = applyEffect(sendPrivateMessageNotificationEffect);
const onReadMessage = applyEffect(readPrivateMessageNotificationEffect);
Expand Down
2 changes: 0 additions & 2 deletions src/pages/DialoguesPage/ui/DialoguesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export const DialoguesPage: FC<DialoguesPageProps> = memo(function DialoguesPage
const dialogue = dialogues.find((dialogue) => dialogue.id === dialogueId);
const dialogueTitle = dialogue.title || dialogue.user.login;

console.log('set page title to with dialogue', t.app.dialogue_page);
setPageTitle(
replace(
t.app.dialogue_page,
Expand All @@ -78,7 +77,6 @@ export const DialoguesPage: FC<DialoguesPageProps> = memo(function DialoguesPage
),
);
} else {
console.log('set page title to', t.app.dialogue_page);
setPageTitle(t.app.dialogues_page);
}
}, [ dialogueId, dialogueNotSelected, dialogues, replace, setPageTitle, t.app.dialogue_page, t.app.dialogues_page ]);
Expand Down
13 changes: 13 additions & 0 deletions src/shared/hooks/useDebounce/useDebounce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useRef } from 'react';


export type DebounceCallback = () => any;

export const useDebounce = function (ms: number) {
const timer = useRef<ReturnType<typeof setTimeout>>();

return (callback: DebounceCallback) => {
clearTimeout(timer.current);
timer.current = setTimeout(callback, ms);
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ export const useVirtualScroll = function (props: UseVirtualScrollProps) {
previousScrollHeight.current = ref.scrollHeight;

return () => {
console.log('[RETURN] RefContainerHeight', ref.scrollHeight);

};
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/shared/ui-kit/input/TextInput/ui/TextInput.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@
background : var(--bg-ghost-color);
color : var(--bg-second-foreground-color);

&:valid {
border : 1px solid var(--primary-color);
}

&:focus {
box-shadow : 0 0 0 1px var(--primary-color), 0 5px 25px -5px var(--primary-color);
border : 1px solid var(--primary-color);
background : var(--bg-main-color);
}

&:required:valid {
border : 1px solid var(--primary-color);
}

&.inputError:not(:focus) {
border : 1px solid var(--danger-color);

Expand Down
1 change: 0 additions & 1 deletion src/shared/ui-kit/modal/Tooltip/ui/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export const Tooltip: FC<TooltipProps> = memo(function Tooltip (props) {
useEffect(() => {
if (show && currentTooltipRenderState && elementRef.current && tooltipRef.current) {
const observer = new IntersectionObserver(() => {
console.log('resized');
setPositionOffset(() => {
const positionDelta = getModalPosition(elementRef, tooltipRef, tooltipPosition);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export const LanguagesContainer: FC<LanguagesContainerProps> = memo(function Lan

useLayoutEffect(() => {
// Tempo
console.log('loading for ->', userId);
getMyLanguagesEffect();
}, [ userId ]);

Expand Down
1 change: 1 addition & 0 deletions src/widgets/posts/CreatePostForm/ui/CreatePostForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const CreatePostForm: FC = memo(function CreatePostForm () {
className={ css.input }
errorMessage={ formState.errors.message?.message }
placeholder={ t.page.posts.write_new_post }
required
type="text"
{ ...register('message', {
required: true,
Expand Down
35 changes: 18 additions & 17 deletions src/widgets/site/search/HeaderSearch/HeaderSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import { ComponentPropsWithoutRef, FC, memo } from 'react';
import classNames from 'classnames';
import css from './HeaderSearch.module.scss';
import { useSearchParams } from 'react-router-dom';
import {
useInputWithError,
} from '@/shared/ui-kit/inputs/InputWithError/hooks/useInputWithError.ts';
import {
InputWithError,
} from '@/shared/ui-kit/inputs/InputWithError/ui/InputWithError.tsx';
import {
useDropdownController,
} from '@/shared/ui-kit/modal/Dropdown/hooks/useDropdownController.ts';
Expand All @@ -16,6 +10,9 @@ import {
SearchContainer,
} from '@/widgets/search/container/SearchContainer/SearchContainer.tsx';
import { useTranslation } from '@/features/i18n/hook/useTranslation.ts';
import { TextInput } from '@/shared/ui-kit/input/TextInput/ui/TextInput.tsx';
import { useForm } from 'react-hook-form';
import { useDebounce } from '@/shared/hooks/useDebounce/useDebounce.ts';


export type HeaderSearchProps =
Expand All @@ -25,6 +22,7 @@ export type HeaderSearchProps =
export const HeaderSearch: FC<HeaderSearchProps> = memo(function HeaderSearch (props) {
const { className, ...other } = props;
const [ searchParams, setSearchParams ] = useSearchParams();
const debounce = useDebounce(300);
const dropdown = useDropdownController();
const setQuery = (query: string) => {
if (query) {
Expand All @@ -35,11 +33,9 @@ export const HeaderSearch: FC<HeaderSearchProps> = memo(function HeaderSearch (p
dropdown.setOpened(false);
}
};
const search = useInputWithError({
name : '',
onChangeHandler: setQuery,
debounce : 300,
});
const { handleSubmit, register } = useForm<{ search: string }>(
{ mode: 'onChange' },
);
const { t } = useTranslation();

return (
Expand All @@ -57,12 +53,17 @@ export const HeaderSearch: FC<HeaderSearchProps> = memo(function HeaderSearch (p
}
>
<search role="search">
<InputWithError
className={ classNames(css.input, {}, [ css.item ]) }
containerClassName={ css.inputContainer }
controller={ search }
placeholder={ t.search.search_placeholder }
/>
<form
className={ css.inputContainer }
onChange={ handleSubmit(({ search }) => debounce(() => setQuery(search))) }
>
<TextInput
className={ css.input }
placeholder={ t.search.search_placeholder }
type="text"
{ ...register('search') }
/>
</form>
</search>
</Dropdown>
</div>
Expand Down

0 comments on commit 5c32ec0

Please sign in to comment.