Separate modeling queries into public vs user data
This will enable better caching! Though it looks like the stale-while-revalidate isn't coming through on modeling public data, I wonder why?
This commit is contained in:
parent
2f7b6571f2
commit
a14bddb39e
1 changed files with 20 additions and 8 deletions
|
@ -12,6 +12,7 @@ import ItemCard, {
|
|||
NcBadge,
|
||||
YouOwnThisBadge,
|
||||
} from "./components/ItemCard";
|
||||
import useCurrentUser from "./components/useCurrentUser";
|
||||
|
||||
function ModelingPage() {
|
||||
usePageTitle("Modeling Hub");
|
||||
|
@ -25,6 +26,8 @@ function ModelingPage() {
|
|||
}
|
||||
|
||||
function ItemModelsSection() {
|
||||
const { isLoggedIn } = useCurrentUser();
|
||||
|
||||
const { loading, error, data } = useQuery(
|
||||
gql`
|
||||
query ModelingPage {
|
||||
|
@ -59,12 +62,6 @@ function ItemModelsSection() {
|
|||
name
|
||||
}
|
||||
}
|
||||
|
||||
currentUser {
|
||||
itemsTheyOwn {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment ItemFields on Item {
|
||||
|
@ -74,8 +71,23 @@ function ItemModelsSection() {
|
|||
isNc
|
||||
createdAt
|
||||
}
|
||||
`
|
||||
);
|
||||
|
||||
// We're going to be silent about the loading/error states here, because it's
|
||||
// not essential info anyway, and announcing the wait or the failure would be
|
||||
// more confusing than anything.
|
||||
const { data: userData } = useQuery(
|
||||
gql`
|
||||
query ModelingPage_UserData {
|
||||
currentUser {
|
||||
itemsTheyOwn {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
{ context: { sendAuth: true } }
|
||||
{ context: { sendAuth: true }, skip: !isLoggedIn }
|
||||
);
|
||||
|
||||
if (loading) {
|
||||
|
@ -102,7 +114,7 @@ function ItemModelsSection() {
|
|||
}
|
||||
|
||||
const ownedItemIds = new Set(
|
||||
data.currentUser?.itemsTheyOwn?.map((item) => item.id)
|
||||
userData?.currentUser?.itemsTheyOwn?.map((item) => item.id)
|
||||
);
|
||||
|
||||
return (
|
||||
|
|
Loading…
Reference in a new issue