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) => { setRevision: async (rev) => {
setCards(rev); setCards(rev);
}, },
getImageUrl: (cardId, rev) => getCardImageUrl(access.current, cardId, rev),
} }
console.log(state);
return { state, actions } return { state, actions }
} }

View File

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

View File

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