allow for channel membership to change

This commit is contained in:
Roland Osborne 2022-05-24 15:21:12 -07:00
parent 3724433fb8
commit a53a3d4847
10 changed files with 77 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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);
},
};

View File

@ -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;
`;

View File

@ -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]);

View File

@ -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 };

View 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();
}

View 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();
}

View File

@ -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);
},

View File

@ -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) {