Skip to content

Commit

Permalink
feat: only show asset table when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Oct 15, 2023
1 parent 9997a74 commit f7241a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export function Popup() {
/>
<Form content={content} setContent={setContent} selectedContentKey={selectedContentKey} assets={assets} />
</div>
<AssetTable fetchingAssets={fetchingAssets} assets={assets} setAssets={setAssets} focusedAssetID={focusedAssetID} setFocusedAssetID={setFocusedAssetID} />
{assets.length > 0 && (
<AssetTable fetchingAssets={fetchingAssets} assets={assets} setAssets={setAssets} focusedAssetID={focusedAssetID} setFocusedAssetID={setFocusedAssetID} />
)}
</div>
);
}
23 changes: 16 additions & 7 deletions src/popup/hooks/useTransformFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,23 @@ export function useTransformFormat(
* Including all type of transformation of HTML, for preview
*/
const newContent = { ...contentReference.current };
if (options.toMd && newContent.html) {
const file = await html2mdParser.process(newContent.html);
const newMarkdown = String(file);
newContent.markdown = newMarkdown;
try {
if (options.toMd && newContent.html) {
// FIXME: Cannot handle unknown node `table`
const file = await html2mdParser.process(newContent.html);
const newMarkdown = String(file);
newContent.markdown = newMarkdown;
}
} catch (error) {
console.error(`html2md error ${(error as Error).message}`);
}
if (newContent.markdown && options.toTid) {
const newTid = await md2tid(newContent.markdown);
newContent.wikitext = newTid;
try {
if (newContent.markdown && options.toTid) {
const newTid = await md2tid(newContent.markdown);
newContent.wikitext = newTid;
}
} catch (error) {
console.error(`md2tid error ${(error as Error).message}`);
}
if (!isEqual(newContent, content)) {
setContent(newContent);
Expand Down

0 comments on commit f7241a4

Please sign in to comment.