fix metadata crash #720

also useMemo to improve performance
pull/841/head
Mikael Finstad 2021-08-24 19:43:39 +07:00
rodzic 662ff44d83
commit 3e6730e00f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 25AB36E3E81CBC26
1 zmienionych plików z 7 dodań i 6 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
import React, { memo, useState } from 'react'; import React, { memo, useState, useMemo } from 'react';
import { FaVideo, FaVideoSlash, FaFileExport, FaFileImport, FaVolumeUp, FaVolumeMute, FaBan, FaTrashAlt, FaInfoCircle } from 'react-icons/fa'; import { FaVideo, FaVideoSlash, FaFileExport, FaFileImport, FaVolumeUp, FaVolumeMute, FaBan, FaTrashAlt, FaInfoCircle } from 'react-icons/fa';
import { GoFileBinary } from 'react-icons/go'; import { GoFileBinary } from 'react-icons/go';
@ -96,7 +96,7 @@ const TagEditor = memo(({ existingTags, customTags, onTagChange, onTagReset }) =
const EditFileDialog = memo(({ editingFile, externalFiles, mainFileFormatData, mainFilePath, customTagsByFile, setCustomTagsByFile }) => { const EditFileDialog = memo(({ editingFile, externalFiles, mainFileFormatData, mainFilePath, customTagsByFile, setCustomTagsByFile }) => {
const formatData = editingFile === mainFilePath ? mainFileFormatData : externalFiles[editingFile].formatData; const formatData = editingFile === mainFilePath ? mainFileFormatData : externalFiles[editingFile].formatData;
const existingTags = formatData.tags; const existingTags = formatData.tags || {};
const customTags = customTagsByFile[editingFile] || {}; const customTags = customTagsByFile[editingFile] || {};
function onTagChange(tag, value) { function onTagChange(tag, value) {
@ -115,11 +115,10 @@ const EditFileDialog = memo(({ editingFile, externalFiles, mainFileFormatData, m
const EditStreamDialog = memo(({ editingStream: { streamId: editingStreamId, path: editingFile }, externalFiles, mainFilePath, mainFileStreams, customTagsByStreamId, setCustomTagsByStreamId }) => { const EditStreamDialog = memo(({ editingStream: { streamId: editingStreamId, path: editingFile }, externalFiles, mainFilePath, mainFileStreams, customTagsByStreamId, setCustomTagsByStreamId }) => {
const streams = editingFile === mainFilePath ? mainFileStreams : externalFiles[editingFile].streams; const streams = editingFile === mainFilePath ? mainFileStreams : externalFiles[editingFile].streams;
const stream = streams.find((s) => s.index === editingStreamId); const stream = useMemo(() => streams.find((s) => s.index === editingStreamId), [streams, editingStreamId]);
if (!stream) return null;
const existingTags = stream.tags; const existingTags = useMemo(() => (stream && stream.tags) || {}, [stream]);
const customTags = (customTagsByStreamId[editingFile] || {})[editingStreamId] || {}; const customTags = useMemo(() => (customTagsByStreamId[editingFile] || {})[editingStreamId] || {}, [customTagsByStreamId, editingFile, editingStreamId]);
// This is deep! // This is deep!
function onTagChange(tag, value) { function onTagChange(tag, value) {
@ -149,6 +148,8 @@ const EditStreamDialog = memo(({ editingStream: { streamId: editingStreamId, pat
}); });
} }
if (!stream) return null;
return <TagEditor existingTags={existingTags} customTags={customTags} onTagChange={onTagChange} onTagReset={onTagReset} />; return <TagEditor existingTags={existingTags} customTags={customTags} onTagChange={onTagChange} onTagReset={onTagReset} />;
}); });