updating thread timestamp and listing results

This commit is contained in:
Roland Osborne 2022-08-24 23:13:30 -07:00
parent df4a812baa
commit 8ed7141ae6
5 changed files with 27 additions and 31 deletions

View File

@ -16,9 +16,6 @@ export function TopicItem({ host, topic }) {
let name = state.name ? state.name : state.handle; let name = state.name ? state.name : state.handle;
let nameClass = state.name ? 'set' : 'unset'; let nameClass = state.name ? 'set' : 'unset';
let d = new Date();
let offset = d.getTime() / 1000 - state.created;
if (name == null) { if (name == null) {
name = "unknown contact" name = "unknown contact"
nameClass = "unknown" nameClass = "unknown"
@ -104,7 +101,7 @@ export function TopicItem({ host, topic }) {
</div> </div>
<div class="info"> <div class="info">
<div class={nameClass}>{ name }</div> <div class={nameClass}>{ name }</div>
<div>{ getTime(offset) }</div> <div>{ state.created }</div>
</div> </div>
</div> </div>
{ !state.confirmed && ( { !state.confirmed && (
@ -136,25 +133,3 @@ export function TopicItem({ host, topic }) {
) )
} }
function getTime(offset) {
if (offset < 1) {
return ''
}
if (offset < 60) {
return Math.floor(offset) + "s";
}
offset /= 60;
if (offset < 60) {
return Math.floor(offset) + "m";
}
offset /= 60;
if (offset < 24) {
return Math.floor(offset) + "h";
}
offset /= 24;
if (offset < 366) {
return Math.floor(offset) + "d";
}
offset /= 365.25;
return Math.floor(offset) + "y";
}

View File

@ -81,13 +81,24 @@ export function useTopicItem(topic) {
if (profile.state.init && card.state.init && conversation.state.init) { if (profile.state.init && card.state.init && conversation.state.init) {
const { guid, created } = topic.data.topicDetail; const { guid, created } = topic.data.topicDetail;
let createdStr;
const date = new Date(created * 1000);
const now = new Date();
if(now.getTime() - date.getTime() < 86400000) {
createdStr = date.toLocaleTimeString([], {hour: 'numeric', minute:'2-digit'});
}
else {
createdStr = date.toLocaleDateString("en-US");
}
if (profile.state.profile.guid == guid) { if (profile.state.profile.guid == guid) {
const { name, handle, imageUrl } = profile.actions.getProfile(); const { name, handle, imageUrl } = profile.actions.getProfile();
updateState({ name, handle, imageUrl, status, message, transform, assets, confirmed, error, ready, created, owner, textColor, textSize }); updateState({ name, handle, imageUrl, status, message, transform, assets, confirmed, error, ready, created: createdStr, owner, textColor, textSize });
} }
else { else {
const { name, handle, imageUrl } = card.actions.getCardProfileByGuid(guid); const { name, handle, imageUrl } = card.actions.getCardProfileByGuid(guid);
updateState({ name, handle, imageUrl, status, message, transform, assets, confirmed, error, ready, created, owner, textColor, textSize }); updateState({ name, handle, imageUrl, status, message, transform, assets, confirmed, error, ready, created: createdStr, owner, textColor, textSize });
} }
} }
}, [profile, card, conversation, topic]); }, [profile, card, conversation, topic]);

View File

@ -4,15 +4,20 @@ import { getListingImageUrl } from 'api/getListingImageUrl';
export function useListingItem(server, item) { export function useListingItem(server, item) {
const [state, setState] = useState({ const [state, setState] = useState({
logo: item.imageSet ? getListingImageUrl(server, item.guid) : null,
name: item.name,
handle: item.handle,
}); });
const updateState = (value) => { const updateState = (value) => {
setState((s) => ({ ...s, ...value })); setState((s) => ({ ...s, ...value }));
} }
useEffect(() => {
updateState({
logo: item.imageSet ? getListingImageUrl(server, item.guid) : null,
name: item.name,
handle: item.handle,
});
}, [server, item]);
const actions = { const actions = {
}; };

View File

@ -20,6 +20,10 @@ export function useListing() {
setState((s) => ({ ...s, ...value })); setState((s) => ({ ...s, ...value }));
} }
useEffect(() => {
updateState({ contacts: [] });
}, [state.node]);
const actions = { const actions = {
onNode: (value) => { onNode: (value) => {
updateState({ node: value }); updateState({ node: value });

View File

@ -20,6 +20,7 @@ export const WelcomeWrapper = styled.div`
.header { .header {
font-weight: bold; font-weight: bold;
font-size: 20px;
} }
} }