Skip to content

Commit 2447b18

Browse files
committed
Update UI as a test
1 parent f26eeb4 commit 2447b18

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/frontend/index.jsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1-
import React, { useEffect, useState } from 'react';
2-
import ForgeReconciler, { Text } from '@forge/react';
3-
import { invoke } from '@forge/bridge';
1+
import React, { useEffect, useState } from "react";
2+
import ForgeReconciler, { Text, useProductContext } from "@forge/react";
3+
import { requestJira } from "@forge/bridge";
44

55
const App = () => {
6-
const [data, setData] = useState(null);
6+
const context = useProductContext();
7+
const [comments, setComments] = useState();
8+
console.log(`Number of comments on this issue: ${comments?.length}`);
9+
10+
const fetchCommentsForIssue = async (issueIdOrKey) => {
11+
const res = await requestJira(`/rest/api/3/issue/${issueIdOrKey}/comment`);
12+
const data = await res.json();
13+
return data.comments;
14+
};
15+
16+
// This is a test of the requestJira function
717
useEffect(() => {
8-
invoke('getText', { example: 'my-invoke-variable' }).then(setData);
9-
}, []);
18+
if (context) {
19+
const issueId = context.extension.issue.id;
20+
fetchCommentsForIssue(issueId).then(setComments);
21+
}
22+
}, [context]);
23+
1024
return (
1125
<>
1226
<Text>Hello world!</Text>
13-
<Text>{data ? data : 'Loading...'}</Text>
27+
<Text>Number of comments on this issue: {comments?.length}</Text>
1428
</>
1529
);
1630
};

0 commit comments

Comments
 (0)