Skip to content

Commit

Permalink
disable animated title
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Jul 26, 2024
1 parent 97f2dbe commit d3e5f49
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 51 deletions.
97 changes: 48 additions & 49 deletions packages/ui/app/src/api-page/endpoints/AnimatedTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
import { FC } from "react";
import { FC, useEffect, useState } from "react";

export const AnimatedTitle: FC<{ children: string }> = ({ children: nextChild }) => {
// const [displayText, setDisplayText] = useState(nextChild);
// const [prevChild, setPrevChild] = useState(nextChild);
const [displayText, setDisplayText] = useState(nextChild);
const [prevChild, setPrevChild] = useState(nextChild);

// useEffect(() => {
// if (prevChild !== nextChild) {
// const commonPrefix = getCommonPrefix(prevChild, nextChild);
// const contractText = prevChild.slice(commonPrefix.length);
// const expandText = nextChild.slice(commonPrefix.length);
useEffect(() => {
if (prevChild !== nextChild) {
const commonPrefix = getCommonPrefix(prevChild, nextChild);
const contractText = prevChild.slice(commonPrefix.length);
const expandText = nextChild.slice(commonPrefix.length);

// let currentIndex = 0;
// const intervalId = setInterval(() => {
// setDisplayText((prevText) => {
// if (currentIndex >= contractText.length) {
// clearInterval(intervalId);
// animateExpand(commonPrefix, expandText);
// return prevText;
// }
// currentIndex++;
// return commonPrefix + contractText.slice(0, -currentIndex);
// });
// }, 50);
let currentIndex = 0;
const intervalId = setInterval(() => {
setDisplayText((prevText) => {
if (currentIndex >= contractText.length) {
clearInterval(intervalId);
animateExpand(commonPrefix, expandText);
return prevText;
}
currentIndex++;
return commonPrefix + contractText.slice(0, -currentIndex);
});
}, 50);

// return () => {
// clearInterval(intervalId);
// };
// }
// return;
// }, [nextChild, prevChild]);
return () => {
clearInterval(intervalId);
};
}
return;
}, [nextChild, prevChild]);

// const animateExpand = (commonPrefix: string, expandText: string) => {
// let currentIndex = 0;
// const intervalId = setInterval(() => {
// setDisplayText(() => {
// if (currentIndex >= expandText.length) {
// clearInterval(intervalId);
// setPrevChild(commonPrefix + expandText);
// return commonPrefix + expandText;
// }
// currentIndex++;
// return commonPrefix + expandText.slice(0, currentIndex);
// });
// }, 50);
// };
const animateExpand = (commonPrefix: string, expandText: string) => {
let currentIndex = 0;
const intervalId = setInterval(() => {
setDisplayText(() => {
if (currentIndex >= expandText.length) {
clearInterval(intervalId);
setPrevChild(commonPrefix + expandText);
return commonPrefix + expandText;
}
currentIndex++;
return commonPrefix + expandText.slice(0, currentIndex);
});
}, 50);
};

// return <>{displayText}</>;
return <>{nextChild}</>;
return <>{displayText}</>;
};

// const getCommonPrefix = (str1: string, str2: string): string => {
// let i = 0;
// while (i < str1.length && i < str2.length && str1[i] === str2[i]) {
// i++;
// }
// return str1.slice(0, i);
// };
const getCommonPrefix = (str1: string, str2: string): string => {
let i = 0;
while (i < str1.length && i < str2.length && str1[i] === str2[i]) {
i++;
}
return str1.slice(0, i);
};
4 changes: 2 additions & 2 deletions packages/ui/app/src/api-page/endpoints/EndpointContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
import { ApiPageDescription } from "../ApiPageDescription";
import { JsonPropertyPath } from "../examples/JsonPropertyPath";
import { CodeExample, generateCodeExamples } from "../examples/code-example";
import { AnimatedTitle } from "./AnimatedTitle";
import { EndpointAvailabilityTag } from "./EndpointAvailabilityTag";
import { EndpointContentLeft, convertNameToAnchorPart } from "./EndpointContentLeft";
import { EndpointStreamingEnabledToggle } from "./EndpointStreamingEnabledToggle";
Expand Down Expand Up @@ -279,7 +278,8 @@ const UnmemoizedEndpointContent: React.FC<EndpointContent.Props> = ({
<div className="flex items-center justify-between">
<span>
<h1 className="fern-page-heading">
<AnimatedTitle>{endpoint.title}</AnimatedTitle>
{/* <AnimatedTitle>{endpoint.title}</AnimatedTitle> */}
{endpoint.title}
</h1>
{endpoint.availability != null && (
<span className="inline-block ml-2 align-text-bottom">
Expand Down

0 comments on commit d3e5f49

Please sign in to comment.