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

fixed #445 by adding a animated search component #459

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useEffect, useState } from 'react';

import styles from './slider.module.css';

const AnimatedInputWrapper = () => {
return (
<div className={styles.placeholder}>
<AnimatedPlaceHolderWrapper />
</div>
);
};

const popRepos = ['golang/go', 'mozilla/rust', 'apple/swift', 'oven-sh/bun'];
const AnimatedPlaceHolderWrapper = () => {
return (
<div className={styles.animationWrapper}>
<span>Search for</span>
<AnimatedRepos />
</div>
);
};

const AnimatedRepos = () => {
const [animationIndex, setAnimationIndex] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
if (animationIndex < popRepos.length - 1) {
setAnimationIndex(animationIndex + 1);
} else {
setAnimationIndex(0);
}
}, 2000);
return () => clearInterval(interval);
});
return (
<div className={styles.textslide}>
<div
className={styles.text}
style={{ bottom: animationIndex * 1.4 + 'em' }}
>
{popRepos.map((item) => (
<div key={item} className={styles.repo}>
<span>{item}</span>
</div>
))}
</div>
</div>
);
};

export default AnimatedInputWrapper;
29 changes: 29 additions & 0 deletions web-server/src/components/AnimatedInputWrapper/slider.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.animationWrapper{
position: absolute;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are using absolute position, but the parent (element wrapping this component) isn't having relative position.
this can cause unexpected behaviour when you are trying to debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave position:relative to .placeholder which was the parent element of .animationWrapper

top: 50%;
transform: translate(0%, -50%);
font-size: 1em;
display: flex;
gap: 4px;
}

.placeholder{
height: 1.4em;
width: 10rem;
position: relative;
}

.repo{
height: 1.4em;
}

.text{
position: relative;
transition: all 0.5s ease;
}

.textslide{
display: flex;
height: 1.4em;
align-items: flex-start;
}
14 changes: 11 additions & 3 deletions web-server/src/components/Teams/CreateTeams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { DeploymentWorkflowSelector } from '@/components/WorkflowSelector';
import { useBoolState, useEasyState } from '@/hooks/useEasyState';
import { BaseRepo, DeploymentSources } from '@/types/resources';

import AnimatedInputWrapper from '../AnimatedInputWrapper/AnimatedInputWrapper';
import { FlexBox } from '../FlexBox';
import { Line } from '../Text';

Expand Down Expand Up @@ -162,6 +163,7 @@ const TeamRepos: FC = () => {
} = useTeamCRUD();

const searchQuery = useEasyState('');
const searchFocus = useBoolState(false);

return (
<FlexBox col gap={2}>
Expand Down Expand Up @@ -191,15 +193,21 @@ const TeamRepos: FC = () => {
getOptionLabel={(option) => `${option.parent}/${option.name}`}
renderInput={(params) => (
<TextField
onFocus={searchFocus.true}
onBlur={searchFocus.false}
onChange={(e) => {
handleReposSearch(e as React.ChangeEvent<HTMLInputElement>);
searchQuery.set(e.target.value);
}}
{...params}
label={
selectedRepos.length
? `${selectedRepos.length} selected`
: `Search repositories`
selectedRepos.length ? (
`${selectedRepos.length} selected`
) : !searchFocus.value ? (
<AnimatedInputWrapper />
) : (
'Search for org/repo'
)
}
error={teamRepoError}
InputProps={{
Expand Down