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

[Frontend] Fix Search Posts bugs #596

Open
wants to merge 4 commits into
base: main
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useNavigate } from 'react-router-dom'
import { useState, KeyboardEvent } from 'react'
import { PATHS } from '@/constants/paths'
import { ReactComponent as SearchIcon } from '@/assets/svg/search.svg'

export default function SearchInput() {
Expand All @@ -8,12 +9,14 @@ export default function SearchInput() {

const handleSearch = (e: KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter') {
navigate(`?q=${encodeURIComponent(query.trim())}`)
e.preventDefault()
e.stopPropagation()
navigate(`${PATHS.HOME}?q=${encodeURIComponent(query.trim())}`)
}
}

const onClick = () => {
navigate(`?q=${encodeURIComponent(query.trim())}`)
navigate(`${PATHS.HOME}?q=${encodeURIComponent(query.trim())}`)
}

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CLEAR_EDITOR_COMMAND } from 'lexical'
import { $getRoot, CLEAR_EDITOR_COMMAND } from 'lexical'
import { useEffect } from 'react'
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
import { useIsFirstRender } from '@uidotdev/usehooks'
Expand All @@ -14,9 +14,16 @@ export default function ClearAllPlugin({
const [editor] = useLexicalComposerContext()
useEffect(() => {
if (!value && !isFirstRender) {
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined)
editor.focus()
onClear?.()
editor.getEditorState().read(() => {
const root = $getRoot()
const isContentEmpty = root.getTextContent() === ''

if (isContentEmpty) return

editor.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined)
editor.focus()
onClear?.()
})
}
}, [value, isFirstRender, editor, onClear])
return null
Expand Down