mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
using card specific context
This commit is contained in:
parent
6b85537400
commit
984744b9ed
@ -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 }
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user