-
Notifications
You must be signed in to change notification settings - Fork 170
Description
Hi guys, so I've been experiencing an issue with local transcripts and hope you could help me understand a bit more what could be happening and if my approach is correct.
My previously edited local transcripts weren't loading, (due to the fact my mediaUrls contains a session signature appended to it which change periodically). After searching for localStorage load/save methods and updating this.props.mediaUrl to this.props.fileName, things still didn't work, unless I also update the componentDidUpdate lifecyle under TranscriptEditor.
Once I also updated prevProps.mediaUrl within this method my local transcripts started loading successfully. The problem then is that every time I started editing a transcript, the cursor started jumping to the beginning of the editor, and I could see in the console these repeated messages:
Transcript first and then media
was already present in local storage...
as the method keeps updating/executing it seems to be checking if the transcript is available locally - so I'm not understanding the purpose of why this code is under the componentDidUpdate method (or purpose of it, and the repetition under different conditions).
componentDidUpdate(prevProps, prevState) {
// Transcript and media passed to component at same time
if (
(prevState.transcriptData !== this.state.transcriptData)
&& (prevProps.mediaUrl !== this.props.fileName )
) {
console.info('Transcript and media');
this.ifPresentRetrieveTranscriptFromLocalStorage();
}
// Transcript first and then media passed to component
else if (
(prevState.transcriptData === this.state.transcriptData)
&& (prevProps.mediaUrl !== this.props.mediaUrl)
) {
console.info('Transcript first and then media');
this.ifPresentRetrieveTranscriptFromLocalStorage();
}
// Media first and then transcript passed to component
else if (
(prevState.transcriptData !== this.state.transcriptData)
&& (prevProps.mediaUrl === this.props.fileName)
) {
console.info('Media first and then transcript');
this.ifPresentRetrieveTranscriptFromLocalStorage();
}
}don't know if these same changes (from mediaUrl -> fileName) caused an unexpected behaviour, but having this check running on every single update doesn't seem right.
I've already applied a solution to the issue by running the isPresentInLocalStorage method once during the componentDidMount lifecyle method instead, and I can edit my transcripts without hiccups. But I'm not sure if I'm missing something that you guys had in mind with the above code.
Don't know if this could be a section we could improve - and if there's scope also to provide an alternative prop to be used as title for localStorage as well.
Thanks!