-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Application freezing but when moving dialog to bin (#1352)
* fix: Application freezing but when moving dialog to bin * Updated according to PR comments * Fixed linting * Fixed linting
- Loading branch information
1 parent
efba0f5
commit 532f2df
Showing
4 changed files
with
30 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 22 additions & 23 deletions
45
packages/frontend/src/components/MainContentReference/MainContentReference.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,38 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { Html, Markdown } from 'embeddable-markdown-html'; | ||
import { memo } from 'react'; | ||
import { type DialogByIdDetails, EmbeddableMediaType } from '../../api/useDialogById.tsx'; | ||
import { QUERY_KEYS } from '../../constants/queryKeys.ts'; | ||
import styles from './mainContentReference.module.css'; | ||
|
||
const getContent = (mediaType: EmbeddableMediaType, data: string) => { | ||
switch (mediaType) { | ||
case EmbeddableMediaType.markdown: | ||
return <Markdown>{data}</Markdown>; | ||
return <Markdown onError={(e) => console.error('Markdown error: ', e)}>{data}</Markdown>; | ||
case EmbeddableMediaType.html: | ||
return <Html>{data}</Html>; | ||
return <Html onError={(e) => console.error('Html error: ', e)}>{data}</Html>; | ||
default: | ||
return data; | ||
} | ||
}; | ||
|
||
export const MainContentReference = ({ | ||
content, | ||
dialogToken, | ||
}: { content: DialogByIdDetails['mainContentReference']; dialogToken: string }) => { | ||
const { data, isSuccess } = useQuery({ | ||
queryKey: [QUERY_KEYS.MAIN_CONTENT_REFERENCE, content?.url, content?.mediaType], | ||
queryFn: () => | ||
fetch(content!.url, { | ||
headers: { | ||
'Content-Type': 'text/plain', | ||
Authorization: `Bearer ${dialogToken}`, | ||
}, | ||
}).then((res) => res.text()), | ||
enabled: content?.url !== undefined && Object.values(EmbeddableMediaType).includes(content.mediaType), | ||
}); | ||
export const MainContentReference = memo( | ||
({ content, dialogToken }: { content: DialogByIdDetails['mainContentReference']; dialogToken: string }) => { | ||
const { data, isSuccess } = useQuery({ | ||
queryKey: [QUERY_KEYS.MAIN_CONTENT_REFERENCE, content?.url, content?.mediaType], | ||
queryFn: () => | ||
fetch(content!.url, { | ||
headers: { | ||
'Content-Type': 'text/plain', | ||
Authorization: `Bearer ${dialogToken}`, | ||
}, | ||
}).then((res) => res.text()), | ||
enabled: content?.url !== undefined && Object.values(EmbeddableMediaType).includes(content.mediaType), | ||
}); | ||
|
||
if (!content || !isSuccess) { | ||
return null; | ||
} | ||
|
||
return <section className={styles.mainContentReference}>{getContent(content.mediaType, data)}</section>; | ||
}; | ||
if (!content || !isSuccess) { | ||
return null; | ||
} | ||
return <section className={styles.mainContentReference}>{getContent(content.mediaType, data)}</section>; | ||
}, | ||
); |