-
Hey guys! I've been working a feature for a client that wants to use 1 payload instance for all his sites. I've added a Context for setting your currently active site: import React, {
useState, createContext, useContext, useEffect,
} from 'react';
const Context = createContext({
currentSite: null,
setCurrentSite: () => {},
} as SiteContext);
export const SiteProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [currentSite, setCurrentSite] = useState<string | null>();
useEffect(() => {
const site = localStorage.getItem('currentSite');
if (site) {
setCurrentSite(site);
}
});
const setSite = (site: string | null) => {
localStorage.setItem('currentSite', site);
setCurrentSite(site);
}
return (
<Context.Provider value={{
currentSite,
setCurrentSite: setSite,
}}>
{children}
</Context.Provider>
);
};
class SiteContext {
currentSite: string | null;
setCurrentSite: (string) => void;
}
type UseSite = () => SiteContext;
export const useSite: UseSite = () => useContext(Context); And added a simple dropdown below the logo to pick one of the sites. Now I want to enable the " |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @falko100 — that type of "filter" would be referred to as a query constraint, and that is generally accomplished via some backend logic in either a field hook or an access control operation. There are lots of ways to do this - but I think how I'd do it is persist something to the user when you switch the selected site - like... a And then write all your access control to look at which site the user has selected, and return your query constraint based on that. Does that make sense? |
Beta Was this translation helpful? Give feedback.
Hey @falko100 — that type of "filter" would be referred to as a query constraint, and that is generally accomplished via some backend logic in either a field hook or an access control operation.
There are lots of ways to do this - but I think how I'd do it is persist something to the user when you switch the selected site - like... a
select
field on the user or similar.And then write all your access control to look at which site the user has selected, and return your query constraint based on that. Does that make sense?