Custom Collection Snippets
pogseal
Helpful snippets to use when working with Custom Collections
Table of Contents
Custom Entry Template
1import type { LoaderFunctionArgs } from "@remix-run/node";2import { json } from "@remix-run/node";3import { useLoaderData } from "@remix-run/react";4import { gql } from "graphql-request";56import { Entry } from "~/routes/_site+/c_+/$collectionId_.$entryId/components/Entry";7import { entryMeta } from "~/routes/_site+/c_+/$collectionId_.$entryId/utils/entryMeta";8910const SECTIONS = {11main: Main,12};1314export { entryMeta as meta };1516export async function loader({17context: { payload, user },18params,19request,20}: LoaderFunctionArgs) {21const { entry } = await fetchEntry({22payload,23params,24request,25user,26gql: {27query: QUERY,28variables: {},29},30// rest: {31// depth: 1,32// },33});3435return json({36entry,37});38}3940export default function EntryPage() {41const { entry } = useLoaderData<typeof loader>();4243return <Entry customComponents={SECTIONS} customData={entry} />;44}4546//The $entryId variable is optional, but always passed in with the query.47const QUERY = gql`48query ($entryId: String!) {49SingularCollectionName(id: $entryId) {50id51slug52name53icon {54id55url56}57}58}59`;
Custom List Template
1import type { LoaderFunctionArgs } from "@remix-run/node";2import { json } from "@remix-run/node";3import { useLoaderData } from "@remix-run/react";4import { gql } from "graphql-request";56import { List } from "~/routes/_site+/$siteId.c_+/components/List";7import {8customListMeta,9fetchList,10} from "~/routes/_site+/$siteId.c_+/functions/list";1112export { customListMeta as meta };1314export async function loader({15context: { payload, user },16params,17request,18}: LoaderFunctionArgs) {19const { list } = await fetchList({20params,21gql: {22query: QUERY,23variables: {},24},25payload,26user,27});28return json({ list });29}3031export default function ListPage() {32const { list } = useLoaderData<typeof loader>();3334return (35<List>36<div></div>37</List>38);39}4041const QUERY = gql`42query {43PluralCollectionName(limit: 100, sort: "name") {44docs {45id46name47slug48element {49id50icon {51url52}53}54}55}56}57`;