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

Delay search url updating to not add lots of half written queries #654

Merged
merged 5 commits into from
Sep 23, 2024
Merged
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
2 changes: 2 additions & 0 deletions e2e/cypress/e2e/multiProject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ describe('Multi project page', () => {
// Search for the project
cy.get('[data-cy=search-field] > input').type(user.username)

cy.wait(1000)

// Click on a multiproject project card
cy.get('[data-cy=project-card]')
.first()
Expand Down
20 changes: 18 additions & 2 deletions frontend/src/components/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,29 @@ const SearchInput = () => {
}, [routerQuery])

const debouncedSubmit = useRef(debounce(value => updateContextQuery(value), 100))
const debouncedUpdateUrl = useRef(
debounce(value => {
const path = value ? `/search?q=${encodeURIComponent(value)}` : '/'
replace(path, undefined, { shallow: true })
}, 500),
)

// Cancel on component dismount
useEffect(() => {
return () => {
// I don't understand what react / eslint wants us to do in this case:
// the ref doesn't actually change.
// eslint-disable-next-line react-hooks/exhaustive-deps
debouncedUpdateUrl.current.cancel()
}
}, [])

const handleChange = (value: string) => {
debouncedSubmit.current.cancel()
debouncedUpdateUrl.current.cancel()
setInputQuery(value)
debouncedSubmit.current(value)
const path = value ? `/search?q=${encodeURIComponent(value)}` : '/'
replace(path, undefined, { shallow: true })
debouncedUpdateUrl.current(value)
}

return (
Expand Down
2 changes: 2 additions & 0 deletions processor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ RUN addgroup --gid 1000 node && \
mkdir /data /gitea-data && \
chown -R node /data /gitea-data

RUN git config --global --add safe.directory '*'

USER node
CMD ["node", "dist/src/main.js"]
1 change: 1 addition & 0 deletions processor/src/queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ async function sync(gitDir, checkoutDir) {
try {
await sh`git clone ${gitDir} ${checkoutDir}`
} catch (err) {
log.error(err)
if (err.stderr) {
return
}
Expand Down
6 changes: 4 additions & 2 deletions scripts/importBoardsTxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ async function generateGiteaAdminToken() {
)

if (!giteaAdminCommand.status.success) {
throw new Error('Failed to create gitea admin user')
console.error(giteaAdminCommand.output)
throw new Error("Failed to create gitea admin user")
}

const giteaAdminTokenCommand = await exec(
Expand All @@ -308,7 +309,8 @@ async function generateGiteaAdminToken() {
)

if (!giteaAdminTokenCommand.status.success) {
throw new Error('Failed to create gitea admin token')
console.error(giteaAdminTokenCommand.output)
throw new Error("Failed to create gitea admin token")
}

return giteaAdminTokenCommand.output.split('\n').at(-1)
Expand Down
Loading