From 8c5c932c8ba6fd1797ef5e8123fcb59049b5dadd Mon Sep 17 00:00:00 2001 From: Michael Foiani Date: Thu, 4 Aug 2022 14:52:12 -0400 Subject: add way to view the issues and search them (but with poor styling) --- src/client/util/ReportManager.tsx | 63 ++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/client/util/ReportManager.tsx b/src/client/util/ReportManager.tsx index 128d58d88..7d8f02bb8 100644 --- a/src/client/util/ReportManager.tsx +++ b/src/client/util/ReportManager.tsx @@ -29,25 +29,65 @@ export class ReportManager extends React.Component<{}> { private octokit: Octokit; + public issues: any[] = []; + + @observable public shownIssues = this.issues.filter(issue => issue.state === 'open'); + + public updateIssueSearch = action((query: string = '') => { + if (query === '') { + this.shownIssues = this.issues.filter(issue => issue.state === 'open'); + return; + } + this.shownIssues = this.issues.filter(issue => issue.title.toLowerCase().includes(query.toLowerCase())); + }); + constructor(props: {}) { super(props); ReportManager.Instance = this; this.octokit = new Octokit({ - auth: 'auth key' + auth: 'key' }); } public close = action(() => (this.isOpen = false)); - public open = action(() => (this.isOpen = true)); + public open = action(() => { + if (this.issues.length === 0) { + // load in the issues if not already loaded + this.getAllIssues() + .then(issues => { + this.issues = issues + this.updateIssueSearch(); + }) + .catch(err => console.log(err)); + } + (this.isOpen = true) + }); private bugTitle = ''; private bugDescription = ''; - private toGithub = false; + + // private toGithub = false; + // will always be set to true - no alterntive option yet + private toGithub = true; private formatTitle = (title: string, userEmail: string) => `${title} - ${userEmail.replace('@brown.edu', '')}`; - public async reportBug() { + public async getAllIssues() : Promise { + const res = await this.octokit.request('GET /repos/{owner}/{repo}/issues', { + owner: 'brown-dash', + repo: 'Dash-Web', + }); + + // 200 status means success + if (res.status === 200) { + return res.data; + } else { + throw new Error('Error getting issues'); + } + } + + public async reportIssue() { if (this.toGithub) { const req = await this.octokit.request('POST /repos/{owner}/{repo}/issues', { owner: 'brown-dash', @@ -81,6 +121,15 @@ export class ReportManager extends React.Component<{}> { return (
+
+ this.updateIssueSearch(e.target.value))}> +

Previous Issues

+ {this.shownIssues.map(issue =>
{issue.title}
)} + +
+ +
+
@@ -93,10 +142,10 @@ export class ReportManager extends React.Component<{}> {