From c1df53a7616ccbb9afad2deaf3026e70f3e974b4 Mon Sep 17 00:00:00 2001 From: Sophie Zhang Date: Tue, 11 Jul 2023 13:30:51 -0400 Subject: starting connecting to new upload endpoint and standardized displaying media --- src/client/Network.ts | 2 +- src/client/util/reportManager/ReportManager.tsx | 75 +++++----- .../util/reportManager/ReportManagerComponents.tsx | 162 +++++++++++++++------ .../util/reportManager/reportManagerSchema.ts | 2 +- .../util/reportManager/reportManagerUtils.ts | 4 +- 5 files changed, 161 insertions(+), 84 deletions(-) (limited to 'src') diff --git a/src/client/Network.ts b/src/client/Network.ts index eb827e0c8..70b51d036 100644 --- a/src/client/Network.ts +++ b/src/client/Network.ts @@ -68,7 +68,7 @@ export namespace Networking { body: formData, }; - const endpoint = '/uploadFormData'; + const endpoint = browndash ? 'http://10.38.71.246:1050/uploadFormData' : '/uploadFormData'; const response = await fetch(endpoint, parameters); return response.json(); } diff --git a/src/client/util/reportManager/ReportManager.tsx b/src/client/util/reportManager/ReportManager.tsx index ff17a5097..d091e2a34 100644 --- a/src/client/util/reportManager/ReportManager.tsx +++ b/src/client/util/reportManager/ReportManager.tsx @@ -164,11 +164,11 @@ export class ReportManager extends React.Component<{}> { this.setSubmitting(true); const links = await this.uploadFilesToServer(); + console.log(links); if (!links) { // error uploading files to the server return; } - console.log(links); const formattedLinks = (links ?? []).map(this.fileLinktoServerLink); // const req = await this.octokit.request('POST /repos/{owner}/{repo}/issues', { @@ -252,12 +252,43 @@ export class ReportManager extends React.Component<{}> { /** * Handles file upload. + * * @param files uploaded files */ private onDrop = (files: File[]) => { this.setMediaFiles([...this.mediaFiles, ...files.map(file => ({ _id: v4(), file }))]); }; + /** + * Returns when the issue passes the current filters. + * + * @param issue issue to check + * @returns boolean indicating whether the issue passes the current filters + */ + private passesTagFilter = (issue: Issue) => { + let passesPriority = true; + let passesBug = true; + if (this.priorityFilter) { + passesPriority = issue.labels.some(label => { + if (typeof label === 'string') { + return label === this.priorityFilter; + } else { + return label.name === this.priorityFilter; + } + }); + } + if (this.bugFilter) { + passesBug = issue.labels.some(label => { + if (typeof label === 'string') { + return label === this.bugFilter; + } else { + return label.name === this.bugFilter; + } + }); + } + return passesPriority && passesBug; + }; + /** * Gets a JSX element to render a media preview * @param fileData file data @@ -306,30 +337,6 @@ export class ReportManager extends React.Component<{}> { return <>; }; - private passesTagFilter = (issue: Issue) => { - let passesPriority = true; - let passesBug = true; - if (this.priorityFilter) { - passesPriority = issue.labels.some(label => { - if (typeof label === 'string') { - return label === this.priorityFilter; - } else { - return label.name === this.priorityFilter; - } - }); - } - if (this.bugFilter) { - passesBug = issue.labels.some(label => { - if (typeof label === 'string') { - return label === this.bugFilter; - } else { - return label.name === this.bugFilter; - } - }); - } - return passesPriority && passesBug; - }; - /** * @returns the component that dispays all issues */ @@ -487,26 +494,26 @@ export class ReportManager extends React.Component<{}> { - - - - - (this.bugPriority = e.target.value)}> - - - + + + { this.reportIssue(); }}> Submit - {this.submitting && } + {this.submitting && } diff --git a/src/client/util/reportManager/ReportManagerComponents.tsx b/src/client/util/reportManager/ReportManagerComponents.tsx index 1a4ddb3a3..21c0cb43c 100644 --- a/src/client/util/reportManager/ReportManagerComponents.tsx +++ b/src/client/util/reportManager/ReportManagerComponents.tsx @@ -5,12 +5,16 @@ import ReactMarkdown from 'react-markdown'; import rehypeRaw from 'rehype-raw'; import remarkGfm from 'remark-gfm'; -// Mini components to render issues +/** + * Mini components to render issues. + */ interface IssueCardProps { issue: Issue; onSelect: () => void; } + +// Component for the issue cards list on the left export const IssueCard = ({ issue, onSelect }: IssueCardProps) => { return (
@@ -33,62 +37,25 @@ interface IssueViewProps { issue: Issue; } +// Detailed issue view that displays on the right export const IssueView = ({ issue }: IssueViewProps) => { const [issueBody, setIssueBody] = React.useState(''); - const isVideoValid = (src: string) => { - const videoElement = document.createElement('video'); - const validPromise: Promise = new Promise(resolve => { - videoElement.addEventListener('loadeddata', () => resolve(true)); - videoElement.addEventListener('error', () => resolve(false)); - }); - videoElement.src = src; - return validPromise; - }; - - const getLinkFromTag = async (tag: string) => { - const regex = /src="([^"]+)"/; - let url = ''; - const match = tag.match(regex); - if (match) { - url = match[1]; - } - - if (url.startsWith('https://github.com/brown-dash/Dash-Web/assets')) { - return `\n${url} (Not authorized to display image here)`; - } - return await getTagFromUrl(url); - }; - - const getTagFromUrl = async (url: string) => { - const imgRegex = /https:\/\/browndash\.com\/files[/\\]images/; - const videoRegex = /https:\/\/browndash\.com\/files[/\\]videos/; - const audioRegex = /https:\/\/browndash\.com\/files[/\\]audio/; - - if (imgRegex.test(url) || url.includes('user-images.githubusercontent.com')) { - return `\n${url}\nIssue asset\n`; - } else if (videoRegex.test(url)) { - const videoValid = await isVideoValid(url); - if (!videoValid) return `\n${url} (This video could not be loaded)\n`; - return `\n${url}\n