mirror of
https://github.com/owncast/owncast.git
synced 2025-11-03 04:27:18 +08:00
Post-merge fixes
This commit is contained in:
83
web/pages/components/message-visiblity-toggle.tsx
Normal file
83
web/pages/components/message-visiblity-toggle.tsx
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
// Custom component for AntDesign Button that makes an api call, then displays a confirmation icon upon
|
||||||
|
import React, { useState, useEffect } from "react";
|
||||||
|
import { Button, Tooltip } from "antd";
|
||||||
|
import { EyeOutlined, EyeInvisibleOutlined, CheckCircleFilled, ExclamationCircleFilled } from "@ant-design/icons";
|
||||||
|
import { fetchData, UPDATE_CHAT_MESSGAE_VIZ } from "../../utils/apis";
|
||||||
|
import { MessageType } from '../../types/chat';
|
||||||
|
import { OUTCOME_TIMEOUT } from "../chat";
|
||||||
|
import { isEmptyObject } from "../../utils/format";
|
||||||
|
|
||||||
|
interface MessageToggleProps {
|
||||||
|
isVisible: boolean;
|
||||||
|
message: MessageType;
|
||||||
|
setMessage: (message: MessageType) => void,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default function MessageVisiblityToggle({ isVisible, message, setMessage }: MessageToggleProps) {
|
||||||
|
if (!message || isEmptyObject(message)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let outcomeTimeout = null;
|
||||||
|
const [outcome, setOutcome] = useState(0);
|
||||||
|
|
||||||
|
const { id: messageId } = message || {};
|
||||||
|
|
||||||
|
const resetOutcome = () => {
|
||||||
|
outcomeTimeout = setTimeout(() => { setOutcome(0)}, OUTCOME_TIMEOUT);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
clearTimeout(outcomeTimeout);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const updateChatMessage = async () => {
|
||||||
|
clearTimeout(outcomeTimeout);
|
||||||
|
setOutcome(0);
|
||||||
|
const result = await fetchData(UPDATE_CHAT_MESSGAE_VIZ, {
|
||||||
|
auth: true,
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
visible: !isVisible,
|
||||||
|
idArray: [messageId],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.success && result.message === "changed") {
|
||||||
|
setMessage({ ...message, visible: !isVisible });
|
||||||
|
setOutcome(1);
|
||||||
|
} else {
|
||||||
|
setMessage({ ...message, visible: isVisible });
|
||||||
|
setOutcome(-1);
|
||||||
|
}
|
||||||
|
resetOutcome();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let outcomeIcon = <CheckCircleFilled style={{ color: 'transparent' }} />;
|
||||||
|
if (outcome) {
|
||||||
|
outcomeIcon = outcome > 0 ?
|
||||||
|
<CheckCircleFilled style={{ color: 'var(--ant-success)' }} /> :
|
||||||
|
<ExclamationCircleFilled style={{ color: 'var(--ant-warning)' }} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const toolTipMessage = `Click to ${isVisible ? 'hide' : 'show'} this message`;
|
||||||
|
return (
|
||||||
|
<div className={`toggle-switch ${isVisible ? '' : 'hidden'}`}>
|
||||||
|
<span className="outcome-icon">{outcomeIcon}</span>
|
||||||
|
<Tooltip title={toolTipMessage} placement="topRight">
|
||||||
|
<Button
|
||||||
|
shape="circle"
|
||||||
|
size="small"
|
||||||
|
type="text"
|
||||||
|
icon={ isVisible ? <EyeOutlined /> : <EyeInvisibleOutlined /> }
|
||||||
|
onClick={updateChatMessage}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -63,6 +63,8 @@ export const CREATE_WEBHOOK = `${API_LOCATION}webhooks/create`;
|
|||||||
// hard coded social icons list
|
// hard coded social icons list
|
||||||
export const SOCIAL_PLATFORMS_LIST = `${NEXT_PUBLIC_API_HOST}api/socialplatforms`;
|
export const SOCIAL_PLATFORMS_LIST = `${NEXT_PUBLIC_API_HOST}api/socialplatforms`;
|
||||||
|
|
||||||
|
export const TEMP_UPDATER_API = LOGS_ALL;
|
||||||
|
|
||||||
|
|
||||||
const GITHUB_RELEASE_URL = "https://api.github.com/repos/owncast/owncast/releases/latest";
|
const GITHUB_RELEASE_URL = "https://api.github.com/repos/owncast/owncast/releases/latest";
|
||||||
|
|
||||||
@ -72,12 +74,6 @@ interface FetchOptions {
|
|||||||
auth?: boolean;
|
auth?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function fetchData(url: string, options?: FetchOptions) {
|
|
||||||
// TEMP
|
|
||||||
export const TEMP_UPDATER_API = LOGS_ALL;
|
|
||||||
|
|
||||||
const GITHUB_RELEASE_URL = "https://api.github.com/repos/owncast/owncast/releases/latest";
|
|
||||||
|
|
||||||
export async function fetchData(url: string, options?: object) {
|
export async function fetchData(url: string, options?: object) {
|
||||||
const {
|
const {
|
||||||
data,
|
data,
|
||||||
|
|||||||
Reference in New Issue
Block a user