Skip to content

Commit

Permalink
Proof of concept fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
ericdrosas87 authored and alexgoff committed Dec 27, 2024
1 parent e033a1f commit 7000701
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 3 deletions.
17 changes: 16 additions & 1 deletion app/[locale]/gallery/[gallery]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import { FunctionComponent } from "react";
import { getGalleryData } from "@/lib/api/galleries";

// should retrieve all galleries by entry, and
// return an array of their slugs to statically
// generate their content
// export async function generateStaticParams() {
// }

const Gallery: FunctionComponent<WithSearchParams<GalleryProps>> = ({
const Gallery: FunctionComponent<WithSearchParams<GalleryProps>> = async ({
params: { locale, gallery },
searchParams = {},
}) => {

const data = await getGalleryData(
gallery,
searchParams
// section,
// type,
// locale,
// previewToken
);

return (
<div>
<h1>Gallery {gallery}</h1>
<a href="?sort=asc">Sort Ascending</a><br></br>
<a href="?sort=desc">Sort Descending</a>
<p>searchParams: {JSON.stringify(searchParams)}</p>
<pre>Data : {JSON.stringify(data, null, 2)} </pre>
</div>
);
};
Expand Down
79 changes: 79 additions & 0 deletions lib/api/galleries/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { gql } from "@urql/core";
import queryAPI from "@/lib/api/client/query";

export async function getGalleryData(
uri: string,
searchParams: any
// section: string,
// type: string,
// locale: string,
// previewToken?: string
) {
// const site = getSiteFromLocale(locale);
// const query = getQueryFragments(uri, section, type, site);
const query = getQuery(searchParams?.sort);
console.info(query);

const { data } = await queryAPI({
query,
variables : {},
// variables: {
// section,
// type,
// site,
// uri: decodeURI(uri),
// },
// previewToken,
});

// Get the related investigation
// const entryWithRelatedData = await includeRelatedEntries(data.entry, site);
return cleanUpQueryResponse(data);
}

function cleanUpQueryResponse(response) {
return response?.entries.filter( e => Object.keys(e).length !== 0);
}

function getQuery(sort) {
let sortArg = "";
if (sort != undefined && sort != null) {
if (sort == "asc") {
sortArg = "(sortBy: \"default.DateCreated\")";
} else {
sortArg = "(sortByDesc: \"default.DateCreated\")";
}
}
return gql`
query MyQuery {
entries {
... on galleryItems_galleryItem_Entry {
id
title
albumAsGallery${sortArg} {
id
approvalStatus
owner
size
smartTags
url {
HighJPG
}
additional {
AltTextEN
AltTextES
CaptionEN
CaptionES
Credit
Description
}
default {
DateCreated
Author
Copyright
}
}
}
}
}`;
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"static": "npm-run-all static:*",
"static:build": "next build --debug",
"static:export": "next export",
"start": "next start -p 8080",
"start": "next start -p 3000",
"bs": "next build && next start -p 3000",
"prepare": "husky install",
"precommit": "lint-staged",
Expand Down Expand Up @@ -151,5 +151,6 @@
"tsconfig-paths-webpack-plugin": "^4.0.1",
"typescript": "^5.6.2",
"typescript-plugin-css-modules": "^5.1.0"
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}

0 comments on commit 7000701

Please sign in to comment.