using card specific context

This commit is contained in:
Roland Osborne 2022-04-24 14:37:13 -07:00
parent 6b85537400
commit 984744b9ed
3 changed files with 8 additions and 14 deletions

View File

@ -148,10 +148,9 @@ export function useCardContext() {
setRevision: async (rev) => {
setCards(rev);
},
getImageUrl: (cardId, rev) => getCardImageUrl(access.current, cardId, rev),
}
console.log(state);
return { state, actions }
}

View File

@ -24,8 +24,8 @@ export function Cards({ showRegistry }) {
}
const cardImage = (item) => {
if (actions?.getCardImageUrl) {
return actions.getCardImageUrl(item.id, item.revision);
if (actions?.getImageUrl) {
return actions.getImageUrl(item.id, item.revision);
}
return null
}

View File

@ -1,5 +1,5 @@
import { useContext, useState, useEffect } from 'react';
import { AppContext } from '../../../../AppContext/AppContext';
import { CardContext } from '../../../../AppContext/CardContext';
import { useNavigate } from 'react-router-dom';
export function useCards() {
@ -9,10 +9,10 @@ export function useCards() {
});
const navigate = useNavigate();
const app = useContext(AppContext);
const card = useContext(CardContext);
const actions = {
getCardImageUrl: app?.actions?.getCardImageUrl,
getImageUrl: card.actions.getImageUrl,
select: (contact) => {
navigate(`/user/contact/${contact.data.cardProfile.guid}`);
}
@ -23,13 +23,8 @@ export function useCards() {
}
useEffect(() => {
if (app?.state?.Data?.cards) {
updateState({ cards: app.state.Data.cards });
}
else {
updateState({ cards: [] });
}
}, [app])
updateState({ cards: Array.from(card.state.cards.values()) });
}, [card])
return { state, actions };
}