| 53 | |
| 54 | @singleton() |
| 55 | export class ProblemsService |
| 56 | extends Component<IProblems> |
| 57 | implements IProblemsService |
| 58 | { |
| 59 | protected state: IProblems; |
| 60 | private readonly statusBarService: IStatusBarService; |
| 61 | private readonly builtinService: IBuiltinService; |
| 62 | constructor() { |
| 63 | super(); |
| 64 | this.state = container.resolve(ProblemsModel); |
| 65 | this.statusBarService = container.resolve(StatusBarService); |
| 66 | this.builtinService = container.resolve(BuiltinService); |
| 67 | } |
| 68 | |
| 69 | public toggleProblems(): void { |
| 70 | this.setState({ |
| 71 | ...this.state, |
| 72 | show: !this.state.show, |
| 73 | }); |
| 74 | } |
| 75 | public add<T>(item: IProblemsItem<T> | IProblemsItem<T>[]): void { |
| 76 | const problems = Array.isArray(item) ? item : [item]; |
| 77 | const { data } = this.state; |
| 78 | |
| 79 | problems.forEach((problem) => { |
| 80 | const index = data.findIndex(searchById(problem.id)); |
| 81 | if (index > -1) { |
| 82 | data.splice(index, 1, problem); |
| 83 | } else { |
| 84 | data.push(problem); |
| 85 | } |
| 86 | }); |
| 87 | |
| 88 | this.setState( |
| 89 | { |
| 90 | data: [...data], |
| 91 | }, |
| 92 | () => { |
| 93 | this.updateStatusBar(); |
| 94 | } |
| 95 | ); |
| 96 | } |
| 97 | public update<T>(item: IProblemsItem<T> | IProblemsItem<T>[]) { |
| 98 | const problems = Array.isArray(item) ? item : [item]; |
| 99 | const { data } = this.state; |
| 100 | |
| 101 | problems.forEach((problem) => { |
| 102 | const index = data.findIndex(searchById(problem.id)); |
| 103 | if (index > -1) { |
| 104 | data.splice(index, 1, problem); |
| 105 | } else { |
| 106 | logger.error( |
| 107 | `Update problems failed, because there is no problem found via ${problem.id}` |
| 108 | ); |
| 109 | } |
| 110 | }); |
| 111 | |
| 112 | this.setState( |
nothing calls this directly
no outgoing calls
no test coverage detected