How to use the react-sortable-hoc/dist/es6.arrayMove function in react-sortable-hoc

To help you get started, we’ve selected a few react-sortable-hoc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kong / insomnia / packages / insomnia-app / app / ui / components / modals / workspace-environments-edit-modal.js View on Github external
async _handleSortEnd(results: {
    oldIndex: number,
    newIndex: number,
    collection: Array,
  }) {
    const { oldIndex, newIndex } = results;
    if (newIndex === oldIndex) {
      return;
    }

    const { subEnvironments } = this.state;

    const newSubEnvironments = arrayMove(subEnvironments, oldIndex, newIndex);
    this.setState({ subEnvironments: newSubEnvironments });

    // Do this last so we don't block the sorting
    db.bufferChanges();
    for (let i = 0; i < newSubEnvironments.length; i++) {
      const environment = newSubEnvironments[i];
      await this._updateEnvironment(environment, { metaSortKey: i }, false);
    }
    db.flushChanges();
  }