Skip to content

Commit

Permalink
feat: problem content hide empty section
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamerblue committed Jan 31, 2024
1 parent b748a3a commit 5786559
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/common
21 changes: 15 additions & 6 deletions src/components/ProblemContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ class ProblemContent extends React.Component<Props, State> {
});
};

simpleFilterHTML = (html: string) => {
let res = (html || '').replace(/^&nbsp;/, '').trim();
if (res === '<p></p>') {
res = '';
}
return res;
};

renderContent = (html: string) => {
return (
<div style={this.getFontStyle()}>
Expand Down Expand Up @@ -119,10 +127,10 @@ class ProblemContent extends React.Component<Props, State> {
}

const spConfig = (data.spConfig || {}) as IProblemSpConfig;
const description = (data.description || '').replace(/^&nbsp;/, '');
const input = (data.input || '').replace(/^&nbsp;/, '');
const output = (data.output || '').replace(/^&nbsp;/, '');
const hint = (data.hint || '').replace(/^&nbsp;/, '');
const description = this.simpleFilterHTML(data.description);
const input = this.simpleFilterHTML(data.input || '');
const output = this.simpleFilterHTML(data.output || '');
const hint = this.simpleFilterHTML(data.hint || '');
const titlePrefix =
typeof problemAlias === 'string'
? `${problemAlias} - `
Expand All @@ -132,7 +140,8 @@ class ProblemContent extends React.Component<Props, State> {

const audioConf = spConfig.onEnteredAudio;
const urls = audioConf?.urls || [];
const toUseOnEnteredAudioUrl = audioConf?.playMode === 'random' ? randomlyPickOne(urls) : urls[0];
const toUseOnEnteredAudioUrl =
audioConf?.playMode === 'random' ? randomlyPickOne(urls) : urls[0];

return (
<div
Expand Down Expand Up @@ -175,7 +184,7 @@ class ProblemContent extends React.Component<Props, State> {
</>
)}

{data.samples && (
{data.samples?.length > 0 && (
<>
<h3>Samples</h3>
{data.samples.map((sample, index) => (
Expand Down

0 comments on commit 5786559

Please sign in to comment.