-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch to resouce-based loading process.
this realigns this component with Program::LeadershipExpanded.
- Loading branch information
1 parent
a67e39a
commit e135037
Showing
2 changed files
with
36 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 34 additions & 20 deletions
54
packages/frontend/app/components/program-year/leadership-expanded.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,62 @@ | ||
import Component from '@glimmer/component'; | ||
import { dropTask, timeout } from 'ember-concurrency'; | ||
import { dropTask } from 'ember-concurrency'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { TrackedAsyncData } from 'ember-async-data'; | ||
import { cached } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
|
||
export default class ProgramYearLeadershipExpandedComponent extends Component { | ||
@tracked directors = []; | ||
@tracked directorsToAdd = []; | ||
@tracked directorsToRemove = []; | ||
|
||
@cached | ||
get count() { | ||
return this.directors.length; | ||
} | ||
|
||
@cached | ||
get programYearDirectors() { | ||
return new TrackedAsyncData(this.args.programYear.directors); | ||
} | ||
|
||
@cached | ||
get directors() { | ||
const directors = this.programYearDirectors.isResolved | ||
? this.programYearDirectors.value.slice() | ||
: []; | ||
return [...directors, ...this.directorsToAdd].filter( | ||
(user) => !this.directorsToRemove.includes(user), | ||
); | ||
} | ||
|
||
resetBuffers() { | ||
this.directorsToAdd = []; | ||
this.directorsToRemove = []; | ||
} | ||
|
||
@action | ||
addDirector(user) { | ||
this.directors = [...this.directors, user]; | ||
this.directorsToAdd = [...this.directorsToAdd, user]; | ||
this.directorsToRemove = this.directorsToRemove.filter((d) => d !== user); | ||
} | ||
|
||
@action | ||
removeDirector(user) { | ||
this.directors = this.directors.filter((obj) => obj !== user); | ||
this.directorsToRemove = [...this.directorsToRemove, user]; | ||
this.directorsToAdd = this.directorsToAdd.filter((d) => d !== user); | ||
} | ||
|
||
@action | ||
manage() { | ||
this.args.setIsManaging(true); | ||
} | ||
|
||
async setBuffers() { | ||
this.directors = (await this.args.programYear.directors).slice(); | ||
close() { | ||
this.resetBuffers(); | ||
this.args.setIsManaging(false); | ||
} | ||
|
||
load = dropTask(async () => { | ||
await this.setBuffers(); | ||
}); | ||
|
||
save = dropTask(async () => { | ||
await timeout(10); | ||
this.args.programYear.set('directors', this.directors); | ||
this.args.expand(); | ||
this.resetBuffers(); | ||
await this.args.programYear.save(); | ||
this.args.setIsManaging(false); | ||
}); | ||
|
||
cancel = dropTask(async () => { | ||
await this.setBuffers(); | ||
this.args.setIsManaging(false); | ||
}); | ||
} |