mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
rendering channel icon and subject
This commit is contained in:
parent
8a1531bcee
commit
6365145df7
@ -79,6 +79,7 @@ export const SessionWrapper = styled.div`
|
||||
.bottom {
|
||||
height: 48px;
|
||||
position: relative;
|
||||
box-shadow: 0px -8px 16px 0px rgba(0,0,0,0.3);
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
@ -8,13 +8,12 @@ export function Channels() {
|
||||
|
||||
const { state, actions } = useChannels();
|
||||
|
||||
console.log(state);
|
||||
|
||||
return (
|
||||
<ChannelsWrapper>
|
||||
<div class="search">
|
||||
<div class="filter">
|
||||
<Input bordered={false} allowClear={true} placeholder="Channels" prefix={<SearchOutlined />} />
|
||||
<Input bordered={false} allowClear={true} placeholder="Channels" prefix={<SearchOutlined />}
|
||||
size="large" spellCheck="false" onChange={(e) => actions.onFilter(e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="results">
|
||||
|
@ -8,9 +8,11 @@ export const ChannelsWrapper = styled.div`
|
||||
flex-direction: column;
|
||||
background-color: ${Colors.formBackground};
|
||||
min-height: 0;
|
||||
overflow: scroll;
|
||||
|
||||
.search {
|
||||
padding: 8px;
|
||||
padding: 16px;
|
||||
border-bottom: 1px solid ${Colors.divider};
|
||||
|
||||
.filter {
|
||||
border: 1px solid ${Colors.divider};
|
||||
@ -20,6 +22,5 @@ export const ChannelsWrapper = styled.div`
|
||||
}
|
||||
|
||||
.results {
|
||||
min-height: 0;
|
||||
overflow: scroll;
|
||||
}
|
||||
`;
|
||||
|
@ -1,29 +1,36 @@
|
||||
import { ChannelItemWrapper } from './ChannelItem.styled';
|
||||
import { useChannelItem } from './useChannelItem.hook';
|
||||
import { SolutionOutlined } from '@ant-design/icons';
|
||||
import { Logo } from 'logo/Logo';
|
||||
import { AppstoreFilled, SolutionOutlined } from '@ant-design/icons';
|
||||
|
||||
export function ChannelItem({ item }) {
|
||||
|
||||
const { state, actions } = useChannelItem(item);
|
||||
console.log(item.contacts);
|
||||
|
||||
return (
|
||||
<ChannelItemWrapper>
|
||||
{ state.contacts.length === 0 && (
|
||||
<div class="notes">
|
||||
{ item.contacts.length === 0 && (
|
||||
<div class="item">
|
||||
<div class="logo">
|
||||
<SolutionOutlined />
|
||||
</div>
|
||||
<div class="subject">
|
||||
</div>
|
||||
<div class="markup">
|
||||
</div>
|
||||
<div class="subject">{ item.subject }</div>
|
||||
</div>
|
||||
)}
|
||||
{ state.contacts.length === 1 && (
|
||||
<div>PERSONAL</div>
|
||||
{ item.contacts.length === 1 && (
|
||||
<div class="item">
|
||||
<Logo url={item.logo} width={32} height={32} radius={8} />
|
||||
<div class="subject">{ item.subject }</div>
|
||||
<div class="markup"></div>
|
||||
</div>
|
||||
)}
|
||||
{ state.contacts.length > 1 && (
|
||||
<div>GROUP</div>
|
||||
{ item.contacts.length > 1 && (
|
||||
<div class="item">
|
||||
<div class="logo">
|
||||
<AppstoreFilled />
|
||||
</div>
|
||||
<div class="subject">{ item.subject }</div>
|
||||
<div class="markup"></div>
|
||||
</div>
|
||||
)}
|
||||
</ChannelItemWrapper>
|
||||
)
|
||||
|
@ -5,9 +5,20 @@ export const ChannelItemWrapper = styled.div`
|
||||
height: 48px;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-align: center;
|
||||
align-items: center;
|
||||
border-bottom: 1px solid ${Colors.divider};
|
||||
padding-left: 16px;
|
||||
padding-right: 16px;
|
||||
|
||||
&:hover {
|
||||
background-color: ${Colors.formHover};
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
|
||||
.logo {
|
||||
display: flex;
|
||||
@ -21,9 +32,11 @@ export const ChannelItemWrapper = styled.div`
|
||||
}
|
||||
|
||||
.subject {
|
||||
padding-left: 16px;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.markup {
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
@ -1,36 +0,0 @@
|
||||
import { useContext, useState, useEffect } from 'react';
|
||||
import { ProfileContext } from 'context/ProfileContext';
|
||||
import { CardContext } from 'context/CardContext';
|
||||
|
||||
export function useChannelItem(item) {
|
||||
|
||||
const [state, setState] = useState({
|
||||
contacts: [],
|
||||
});
|
||||
|
||||
const profile = useContext(ProfileContext);
|
||||
const card = useContext(CardContext);
|
||||
|
||||
const updateState = (value) => {
|
||||
setState((s) => ({ ...s, ...value }));
|
||||
}
|
||||
|
||||
const actions = {
|
||||
};
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
let contacts = [];
|
||||
if (item.guid != null && profile.state.profile.guid != item.guid) {
|
||||
contacts.push(card.actions.getCardByGuid(item.guid));
|
||||
}
|
||||
for (let guid of item.data.channelDetail?.members) {
|
||||
if (guid != profile.state.profile.guid) {
|
||||
contacts.push(card.actions.getCardByGuid(guid));
|
||||
}
|
||||
}
|
||||
updateState({ contacts });
|
||||
}, [profile, item]);
|
||||
|
||||
return { state, actions };
|
||||
}
|
@ -2,9 +2,12 @@ import { useContext, useState, useEffect } from 'react';
|
||||
import { StoreContext } from 'context/StoreContext';
|
||||
import { ChannelContext } from 'context/ChannelContext';
|
||||
import { CardContext } from 'context/CardContext';
|
||||
import { ProfileContext } from 'context/ProfileContext';
|
||||
|
||||
export function useChannels() {
|
||||
|
||||
const [filter, setFilter] = useState(null);
|
||||
|
||||
const [state, setState] = useState({
|
||||
channels: [],
|
||||
busy: false }
|
||||
@ -13,12 +16,16 @@ export function useChannels() {
|
||||
const card = useContext(CardContext);
|
||||
const channel = useContext(ChannelContext);
|
||||
const store = useContext(StoreContext);
|
||||
const profile = useContext(ProfileContext);
|
||||
|
||||
const updateState = (value) => {
|
||||
setState((s) => ({ ...s, ...value }));
|
||||
}
|
||||
|
||||
const actions = {
|
||||
onFilter: (value) => {
|
||||
setFilter(value.toUpperCase());
|
||||
},
|
||||
};
|
||||
|
||||
const setUpdated = (chan) => {
|
||||
@ -39,6 +46,46 @@ export function useChannels() {
|
||||
}
|
||||
}
|
||||
|
||||
const setContacts = (chan) => {
|
||||
let contacts = [];
|
||||
if (chan.guid != null && profile.state.profile.guid != chan.guid) {
|
||||
contacts.push(card.actions.getCardByGuid(chan.guid));
|
||||
}
|
||||
for (let guid of chan.data.channelDetail?.members) {
|
||||
if (guid != profile.state.profile.guid) {
|
||||
contacts.push(card.actions.getCardByGuid(guid));
|
||||
}
|
||||
}
|
||||
chan.contacts = contacts;
|
||||
if (contacts.length === 1 && contacts[0]) {
|
||||
chan.logo = card.actions.getImageUrl(contacts[0].id);
|
||||
}
|
||||
}
|
||||
|
||||
const setSubject = (chan) => {
|
||||
let subject = "";
|
||||
if (chan.data.channelDetail?.data) {
|
||||
try {
|
||||
subject = JSON.parse(chan.data.channelDetail?.data).subject;
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
if (!subject) {
|
||||
let names = [];
|
||||
for (let contact of chan.contacts) {
|
||||
names.push(contact?.data?.cardProfile?.name);
|
||||
}
|
||||
subject = names.join(", ");
|
||||
}
|
||||
if (!subject && !chan.contacts?.length) {
|
||||
subject = "notes";
|
||||
}
|
||||
|
||||
chan.subject = subject;
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
let merged = [];
|
||||
card.state.cards.forEach((value, key, map) => {
|
||||
@ -53,9 +100,20 @@ export function useChannels() {
|
||||
return 1;
|
||||
});
|
||||
|
||||
merged.forEach(chan => { setUpdated(chan) });
|
||||
updateState({ channels: merged });
|
||||
}, [channel, card, store]);
|
||||
merged.forEach(chan => {
|
||||
setUpdated(chan);
|
||||
setContacts(chan);
|
||||
setSubject(chan);
|
||||
});
|
||||
|
||||
const filtered = merged.filter((chan) => {
|
||||
let subject = chan?.subject?.toUpperCase();
|
||||
return !filter || subject?.includes(filter);
|
||||
});
|
||||
|
||||
updateState({ channels: filtered });
|
||||
|
||||
}, [channel, card, store, filter]);
|
||||
|
||||
return { state, actions };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user