diff --git a/net/web/src/Home/Home.jsx b/net/web/src/Home/Home.jsx index a0dab1e5..50e1cf99 100644 --- a/net/web/src/Home/Home.jsx +++ b/net/web/src/Home/Home.jsx @@ -19,7 +19,7 @@ export function Home() { navigate('/admin') } } - }, []) + }, [app]) return <> } diff --git a/net/web/src/api/addChannelTopic.js b/net/web/src/api/addChannelTopic.js index bc41a320..7bb8ed54 100644 --- a/net/web/src/api/addChannelTopic.js +++ b/net/web/src/api/addChannelTopic.js @@ -1,24 +1,32 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function addChannelTopic(token, channelId, message, assets ) { - let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics?agent=${token}`, - { method: 'POST', body: JSON.stringify({}) }); - checkResponse(topic); - let slot = await topic.json(); - - // add each asset - + let subject = { data: JSON.stringify(message, (key, value) => { - if (value !== null) return value - }), datatype: 'superbasictopic' }; - let unconfirmed = await fetchWithTimeout(`/content/channels/${channelId}/topics/${slot.id}/subject?agent=${token}`, - { method: 'PUT', body: JSON.stringify(subject) }); - checkResponse(unconfirmed); + if (value !== null) return value + }), datatype: 'superbasictopic' }; + + if (assets == null || assets.length == 0) { + let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics?agent=${token}&confirm=true`, + { method: 'POST', body: JSON.stringify(subject) }); + checkResponse(topic); + } + else { + let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics?agent=${token}`, + { method: 'POST', body: JSON.stringify({}) }); + checkResponse(topic); - let confirmed = await fetchWithTimeout(`/content/channels/${channelId}/topics/${slot.id}/confirmed?agent=${token}`, - { method: 'PUT', body: JSON.stringify('confirmed') }); - checkResponse(confirmed); + let slot = await topic.json(); - return; + // add each asset + + let unconfirmed = await fetchWithTimeout(`/content/channels/${channelId}/topics/${slot.id}/subject?agent=${token}`, + { method: 'PUT', body: JSON.stringify(subject) }); + checkResponse(unconfirmed); + + let confirmed = await fetchWithTimeout(`/content/channels/${channelId}/topics/${slot.id}/confirmed?agent=${token}`, + { method: 'PUT', body: JSON.stringify('confirmed') }); + checkResponse(confirmed); + } } diff --git a/net/web/src/api/addContactChannelTopic.js b/net/web/src/api/addContactChannelTopic.js index 646a8c38..e54641c2 100644 --- a/net/web/src/api/addContactChannelTopic.js +++ b/net/web/src/api/addContactChannelTopic.js @@ -1,24 +1,31 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function addContactChannelTopic(server, token, channelId, message, assets ) { - let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}`, - { method: 'POST', body: JSON.stringify({}) }); - checkResponse(topic); - let slot = await topic.json(); - - // add each asset let subject = { data: JSON.stringify(message, (key, value) => { - if (value !== null) return value - }), datatype: 'superbasictopic' }; - let unconfirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/subject?contact=${token}`, - { method: 'PUT', body: JSON.stringify(subject) }); - checkResponse(unconfirmed); + if (value !== null) return value + }), datatype: 'superbasictopic' }; - let confirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/confirmed?contact=${token}`, - { method: 'PUT', body: JSON.stringify('confirmed') }); - checkResponse(confirmed); + if (assets == null || assets.length == 0) { + let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}&confirm=true`, + { method: 'POST', body: JSON.stringify(subject) }); + checkResponse(topic); + } + else { + let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}`, + { method: 'POST', body: JSON.stringify({}) }); + checkResponse(topic); + let slot = await topic.json(); - return; + // add each asset + + let unconfirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/subject?contact=${token}`, + { method: 'PUT', body: JSON.stringify(subject) }); + checkResponse(unconfirmed); + + let confirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/confirmed?contact=${token}`, + { method: 'PUT', body: JSON.stringify('confirmed') }); + checkResponse(confirmed); + } } diff --git a/net/web/src/context/useAppContext.hook.js b/net/web/src/context/useAppContext.hook.js index 85ac39e8..4ff6586a 100644 --- a/net/web/src/context/useAppContext.hook.js +++ b/net/web/src/context/useAppContext.hook.js @@ -163,8 +163,8 @@ export function useAppContext() { } }, []); - if (!state) { - return {} + if (state == null) { + return {}; } if (state.access === 'user') { return { state, actions: userActions }