kopia lustrzana https://github.com/bugout-dev/moonstream
add sorting, remove disabling on isLoading
rodzic
0927a24ae7
commit
8f52a11b15
|
@ -1,4 +1,4 @@
|
||||||
import React from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Skeleton, IconButton } from "@chakra-ui/react";
|
import { Skeleton, IconButton } from "@chakra-ui/react";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
|
@ -16,12 +16,29 @@ import moment from "moment";
|
||||||
import CopyButton from "./CopyButton";
|
import CopyButton from "./CopyButton";
|
||||||
|
|
||||||
const List = ({ data, revoke, isLoading, update }) => {
|
const List = ({ data, revoke, isLoading, update }) => {
|
||||||
|
const [stateData, setStateData] = useState(data);
|
||||||
const userToken = localStorage.getItem("MOONSTREAM_ACCESS_TOKEN");
|
const userToken = localStorage.getItem("MOONSTREAM_ACCESS_TOKEN");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data?.token?.length > 0) {
|
||||||
|
const sortedTokens = data.token.sort(function (a, b) {
|
||||||
|
var aName = a?.note?.toUpperCase();
|
||||||
|
var bName = b?.note?.toUpperCase();
|
||||||
|
if (a.note || b.note) {
|
||||||
|
return aName < bName ? -1 : aName < bName ? 1 : 0;
|
||||||
|
} else {
|
||||||
|
return new Date(b.created_at) - new Date(a.created_at);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setStateData({ ...data, token: [...sortedTokens] });
|
||||||
|
}
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
const cellProps = {
|
const cellProps = {
|
||||||
px: ["2px", "6px", "inherit"],
|
px: ["2px", "6px", "inherit"],
|
||||||
};
|
};
|
||||||
if (data) {
|
if (stateData) {
|
||||||
return (
|
return (
|
||||||
<Table
|
<Table
|
||||||
variant="simple"
|
variant="simple"
|
||||||
|
@ -40,7 +57,7 @@ const List = ({ data, revoke, isLoading, update }) => {
|
||||||
</Tr>
|
</Tr>
|
||||||
</Thead>
|
</Thead>
|
||||||
<Tbody>
|
<Tbody>
|
||||||
{data.token.map((token) => {
|
{stateData.token.map((token) => {
|
||||||
if (token.active) {
|
if (token.active) {
|
||||||
if (userToken !== token.id) {
|
if (userToken !== token.id) {
|
||||||
return (
|
return (
|
||||||
|
@ -50,7 +67,6 @@ const List = ({ data, revoke, isLoading, update }) => {
|
||||||
colorScheme="blue"
|
colorScheme="blue"
|
||||||
placeholder="Click to set up label"
|
placeholder="Click to set up label"
|
||||||
defaultValue={token.note}
|
defaultValue={token.note}
|
||||||
isDisabled={update.isLoading}
|
|
||||||
onSubmit={(nextValue) =>
|
onSubmit={(nextValue) =>
|
||||||
update.mutate({ token: token.id, note: nextValue })
|
update.mutate({ token: token.id, note: nextValue })
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue