review fixes

This commit is contained in:
Sara
2024-01-09 15:41:16 +01:00
parent 673f5d7cbd
commit b70ff46c72
3 changed files with 52 additions and 33 deletions

View File

@@ -78,13 +78,16 @@ const TopicPlayer = ({
setEndTopicCallback( setEndTopicCallback(
() => () =>
function () { function () {
if (!topicTime) return; if (
if (mp3.media && mp3.media.currentTime >= topicTime.end) { !topicTime ||
mp3.media.pause(); !mp3.media ||
setIsPlaying(false); !(mp3.media.currentTime >= topicTime.end)
mp3.media.currentTime = topicTime.start; )
calcShowTime(); return;
} mp3.media.pause();
setIsPlaying(false);
mp3.media.currentTime = topicTime.start;
calcShowTime();
}, },
); );
if (mp3.media) { if (mp3.media) {

View File

@@ -28,22 +28,39 @@ const topicWords = ({
}, [topicWithWords.loading]); }, [topicWithWords.loading]);
const getStartTimeFromFirstNode = (node, offset, reverse) => { const getStartTimeFromFirstNode = (node, offset, reverse) => {
// if the first element is a word // Check if the current node represents a word with a start time
return node.parentElement?.dataset["start"] if (node.parentElement?.dataset["start"]) {
? // but after of the word (like on the blank space right of the word) // Check if the position is at the end of the word
node.textContent?.length == offset if (node.textContent?.length == offset) {
? // if next element is a word, we need the start of it // Try to get the start time of the next word
(node.parentElement?.nextElementSibling as any)?.dataset?.["start"] || const nextWordStartTime =
// otherwise we get the start of the first word of the next paragraph node.parentElement.nextElementSibling?.dataset["start"];
( if (nextWordStartTime) {
node.parentElement?.parentElement?.nextElementSibling return nextWordStartTime;
?.childNodes[1] as any }
)?.dataset?.["start"] ||
(reverse ? 0 : 99) // If no next word, get start of the first word in the next paragraph
: // otherwise it's just somewhere in the word and we get the start of the word const nextParaFirstWordStartTime =
node.parentElement?.dataset["start"] node.parentElement.parentElement.nextElementSibling?.childNodes[1]
: // otherwise selection start is on a name and we get the start of the next word ?.dataset["start"];
(node.parentElement?.nextElementSibling as any)?.dataset["start"]; if (nextParaFirstWordStartTime) {
return nextParaFirstWordStartTime;
}
// Return default values based on 'reverse' flag
// If reverse is false, means the node is the last word of the topic transcript,
// so reverse should be true, and we set a high value to make sure this is not picked as the start time.
// Reverse being true never happens given how we use this function, but for consistency in case things change,
// we set a low value.
return reverse ? 0 : 9999999999999;
} else {
// Position is within the word, return start of this word
return node.parentElement.dataset["start"];
}
} else {
// Selection is on a name, return start of the next word
return node.parentElement.nextElementSibling?.dataset["start"];
}
}; };
const onMouseUp = (e) => { const onMouseUp = (e) => {
@@ -83,7 +100,6 @@ const topicWords = ({
? parseInt(focusNode.parentElement?.dataset["speaker"]) ? parseInt(focusNode.parentElement?.dataset["speaker"])
: undefined, : undefined,
); );
console.log("Unset Time : selected Speaker");
return; return;
} }
@@ -107,11 +123,12 @@ const topicWords = ({
const reverse = parseFloat(anchorStart) >= parseFloat(focusEnd); const reverse = parseFloat(anchorStart) >= parseFloat(focusEnd);
if (!reverse) { if (!reverse) {
setSelectedText({ anchorStart &&
start: parseFloat(anchorStart), focusEnd &&
end: parseFloat(focusEnd), setSelectedText({
}); start: parseFloat(anchorStart),
console.log("setting right"); end: parseFloat(focusEnd),
});
} else { } else {
const anchorEnd = const anchorEnd =
anchorNode.parentElement?.dataset["end"] || anchorNode.parentElement?.dataset["end"] ||
@@ -130,7 +147,6 @@ const topicWords = ({
start: parseFloat(focusStart), start: parseFloat(focusStart),
end: parseFloat(anchorEnd), end: parseFloat(anchorEnd),
}); });
console.log("setting reverse");
} }
} }
selection && selection.empty(); selection && selection.empty();
@@ -144,7 +160,6 @@ const topicWords = ({
)?.name || `Speaker ${speakerNumber}` )?.name || `Speaker ${speakerNumber}`
); );
}; };
if ( if (
!topicWithWords.loading && !topicWithWords.loading &&
topicWithWords.response && topicWithWords.response &&
@@ -199,7 +214,6 @@ const topicWords = ({
} }
if (topicWithWords.loading || participants.loading) if (topicWithWords.loading || participants.loading)
return <Spinner size="xl" margin="auto" />; return <Spinner size="xl" margin="auto" />;
if (topicWithWords.error || participants.error) return <p>error</p>;
return null; return null;
}; };

View File

@@ -13,7 +13,7 @@ type ErrorParticipants = {
type LoadingParticipants = { type LoadingParticipants = {
response: Participant[] | null; response: Participant[] | null;
loading: true; loading: true;
error: false; error: null;
}; };
type SuccessParticipants = { type SuccessParticipants = {
@@ -63,6 +63,8 @@ const useParticipants = (transcriptId: string): UseParticipants => {
setError(error); setError(error);
} }
setErrorState(error); setErrorState(error);
setResponse(null);
setLoading(false);
}); });
}, [transcriptId, !api, count]); }, [transcriptId, !api, count]);