summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/issue_show/stores/index.js
blob: f4639e9ed2a4f2c50d7e96a64b7f69e738245a6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export default class Store {
  constructor(initialState) {
    this.state = initialState;
    this.formState = {
      title: '',
      confidential: false,
      description: '',
      lockedWarningVisible: false,
      updateLoading: false,
    };
  }

  updateState(data) {
    if (this.stateShouldUpdate(data)) {
      this.formState.lockedWarningVisible = true;
    }

    this.state.titleHtml = data.title;
    this.state.titleText = data.title_text;
    this.state.descriptionHtml = data.description;
    this.state.descriptionText = data.description_text;
    this.state.taskStatus = data.task_status;
    this.state.updatedAt = data.updated_at;
    this.state.updatedByName = data.updated_by_name;
    this.state.updatedByPath = data.updated_by_path;
  }

  stateShouldUpdate(data) {
    return this.state.titleText !== data.title_text ||
      this.state.descriptionText !== data.description_text;
  }

  setFormState(state) {
    this.formState = Object.assign(this.formState, state);
  }
}