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) => {
|
setRevision: async (rev) => {
|
||||||
setCards(rev);
|
setCards(rev);
|
||||||
},
|
},
|
||||||
|
getImageUrl: (cardId, rev) => getCardImageUrl(access.current, cardId, rev),
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(state);
|
|
||||||
|
|
||||||
return { state, actions }
|
return { state, actions }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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 };
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user