Skip to content

Commit

Permalink
Improve animations
Browse files Browse the repository at this point in the history
  • Loading branch information
sawyerh committed Jul 23, 2023
1 parent 9802e9d commit a2849c6
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions web/src/components/AI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useQuery,
} from "@tanstack/react-query";
import classNames from "classnames";
import { AnimatePresence, motion } from "framer-motion";
import { motion } from "framer-motion";
import { request } from "helpers/request";
import useLockBodyScroll from "hooks/useLockBodyScroll";
import { ForwardedRef, forwardRef, useEffect, useRef, useState } from "react";
Expand All @@ -22,15 +22,7 @@ const queryClient = new QueryClient();
* Search result item
*/
function Result(props: { children: React.ReactNode }) {
return (
<motion.div
animate={{ y: 0, opacity: 1 }}
exit={{ y: 20, opacity: 0 }}
initial={{ y: 20, opacity: 0 }}
>
<div className="mb-5 rounded-md bg-white p-5">{props.children}</div>
</motion.div>
);
return <div className="mb-5 rounded-md bg-white p-5">{props.children}</div>;
}

/**
Expand Down Expand Up @@ -152,35 +144,39 @@ const SearchDialog = forwardRef(function SearchDialog(
</button>
</div>
</form>
<AnimatePresence mode="wait">
{isFetching ? (
<motion.div
key="results-loader"
animate={{
opacity: 1,
y: 0,
}}
className="text-shadow-sm text-white"
exit={{ opacity: 0, y: -20 }}
initial={{
opacity: 0,
y: -20,
}}
>
Searching&hellip;
</motion.div>
) : (
queryResults?.map((result) => (
{isFetching ? (
<motion.div
key="results-loader"
animate={{
opacity: 1,
y: 0,
}}
exit={{ opacity: 0, y: -20 }}
initial={{
opacity: 0,
y: -20,
}}
>
<p className="text-shadow-sm text-white">Searching&hellip;</p>
</motion.div>
) : (
<motion.div
key="results"
animate={{ y: 0, opacity: 1 }}
exit={{ y: 20, opacity: 0 }}
initial={{ y: 20, opacity: 0 }}
>
{queryResults?.map((result) => (
<Result key={result.highlight_key}>
<Highlight
body={result.body}
id={result.highlight_key}
onLinkClick={props.hide}
/>
</Result>
))
)}
</AnimatePresence>
))}
</motion.div>
)}
</div>
</dialog>
);
Expand Down

0 comments on commit a2849c6

Please sign in to comment.