feat: finish weather, add week number back, improve widget order and quick links

This commit is contained in:
David Ralph
2021-04-10 13:05:56 +01:00
parent 7c8c61472e
commit e3a482614c
10 changed files with 99 additions and 26 deletions

View File

@@ -3,7 +3,6 @@ import React from 'react';
import DragHandleIcon from '@material-ui/icons/DragIndicator';
import { sortableContainer, sortableElement } from 'react-sortable-hoc';
import arrayMove from 'array-move';
import { toast } from 'react-toastify';
const SortableItem = sortableElement(({value}) => (
@@ -26,9 +25,29 @@ export default class OrderSettings extends React.PureComponent {
this.language = window.language.modals.main.settings;
}
// based on https://stackoverflow.com/a/48301905
arrayMove(array, oldIndex, newIndex) {
if (oldIndex === newIndex) {
return array;
}
const newArray = [...array];
const target = newArray[oldIndex];
const inc = newIndex < oldIndex ? -1 : 1;
for (let i = oldIndex; i !== newIndex; i += inc) {
newArray[i] = newArray[i + inc];
}
newArray[newIndex] = target;
return newArray;
}
onSortEnd = ({oldIndex, newIndex}) => {
this.setState(({items}) => ({
items: arrayMove(items, oldIndex, newIndex)
items: this.arrayMove(items, oldIndex, newIndex)
}));
}