mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 11:39:17 +00:00
edit converstation subject
This commit is contained in:
parent
afb708df79
commit
754b94fcd9
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
func SetChannelSubject(w http.ResponseWriter, r *http.Request) {
|
func SetChannelSubject(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
account, code, err := BearerAppToken(r, false);
|
account, code, err := ParamAgentToken(r, false);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrResponse(w, code, err)
|
ErrResponse(w, code, err)
|
||||||
return
|
return
|
||||||
@ -60,6 +60,9 @@ func SetChannelSubject(w http.ResponseWriter, r *http.Request) {
|
|||||||
if res := tx.Model(&slot.Channel).Update("data_type", subject.DataType).Error; res != nil {
|
if res := tx.Model(&slot.Channel).Update("data_type", subject.DataType).Error; res != nil {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
if res := tx.Model(&slot.Channel).Update("detail_revision", account.ChannelRevision + 1).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
if res := tx.Model(&slot).Update("revision", account.ChannelRevision + 1).Error; res != nil {
|
if res := tx.Model(&slot).Update("revision", account.ChannelRevision + 1).Error; res != nil {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,42 @@
|
|||||||
import React, { useState, useEffect, useRef } from 'react'
|
import React, { useState, useEffect, useRef } from 'react'
|
||||||
import { CloseOutlined, UserOutlined } from '@ant-design/icons';
|
import { CloseOutlined, UserOutlined } from '@ant-design/icons';
|
||||||
import { useConversation } from './useConversation.hook';
|
import { useConversation } from './useConversation.hook';
|
||||||
import { Button, Checkbox, Modal, Spin } from 'antd'
|
import { Button, Input, Checkbox, Modal, Spin } from 'antd'
|
||||||
import { ConversationWrapper, ConversationButton, CloseButton, ListItem, BusySpin } from './Conversation.styled';
|
import { ConversationWrapper, ConversationButton, EditButton, CloseButton, ListItem, BusySpin } from './Conversation.styled';
|
||||||
import { AutoSizer, CellMeasurer, CellMeasurerCache, List } from 'react-virtualized';
|
import { AutoSizer, CellMeasurer, CellMeasurerCache, List } from 'react-virtualized';
|
||||||
import { AddTopic } from './AddTopic/AddTopic';
|
import { AddTopic } from './AddTopic/AddTopic';
|
||||||
import { VirtualList } from '../../VirtualList/VirtualList';
|
import { VirtualList } from '../../VirtualList/VirtualList';
|
||||||
import { TopicItem } from './TopicItem/TopicItem';
|
import { TopicItem } from './TopicItem/TopicItem';
|
||||||
import { HomeOutlined, DatabaseOutlined } from '@ant-design/icons';
|
import { EditOutlined, HomeOutlined, DatabaseOutlined } from '@ant-design/icons';
|
||||||
|
|
||||||
export function Conversation() {
|
export function Conversation() {
|
||||||
|
|
||||||
const { state, actions } = useConversation();
|
const { state, actions } = useConversation();
|
||||||
|
const [ showEdit, setShowEdit ] = useState(false);
|
||||||
|
const [ editSubject, setEditSubject ] = useState(null);
|
||||||
|
const [ subject, setSubject ] = useState(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (state.subject) {
|
||||||
|
setSubject(state.subject);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setSubject(state.contacts);
|
||||||
|
}
|
||||||
|
}, [state]);
|
||||||
|
|
||||||
const topicRenderer = (topic) => {
|
const topicRenderer = (topic) => {
|
||||||
return (<TopicItem topic={topic} />)
|
return (<TopicItem topic={topic} />)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onSaveSubject = () => {
|
||||||
|
actions.setSubject(editSubject);
|
||||||
|
setShowEdit(false);
|
||||||
|
}
|
||||||
|
|
||||||
const onEdit = () => {
|
const onEdit = () => {
|
||||||
console.log("EDIT CONVERSATION");
|
setEditSubject(state.subject);
|
||||||
|
setShowEdit(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Icon = () => {
|
const Icon = () => {
|
||||||
@ -28,12 +46,22 @@ export function Conversation() {
|
|||||||
return <HomeOutlined />
|
return <HomeOutlined />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Edit = () => {
|
||||||
|
if (state.cardId) {
|
||||||
|
return <></>
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<EditButton type="text" size={'large'} onClick={() => onEdit()} icon={<EditOutlined />} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConversationWrapper>
|
<ConversationWrapper>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<Icon />
|
<Icon />
|
||||||
<div class="subject">{ state.subject }</div>
|
<div class="subject">{ subject }</div>
|
||||||
|
<Edit />
|
||||||
</div>
|
</div>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
@ -50,6 +78,10 @@ export function Conversation() {
|
|||||||
<BusySpin size="large" delay="1000" spinning={!state.init} />
|
<BusySpin size="large" delay="1000" spinning={!state.init} />
|
||||||
</div>
|
</div>
|
||||||
<AddTopic />
|
<AddTopic />
|
||||||
|
<Modal title="Edit Subject" visible={showEdit} centered
|
||||||
|
okText="Save" onOk={() => onSaveSubject()} onCancel={() => setShowEdit(false)}>
|
||||||
|
<Input placeholder="Subject" onChange={(e) => setEditSubject(e.target.value)} value={editSubject} />
|
||||||
|
</Modal>
|
||||||
</ConversationWrapper>
|
</ConversationWrapper>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,11 @@ export const ConversationWrapper = styled.div`
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
|
.edit {
|
||||||
|
font-size: 18px;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -32,6 +37,7 @@ export const ConversationWrapper = styled.div`
|
|||||||
color: white;
|
color: white;
|
||||||
font-size: 1.5em;
|
font-size: 1.5em;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
padding-right: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.control {
|
.control {
|
||||||
@ -51,7 +57,7 @@ export const ConversationWrapper = styled.div`
|
|||||||
.buttons {
|
.buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
margin-right: 32px;
|
margin-right: 16px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +82,11 @@ export const ConversationButton = styled(Button)`
|
|||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
`
|
`
|
||||||
|
|
||||||
|
export const EditButton = styled(Button)`
|
||||||
|
font-size: 24px;
|
||||||
|
color: white;
|
||||||
|
`;
|
||||||
|
|
||||||
export const CloseButton = styled(Button)`
|
export const CloseButton = styled(Button)`
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
color: white;
|
color: white;
|
||||||
|
@ -11,6 +11,7 @@ export function useConversation() {
|
|||||||
cardId: null,
|
cardId: null,
|
||||||
channelId: null,
|
channelId: null,
|
||||||
subject: null,
|
subject: null,
|
||||||
|
contacts: null,
|
||||||
topics: [],
|
topics: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -26,6 +27,9 @@ export function useConversation() {
|
|||||||
close: () => {
|
close: () => {
|
||||||
navigate('/user')
|
navigate('/user')
|
||||||
},
|
},
|
||||||
|
setSubject: async (subject) => {
|
||||||
|
await conversation.actions.setChannelSubject(subject);
|
||||||
|
},
|
||||||
remove: async () => {
|
remove: async () => {
|
||||||
await conversation.actions.removeConversation();
|
await conversation.actions.removeConversation();
|
||||||
navigate('/user');
|
navigate('/user');
|
||||||
@ -40,6 +44,7 @@ export function useConversation() {
|
|||||||
updateState({
|
updateState({
|
||||||
init: conversation.state.init,
|
init: conversation.state.init,
|
||||||
subject: conversation.state.subject,
|
subject: conversation.state.subject,
|
||||||
|
contacts: conversation.state.contacts,
|
||||||
cardId: conversation.state.cardId,
|
cardId: conversation.state.cardId,
|
||||||
channelId: conversation.state.channelId,
|
channelId: conversation.state.channelId,
|
||||||
topics: Array.from(conversation.state.topics.values()),
|
topics: Array.from(conversation.state.topics.values()),
|
||||||
|
9
net/web/src/api/setChannelSubject.js
Normal file
9
net/web/src/api/setChannelSubject.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
|
export async function setChannelSubject(token, channelId, subject ) {
|
||||||
|
let data = { subject };
|
||||||
|
let params = { dataType: 'superbasic', data: JSON.stringify(data) };
|
||||||
|
let channel = await fetchWithTimeout(`/content/channels/${channelId}/subject?agent=${token}`, { method: 'PUT', body: JSON.stringify(params)} );
|
||||||
|
checkResponse(channel);
|
||||||
|
return await channel.json();
|
||||||
|
}
|
@ -8,7 +8,7 @@ import { addChannelTopic } from 'api/addChannelTopic';
|
|||||||
import { getChannelTopics } from 'api/getChannelTopics';
|
import { getChannelTopics } from 'api/getChannelTopics';
|
||||||
import { getChannelTopic } from 'api/getChannelTopic';
|
import { getChannelTopic } from 'api/getChannelTopic';
|
||||||
import { getChannelTopicAssetUrl } from 'api/getChannelTopicAssetUrl';
|
import { getChannelTopicAssetUrl } from 'api/getChannelTopicAssetUrl';
|
||||||
|
import { setChannelSubject } from 'api/setChannelSubject';
|
||||||
export function useChannelContext() {
|
export function useChannelContext() {
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
init: false,
|
init: false,
|
||||||
@ -89,6 +89,9 @@ export function useChannelContext() {
|
|||||||
addChannel: async (cards, subject, description) => {
|
addChannel: async (cards, subject, description) => {
|
||||||
return await addChannel(access.current, cards, subject, description);
|
return await addChannel(access.current, cards, subject, description);
|
||||||
},
|
},
|
||||||
|
setChannelSubject: async (channelId, subject) => {
|
||||||
|
return await setChannelSubject(access.current, channelId, subject);
|
||||||
|
},
|
||||||
removeChannel: async (channelId) => {
|
removeChannel: async (channelId) => {
|
||||||
return await removeChannel(access.current, channelId);
|
return await removeChannel(access.current, channelId);
|
||||||
},
|
},
|
||||||
|
@ -9,6 +9,7 @@ export function useConversationContext() {
|
|||||||
cardId: null,
|
cardId: null,
|
||||||
channelId: null,
|
channelId: null,
|
||||||
subject: null,
|
subject: null,
|
||||||
|
contacts: null,
|
||||||
topics: new Map(),
|
topics: new Map(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -33,8 +34,11 @@ export function useConversationContext() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.log(err);
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getContacts = (conversation) => {
|
||||||
let members = [];
|
let members = [];
|
||||||
if (conversation.guid) {
|
if (conversation.guid) {
|
||||||
members.push(card.actions.getCardByGuid(conversation.guid)?.data?.cardProfile?.handle);
|
members.push(card.actions.getCardByGuid(conversation.guid)?.data?.cardProfile?.handle);
|
||||||
@ -63,6 +67,7 @@ export function useConversationContext() {
|
|||||||
if (curRevision != deltaRevision) {
|
if (curRevision != deltaRevision) {
|
||||||
let conversation = card.actions.getChannel(cardId, channelId);
|
let conversation = card.actions.getChannel(cardId, channelId);
|
||||||
let subject = getSubject(conversation);
|
let subject = getSubject(conversation);
|
||||||
|
let contacts = getContacts(conversation);
|
||||||
let delta = await card.actions.getChannelTopics(cardId, channelId, curRevision);
|
let delta = await card.actions.getChannelTopics(cardId, channelId, curRevision);
|
||||||
for (let topic of delta) {
|
for (let topic of delta) {
|
||||||
if (topic.data == null) {
|
if (topic.data == null) {
|
||||||
@ -92,6 +97,7 @@ export function useConversationContext() {
|
|||||||
updateState({
|
updateState({
|
||||||
init: true,
|
init: true,
|
||||||
subject,
|
subject,
|
||||||
|
contacts,
|
||||||
topics: topics.current,
|
topics: topics.current,
|
||||||
});
|
});
|
||||||
revision.current = deltaRevision;
|
revision.current = deltaRevision;
|
||||||
@ -106,6 +112,7 @@ export function useConversationContext() {
|
|||||||
if (curRevision != deltaRevision) {
|
if (curRevision != deltaRevision) {
|
||||||
let conversation = channel.actions.getChannel(channelId);
|
let conversation = channel.actions.getChannel(channelId);
|
||||||
let subject = getSubject(conversation);
|
let subject = getSubject(conversation);
|
||||||
|
let contacts = getContacts(conversation);
|
||||||
let delta = await channel.actions.getChannelTopics(channelId, curRevision);
|
let delta = await channel.actions.getChannelTopics(channelId, curRevision);
|
||||||
for (let topic of delta) {
|
for (let topic of delta) {
|
||||||
if (topic.data == null) {
|
if (topic.data == null) {
|
||||||
@ -135,6 +142,7 @@ export function useConversationContext() {
|
|||||||
updateState({
|
updateState({
|
||||||
init: true,
|
init: true,
|
||||||
subject,
|
subject,
|
||||||
|
contacts,
|
||||||
topics: topics.current,
|
topics: topics.current,
|
||||||
});
|
});
|
||||||
revision.current = deltaRevision;
|
revision.current = deltaRevision;
|
||||||
@ -192,6 +200,9 @@ export function useConversationContext() {
|
|||||||
updateState({ init: false, subject: null, cardId, channelId, topics: topics.current });
|
updateState({ init: false, subject: null, cardId, channelId, topics: topics.current });
|
||||||
updateConversation();
|
updateConversation();
|
||||||
},
|
},
|
||||||
|
setChannelSubject: async (subject) => {
|
||||||
|
return await channel.actions.setChannelSubject(conversationId.current.channelId, subject);
|
||||||
|
},
|
||||||
getAssetUrl: (topicId, assetId) => {
|
getAssetUrl: (topicId, assetId) => {
|
||||||
const { cardId, channelId } = conversationId.current;
|
const { cardId, channelId } = conversationId.current;
|
||||||
if (conversationId.current.cardId) {
|
if (conversationId.current.cardId) {
|
||||||
|
Loading…
Reference in New Issue
Block a user