mirror of
https://github.com/owncast/owncast.git
synced 2024-10-10 19:16:02 +00:00
set up bulkprocessing states and ux
This commit is contained in:
parent
310c6573d3
commit
7c06b74324
@ -1,12 +1,13 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { Table, Typography, Tooltip, Switch, Button, Result } from "antd";
|
import { Table, Typography, Tooltip, Switch, Button } from "antd";
|
||||||
|
import { CheckCircleFilled, ExclamationCircleFilled } from "@ant-design/icons";
|
||||||
import { RowSelectionType } from "antd/es/table/interface";
|
import { RowSelectionType } from "antd/es/table/interface";
|
||||||
import { ColumnsType } from 'antd/es/table';
|
import { ColumnsType } from 'antd/es/table';
|
||||||
import format from 'date-fns/format'
|
import format from 'date-fns/format'
|
||||||
|
|
||||||
import ToggleSwitch from './components/toggle';
|
import ToggleSwitch from './components/toggle';
|
||||||
|
|
||||||
import { CHAT_HISTORY, fetchData } from "../utils/apis";
|
import { CHAT_HISTORY, fetchData, UPDATE_CHAT_MESSGAE_VIZ } from "../utils/apis";
|
||||||
import { MessageType } from '../types/chat';
|
import { MessageType } from '../types/chat';
|
||||||
|
|
||||||
|
|
||||||
@ -35,10 +36,15 @@ function createUserNameFilters(messages: MessageType[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
export const OUTCOME_TIMEOUT = 3000;
|
||||||
|
|
||||||
export default function Chat() {
|
export default function Chat() {
|
||||||
const [messages, setMessages] = useState([]);
|
const [messages, setMessages] = useState([]);
|
||||||
const [selectedRowKeys, setSelectedRows] = useState([]);
|
const [selectedRowKeys, setSelectedRows] = useState([]);
|
||||||
|
const [bulkVisibility, setBulkVisibility] = useState(false);
|
||||||
|
const [bulkProcessing, setBulkProcessing] = useState(false);
|
||||||
|
const [bulkOutcome, setBulkOutcome] = useState(null);
|
||||||
|
let outcomeTimeout = null;
|
||||||
|
|
||||||
const getInfo = async () => {
|
const getInfo = async () => {
|
||||||
try {
|
try {
|
||||||
@ -51,13 +57,15 @@ export default function Chat() {
|
|||||||
|
|
||||||
const updateMessage = message => {
|
const updateMessage = message => {
|
||||||
const messageIndex = messages.findIndex(m => m.id === message.id);
|
const messageIndex = messages.findIndex(m => m.id === message.id);
|
||||||
console.log("====update?", message, messages[messageIndex])
|
|
||||||
messages.splice(messageIndex, 1, message)
|
messages.splice(messageIndex, 1, message)
|
||||||
setMessages([...messages]);
|
setMessages([...messages]);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getInfo();
|
getInfo();
|
||||||
|
return () => {
|
||||||
|
clearTimeout(outcomeTimeout);
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const nameFilters = createUserNameFilters(messages);
|
const nameFilters = createUserNameFilters(messages);
|
||||||
@ -69,6 +77,44 @@ export default function Chat() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleBulkToggle = checked => {
|
||||||
|
setBulkVisibility(checked);
|
||||||
|
};
|
||||||
|
const resetBulkOutcome = () => {
|
||||||
|
outcomeTimeout = setTimeout(() => { setBulkOutcome(null)}, OUTCOME_TIMEOUT);
|
||||||
|
};
|
||||||
|
const handleSubmitBulk = async () => {
|
||||||
|
setBulkProcessing(true);
|
||||||
|
const result = await fetchData(UPDATE_CHAT_MESSGAE_VIZ, {
|
||||||
|
auth: true,
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
visible: bulkVisibility,
|
||||||
|
idArray: selectedRowKeys,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.success && result.message === "changed") {
|
||||||
|
setBulkOutcome(<CheckCircleFilled />);
|
||||||
|
resetBulkOutcome();
|
||||||
|
|
||||||
|
// update messages
|
||||||
|
const updatedList = [...messages];
|
||||||
|
selectedRowKeys.map(key => {
|
||||||
|
const messageIndex = updatedList.findIndex(m => m.id === key);
|
||||||
|
const newMessage = {...messages[messageIndex], visible: bulkVisibility };
|
||||||
|
updatedList.splice(messageIndex, 1, newMessage);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
setMessages(updatedList);
|
||||||
|
} else {
|
||||||
|
setBulkOutcome(<ExclamationCircleFilled />);
|
||||||
|
resetBulkOutcome();
|
||||||
|
}
|
||||||
|
setBulkProcessing(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const chatColumns: ColumnsType<MessageType> = [
|
const chatColumns: ColumnsType<MessageType> = [
|
||||||
{
|
{
|
||||||
@ -109,7 +155,7 @@ export default function Chat() {
|
|||||||
width: 230,
|
width: 230,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Show/ Hide',
|
title: 'Show / Hide',
|
||||||
dataIndex: 'visible',
|
dataIndex: 'visible',
|
||||||
key: 'visible',
|
key: 'visible',
|
||||||
filters: [{ text: 'visible', value: true }, { text: 'hidden', value: false }],
|
filters: [{ text: 'visible', value: true }, { text: 'hidden', value: false }],
|
||||||
@ -129,16 +175,29 @@ export default function Chat() {
|
|||||||
return (
|
return (
|
||||||
<div className="chat-messages">
|
<div className="chat-messages">
|
||||||
<Title level={2}>Chat Messages</Title>
|
<Title level={2}>Chat Messages</Title>
|
||||||
<p>click things and stuff</p>
|
<div className="bulk-editor">
|
||||||
<Button
|
<span className="label">Check multiple messages to change their visibility to: </span>
|
||||||
type="primary"
|
|
||||||
// onClick={}
|
<Switch
|
||||||
disabled={!selectedRowKeys.length}
|
className="toggler"
|
||||||
loading={false}
|
disabled={!selectedRowKeys.length}
|
||||||
>
|
checkedChildren="show"
|
||||||
Bulk toggle
|
unCheckedChildren="hide"
|
||||||
</Button>
|
onChange={handleBulkToggle}
|
||||||
<Switch />
|
checked={bulkVisibility}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
size="small"
|
||||||
|
loading={bulkProcessing}
|
||||||
|
disabled={!selectedRowKeys.length}
|
||||||
|
icon={bulkOutcome}
|
||||||
|
onClick={handleSubmitBulk}
|
||||||
|
>
|
||||||
|
Go
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
<Table
|
<Table
|
||||||
size="small"
|
size="small"
|
||||||
className="messages-table"
|
className="messages-table"
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import { Switch } from "antd";
|
|||||||
import { CheckCircleFilled, ExclamationCircleFilled } from "@ant-design/icons";
|
import { CheckCircleFilled, ExclamationCircleFilled } from "@ant-design/icons";
|
||||||
import { fetchData, UPDATE_CHAT_MESSGAE_VIZ } from "../../utils/apis";
|
import { fetchData, UPDATE_CHAT_MESSGAE_VIZ } from "../../utils/apis";
|
||||||
import { MessageType } from '../../types/chat';
|
import { MessageType } from '../../types/chat';
|
||||||
|
import { OUTCOME_TIMEOUT } from "../chat";
|
||||||
|
|
||||||
interface MessageToggleProps {
|
interface MessageToggleProps {
|
||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
@ -13,7 +14,6 @@ interface MessageToggleProps {
|
|||||||
setMessage: (message: MessageType) => {},
|
setMessage: (message: MessageType) => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const OUTCOME_TIMEOUT = 3000;
|
|
||||||
|
|
||||||
export default function ToggleSwitch({ isVisible, message, setMessage }: MessageToggleProps) {
|
export default function ToggleSwitch({ isVisible, message, setMessage }: MessageToggleProps) {
|
||||||
let outcomeTimeout = null;
|
let outcomeTimeout = null;
|
||||||
|
|||||||
@ -14,6 +14,26 @@
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bulk-editor {
|
||||||
|
margin: .5rem 0;
|
||||||
|
padding: .5rem;
|
||||||
|
border: 1px solid #333;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-end;
|
||||||
|
|
||||||
|
.label {
|
||||||
|
font-size: .75rem;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggler {
|
||||||
|
margin: 0 1rem 0 .5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.ant-table-filter-dropdown {
|
.ant-table-filter-dropdown {
|
||||||
max-width: 250px;
|
max-width: 250px;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user