mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
fix scroll to bottom
This commit is contained in:
@@ -9,15 +9,15 @@ type ScrollToBottomProps = {
|
|||||||
export default function ScrollToBottom(props: ScrollToBottomProps) {
|
export default function ScrollToBottom(props: ScrollToBottomProps) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`absolute left-0 w-10 h-10 ${
|
className={`absolute bottom-0 right-0 ${
|
||||||
props.visible ? "flex" : "hidden"
|
props.visible ? "flex" : "hidden"
|
||||||
} top-[49%] text-2xl cursor-pointer opacity-70 hover:opacity-100 transition-opacity duration-200 animate-bounce rounded-xl text-blue-400`}
|
} text-2xl cursor-pointer opacity-70 hover:opacity-100 transition-opacity duration-200 text-blue-400`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
props.handleScrollBottom();
|
props.handleScrollBottom();
|
||||||
return false;
|
return false;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faArrowDown} />
|
<FontAwesomeIcon icon={faArrowDown} className="animate-bounce" />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ export function TopicList({ topics, useActiveTopic }: TopicListProps) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (autoscrollEnabled) scrollToBottom();
|
if (autoscrollEnabled) scrollToBottom();
|
||||||
console.log(topics);
|
}, [topics]);
|
||||||
}, [topics.length]);
|
|
||||||
|
|
||||||
const scrollToBottom = () => {
|
const scrollToBottom = () => {
|
||||||
const topicsDiv = document.getElementById("topics-div");
|
const topicsDiv = document.getElementById("topics-div");
|
||||||
@@ -33,15 +32,28 @@ export function TopicList({ topics, useActiveTopic }: TopicListProps) {
|
|||||||
else topicsDiv.scrollTop = topicsDiv.scrollHeight;
|
else topicsDiv.scrollTop = topicsDiv.scrollHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleScroll = (e) => {
|
// scroll top is not rounded, heights are, so exact match won't work.
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#determine_if_an_element_has_been_totally_scrolled
|
||||||
|
const toggleScroll = (element) => {
|
||||||
const bottom =
|
const bottom =
|
||||||
e.target.scrollHeight - e.target.scrollTop === e.target.clientHeight;
|
Math.abs(
|
||||||
|
element.scrollHeight - element.clientHeight - element.scrollTop,
|
||||||
|
) < 2 || element.scrollHeight == element.clientHeight;
|
||||||
if (!bottom && autoscrollEnabled) {
|
if (!bottom && autoscrollEnabled) {
|
||||||
setAutoscrollEnabled(false);
|
setAutoscrollEnabled(false);
|
||||||
} else if (bottom && !autoscrollEnabled) {
|
} else if (bottom && !autoscrollEnabled) {
|
||||||
setAutoscrollEnabled(true);
|
setAutoscrollEnabled(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const handleScroll = (e) => {
|
||||||
|
toggleScroll(e.target);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const topicsDiv = document.getElementById("topics-div");
|
||||||
|
|
||||||
|
topicsDiv && toggleScroll(topicsDiv);
|
||||||
|
}, [activeTopic]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="relative w-full h-full bg-blue-400/20 rounded-lg md:rounded-xl px-2 md:px-4 flex flex-col justify-center align-center">
|
<section className="relative w-full h-full bg-blue-400/20 rounded-lg md:rounded-xl px-2 md:px-4 flex flex-col justify-center align-center">
|
||||||
@@ -60,7 +72,7 @@ export function TopicList({ topics, useActiveTopic }: TopicListProps) {
|
|||||||
{topics.map((topic, index) => (
|
{topics.map((topic, index) => (
|
||||||
<button
|
<button
|
||||||
key={index}
|
key={index}
|
||||||
className="rounded-none border-solid border-0 border-b-blue-300 border-b last:border-none p-2 hover:bg-blue-400/20 focus-visible:bg-blue-400/20 text-left block w-full"
|
className="rounded-none border-solid border-0 border-b-blue-300 border-b last:border-none last:rounded-b-lg p-2 hover:bg-blue-400/20 focus-visible:bg-blue-400/20 text-left block w-full"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setActiveTopic(activeTopic?.id == topic.id ? null : topic)
|
setActiveTopic(activeTopic?.id == topic.id ? null : topic)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,58 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
setFinalSummary({ summary: "This is the final summary" });
|
||||||
|
}
|
||||||
|
if (e.key === "z" && process.env.NEXT_PUBLIC_ENV === "development") {
|
||||||
|
setTranscriptText(
|
||||||
|
"This text is in English, and it is a pretty long sentence to test the limits",
|
||||||
|
);
|
||||||
|
setTopics([
|
||||||
|
{
|
||||||
|
id: "1",
|
||||||
|
timestamp: 10,
|
||||||
|
summary: "This is test topic 1",
|
||||||
|
title:
|
||||||
|
"Topic 1: Introduction to Quantum Mechanics, a brief overview of quantum mechanics and its principles.",
|
||||||
|
transcript:
|
||||||
|
"A brief overview of quantum mechanics and its principles.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "2",
|
||||||
|
timestamp: 20,
|
||||||
|
summary: "This is test topic 2",
|
||||||
|
title:
|
||||||
|
"Topic 2: Machine Learning Algorithms, understanding the different types of machine learning algorithms.",
|
||||||
|
transcript:
|
||||||
|
"Understanding the different types of machine learning algorithms.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "3",
|
||||||
|
timestamp: 30,
|
||||||
|
summary: "This is test topic 3",
|
||||||
|
title:
|
||||||
|
"Topic 3: Mental Health Awareness, ways to improve mental health and reduce stigma.",
|
||||||
|
transcript: "Ways to improve mental health and reduce stigma.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "4",
|
||||||
|
timestamp: 40,
|
||||||
|
summary: "This is test topic 4",
|
||||||
|
title:
|
||||||
|
"Topic 4: Basics of Productivity, tips and tricks to increase daily productivity.",
|
||||||
|
transcript: "Tips and tricks to increase daily productivity.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "5",
|
||||||
|
timestamp: 50,
|
||||||
|
summary: "This is test topic 5",
|
||||||
|
title:
|
||||||
|
"Topic 5: Future of Aviation, exploring the advancements and possibilities in aviation.",
|
||||||
|
transcript:
|
||||||
|
"Exploring the advancements and possibilities in aviation.",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
setFinalSummary({ summary: "This is the final summary" });
|
setFinalSummary({ summary: "This is the final summary" });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user