mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
allow for channel membership to change
This commit is contained in:
parent
3724433fb8
commit
a53a3d4847
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func ClearChannelCard(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
account, code, err := BearerAppToken(r, false);
|
||||
account, code, err := ParamAgentToken(r, false);
|
||||
if err != nil {
|
||||
ErrResponse(w, code, err)
|
||||
return
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func SetChannelCard(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
account, code, err := BearerAppToken(r, false);
|
||||
account, code, err := ParamAgentToken(r, false);
|
||||
if err != nil {
|
||||
ErrResponse(w, code, err)
|
||||
return
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { useContext, useState, useEffect, useRef } from 'react';
|
||||
import { CardContext } from 'context/CardContext';
|
||||
import { ConversationContext } from 'context/ConversationContext';
|
||||
|
||||
export function useMemberItem({ item }) {
|
||||
|
||||
@ -10,10 +11,11 @@ export function useMemberItem({ item }) {
|
||||
});
|
||||
|
||||
const card = useContext(CardContext);
|
||||
const conversation = useContext(ConversationContext);
|
||||
|
||||
useEffect(() => {
|
||||
updateState({
|
||||
imageUrl: card.actions.getImageUrl(item.card.id),
|
||||
imageUrl: card.actions.getImageUrl(item.card?.id),
|
||||
name: item.card?.data.cardProfile.name,
|
||||
handle: item.card?.data.cardProfile.handle,
|
||||
});
|
||||
@ -25,10 +27,10 @@ export function useMemberItem({ item }) {
|
||||
|
||||
const actions = {
|
||||
setMembership: async () => {
|
||||
console.log("set membership");
|
||||
conversation.actions.setChannelCard(item.card.id);
|
||||
},
|
||||
clearMembership: async () => {
|
||||
console.log("clear membership");
|
||||
conversation.actions.clearChannelCard(item.card.id);
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -2,7 +2,7 @@ import styled from 'styled-components';
|
||||
|
||||
export const MembersWrapper = styled.div`
|
||||
width: 100%;
|
||||
height: 240px;
|
||||
max-height: 240px;
|
||||
background-color: #f6f5ed;
|
||||
overflow: auto;
|
||||
`;
|
||||
|
@ -31,6 +31,27 @@ export function useMembers({ host, members }) {
|
||||
contacts.push({ member: members.has(value.data.cardProfile.guid), card: value });
|
||||
});
|
||||
}
|
||||
|
||||
contacts.sort((a, b) => {
|
||||
let aName = a.card?.data?.cardProfile?.name?.toLowerCase();
|
||||
let bName = b.card?.data?.cardProfile?.name?.toLowerCase();
|
||||
if (aName == null && bName == null) {
|
||||
return 0;
|
||||
}
|
||||
if (aName == null && bName != null) {
|
||||
return 1;
|
||||
}
|
||||
if (aName != null && bName == null) {
|
||||
return -1;
|
||||
}
|
||||
if (aName < bName) {
|
||||
return -1;
|
||||
}
|
||||
if (aName > bName) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
updateState({ readonly, contacts });
|
||||
}, [host, members]);
|
||||
|
@ -23,7 +23,26 @@ export function useCards() {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
updateState({ cards: Array.from(card.state.cards.values()) });
|
||||
updateState({ cards: Array.from(card.state.cards.values()).sort((a, b) => {
|
||||
let aName = a.data?.cardProfile?.name?.toLowerCase();
|
||||
let bName = b.data?.cardProfile?.name?.toLowerCase();
|
||||
if (aName == null && bName == null) {
|
||||
return 0;
|
||||
}
|
||||
if (aName == null && bName != null) {
|
||||
return 1;
|
||||
}
|
||||
if (aName != null && bName == null) {
|
||||
return -1;
|
||||
}
|
||||
if (aName < bName) {
|
||||
return -1;
|
||||
}
|
||||
if (aName > bName) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
})});
|
||||
}, [card])
|
||||
|
||||
return { state, actions };
|
||||
|
7
net/web/src/api/clearChannelCard.js
Normal file
7
net/web/src/api/clearChannelCard.js
Normal file
@ -0,0 +1,7 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function clearChannelCard(token, channelId, cardId ) {
|
||||
let channel = await fetchWithTimeout(`/content/channels/${channelId}/cards/${cardId}?agent=${token}`, {method: 'DELETE'});
|
||||
checkResponse(channel);
|
||||
return await channel.json();
|
||||
}
|
7
net/web/src/api/setChannelCard.js
Normal file
7
net/web/src/api/setChannelCard.js
Normal file
@ -0,0 +1,7 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function setChannelCard(token, channelId, cardId ) {
|
||||
let channel = await fetchWithTimeout(`/content/channels/${channelId}/cards/${cardId}?agent=${token}`, {method: 'PUT'});
|
||||
checkResponse(channel);
|
||||
return await channel.json();
|
||||
}
|
@ -9,6 +9,8 @@ import { getChannelTopics } from 'api/getChannelTopics';
|
||||
import { getChannelTopic } from 'api/getChannelTopic';
|
||||
import { getChannelTopicAssetUrl } from 'api/getChannelTopicAssetUrl';
|
||||
import { setChannelSubject } from 'api/setChannelSubject';
|
||||
import { setChannelCard } from 'api/setChannelCard';
|
||||
import { clearChannelCard } from 'api/clearChannelCard';
|
||||
export function useChannelContext() {
|
||||
const [state, setState] = useState({
|
||||
init: false,
|
||||
@ -98,6 +100,12 @@ export function useChannelContext() {
|
||||
setChannelSubject: async (channelId, subject) => {
|
||||
return await setChannelSubject(access.current, channelId, subject);
|
||||
},
|
||||
setChannelCard: async (channelId, cardId) => {
|
||||
return await setChannelCard(access.current, channelId, cardId);
|
||||
},
|
||||
clearChannelCard: async (channelId, cardId) => {
|
||||
return await clearChannelCard(access.current, channelId, cardId);
|
||||
},
|
||||
removeChannel: async (channelId) => {
|
||||
return await removeChannel(access.current, channelId);
|
||||
},
|
||||
|
@ -223,6 +223,12 @@ export function useConversationContext() {
|
||||
setChannelSubject: async (subject) => {
|
||||
return await channel.actions.setChannelSubject(conversationId.current.channelId, subject);
|
||||
},
|
||||
setChannelCard: async (cardId) => {
|
||||
return await channel.actions.setChannelCard(conversationId.current.channelId, cardId);
|
||||
},
|
||||
clearChannelCard: async (cardId) => {
|
||||
return await channel.actions.clearChannelCard(conversationId.current.channelId, cardId);
|
||||
},
|
||||
getAssetUrl: (topicId, assetId) => {
|
||||
const { cardId, channelId } = conversationId.current;
|
||||
if (conversationId.current.cardId) {
|
||||
|
Loading…
Reference in New Issue
Block a user