Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple image upload #971

Merged
merged 12 commits into from
Apr 4, 2023
Prev Previous commit
Next Next commit
Did suggested PR changes
  • Loading branch information
SleeplessOne1917 committed Apr 1, 2023
commit e4e1d5581f3484b1b092ba0c1ce7ca4a26878ea7
27 changes: 12 additions & 15 deletions src/shared/components/common/markdown-textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ interface MarkdownTextAreaProps {
siteLanguages: number[]; // TODO same
}

type ImageUploadStatus = {
interface ImageUploadStatus {
total: number;
uploaded: number;
};
}

interface MarkdownTextAreaState {
content?: string;
languageId?: number;
previewMode: boolean;
loading: boolean;
imageUploadStatus: ImageUploadStatus | null;
imageUploadStatus?: ImageUploadStatus;
}

export class MarkdownTextArea extends Component<
Expand All @@ -72,7 +72,6 @@ export class MarkdownTextArea extends Component<
languageId: this.props.initialLanguageId,
previewMode: false,
loading: false,
imageUploadStatus: null,
};

constructor(props: any, context: any) {
Expand Down Expand Up @@ -150,7 +149,7 @@ export class MarkdownTextArea extends Component<
onInput={linkEvent(this, this.handleContentChange)}
onPaste={linkEvent(this, this.handleImageUploadPaste)}
required
disabled={this.getIsDisabled()}
disabled={this.isDisabled}
rows={2}
maxLength={this.props.maxLength ?? markdownFieldCharacterLimit}
placeholder={this.props.placeholder}
Expand Down Expand Up @@ -186,7 +185,7 @@ export class MarkdownTextArea extends Component<
<button
type="submit"
className="btn btn-sm btn-secondary mr-2"
disabled={this.getIsDisabled()}
disabled={this.isDisabled}
>
{this.state.loading ? (
<Spinner />
Expand Down Expand Up @@ -226,15 +225,15 @@ export class MarkdownTextArea extends Component<
}
siteLanguages={this.props.siteLanguages}
onChange={this.handleLanguageChange}
disabled={this.getIsDisabled()}
disabled={this.isDisabled}
/>
)}
{this.getFormatButton("bold", this.handleInsertBold)}
{this.getFormatButton("italic", this.handleInsertItalic)}
{this.getFormatButton("link", this.handleInsertLink)}
<EmojiPicker
onEmojiClick={e => this.handleEmoji(this, e)}
disabled={this.getIsDisabled()}
disabled={this.isDisabled}
></EmojiPicker>
<form className="btn btn-sm text-muted font-weight-bold">
<label
Expand All @@ -257,9 +256,7 @@ export class MarkdownTextArea extends Component<
name="file"
className="d-none"
multiple
disabled={
!UserService.Instance.myUserInfo || this.getIsDisabled()
}
disabled={!UserService.Instance.myUserInfo || this.isDisabled}
onChange={linkEvent(this, this.handleImageUpload)}
/>
</form>
Expand Down Expand Up @@ -314,7 +311,7 @@ export class MarkdownTextArea extends Component<
data-tippy-content={i18n.t(type)}
aria-label={i18n.t(type)}
onClick={linkEvent(this, handleClick)}
disabled={this.getIsDisabled()}
disabled={this.isDisabled}
>
<Icon icon={iconType} classes="icon-inline" />
</button>
Expand Down Expand Up @@ -367,7 +364,7 @@ export class MarkdownTextArea extends Component<
});

i.uploadImages(i, files).then(() => {
i.setState({ imageUploadStatus: null });
i.setState({ imageUploadStatus: undefined });
});
}
}
Expand Down Expand Up @@ -413,7 +410,7 @@ export class MarkdownTextArea extends Component<
throw JSON.stringify(res);
}
} catch (error) {
i.setState({ imageUploadStatus: null });
i.setState({ imageUploadStatus: undefined });
console.error(error);
toast(error, "danger");

Expand Down Expand Up @@ -646,7 +643,7 @@ export class MarkdownTextArea extends Component<
return start !== end ? this.state.content?.substring(start, end) ?? "" : "";
}

getIsDisabled() {
get isDisabled() {
return (
this.state.loading ||
this.props.disabled ||
Expand Down
4 changes: 2 additions & 2 deletions src/shared/components/common/progress-bar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classNames from "classnames";
import { ThemeColor } from "shared/utils";

type ProgressBarProps = {
interface ProgressBarProps {
className?: string;
backgroundColor?: ThemeColor;
barColor?: ThemeColor;
Expand All @@ -11,7 +11,7 @@ type ProgressBarProps = {
max?: number;
value: number;
text?: string;
};
}

const ProgressBar = ({
value,
Expand Down