Skip to content

Commit b5cb3ce

Browse files
committed
Add function to edit displaynames
1 parent 0b0fb74 commit b5cb3ce

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

src/app.jsx

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { OverlayPanel } from 'primereact/overlaypanel'
3737
import { MultiSelect } from 'primereact/multiselect'
3838
import { DataTable } from 'primereact/datatable'
3939
import { Column } from 'primereact/column'
40+
import { Chips } from 'primereact/chips'
4041
// eslint-disable-next-line camelcase
4142
import jwt_decode from 'jwt-decode'
4243
import axios from 'axios'
@@ -2073,6 +2074,7 @@ class App extends Component {
20732074
let joinlecture = false
20742075
let cloudstatus = false
20752076
let startlecture = false
2077+
let editlecturers = false
20762078
let pictures = false
20772079
let pastlectures = false
20782080
let polls = false
@@ -2104,7 +2106,10 @@ class App extends Component {
21042106
if (lectdetail) {
21052107
if (lectdetail.title) lecturename = lectdetail.title
21062108
if (lectdetail.coursetitle) coursename = lectdetail.coursetitle
2107-
if (lectdetail.ownersdisplaynames)
2109+
if (
2110+
lectdetail.ownersdisplaynames &&
2111+
lectdetail.ownersdisplaynames.length > 0
2112+
)
21082113
displaynames = lectdetail.ownersdisplaynames.join(', ')
21092114
if (lectdetail.running) running = true
21102115
if (lectdetail.pictures) {
@@ -2203,6 +2208,7 @@ class App extends Component {
22032208
}
22042209
if (this.state.decodedtoken.role.includes('instructor')) {
22052210
startlecture = true
2211+
editlecturers = true
22062212
if (this.state.lectures && this.state.lectures.length > 1)
22072213
pastlectures = true
22082214
polls = true
@@ -2349,7 +2355,63 @@ class App extends Component {
23492355
<div className='p-col'>
23502356
<h2 style={{ margin: '4px 0' }}>Course: {coursename}</h2>
23512357
<h3 style={{ margin: '2px 0' }}>Lecture: {lecturename}</h3>
2352-
<h4 style={{ margin: '2px 0' }}>{displaynames}</h4>
2358+
<h4 style={{ margin: '2px 0' }}>
2359+
{this.state.editDisplaynames ? (
2360+
<Fragment>
2361+
<Chips
2362+
value={this.state.editDisplaynames}
2363+
onChange={({ value }) => {
2364+
if (
2365+
value?.length >= 1 &&
2366+
value?.includes?.(displayname)
2367+
) {
2368+
this.setState({ editDisplaynames: value })
2369+
}
2370+
}}
2371+
/>
2372+
<Button
2373+
icon='pi pi-save'
2374+
className='p-button-text p-button-sm'
2375+
iconPos='right'
2376+
tooltip='Save lecturer names'
2377+
onClick={async () => {
2378+
this.patchLectureDetails({
2379+
editDisplaynames: this.state.editDisplaynames
2380+
})
2381+
this.setState({ editDisplaynames: undefined })
2382+
}}
2383+
/>
2384+
<Button
2385+
icon='pi pi-times'
2386+
className='p-button-text p-button-sm'
2387+
iconPos='right'
2388+
tooltip='Cancel edit'
2389+
onClick={async () => {
2390+
this.setState({ editDisplaynames: undefined })
2391+
}}
2392+
/>
2393+
</Fragment>
2394+
) : (
2395+
<Fragment>
2396+
{' '}
2397+
{displaynames}{' '}
2398+
{editlecturers &&
2399+
lectdetail.ownersdisplaynames?.length > 1 && (
2400+
<Button
2401+
icon='pi pi-pencil'
2402+
className='p-button-text p-button-sm'
2403+
iconPos='right'
2404+
tooltip={'Edit lecturers'}
2405+
onClick={() => {
2406+
this.setState({
2407+
editDisplaynames: lectdetail.ownersdisplaynames
2408+
})
2409+
}}
2410+
/>
2411+
)}
2412+
</Fragment>
2413+
)}
2414+
</h4>
23532415
<br></br>
23542416
<h4 style={{ margin: '2px 0' }}>Hello {displayname}!</h4>
23552417
</div>

0 commit comments

Comments
 (0)