Skip to content

Commit

Permalink
UX-497 Enable content previews (#2)
Browse files Browse the repository at this point in the history
* UX-497 implement live preview framework

* UX-497 properly set preview data on internal sanity preview

* UX-497 add env variables to sanity studio (public facing, no sensitive data – honestly may not need these)

* UX-497 use correct preview url on production

* UX-497 Remove .env files

* UX-497 update production & local urls

* UX-497 remove unnecessary styled on outer box
  • Loading branch information
logansparlin authored Apr 23, 2021
1 parent 38634e9 commit def18d6
Show file tree
Hide file tree
Showing 22 changed files with 9,334 additions and 56 deletions.
9 changes: 9 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
"node": true,
"es6": true
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"],
"moduleDirectory": ["node_modules", "./"]
},
"typescript": {}
}
},
"parserOptions": {
"ecmaVersion": 8 ,
"sourceType": "module",
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ typings/
# dotenv environment variables file
.env
.env.test
.env.local
studio/.env.*

# parcel-bundler cache (https://parceljs.org/)
.cache
Expand Down
30 changes: 30 additions & 0 deletions lib/sanity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
createClient,
createImageUrlBuilder,
createPreviewSubscriptionHook,
createCurrentUserHook
} from 'next-sanity';

const config = {
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
apiVersion: '2021-03-25',
useCdn: process.env.NODE_ENV === 'production'
};

export const urlFor = (source) => createImageUrlBuilder(config).image(source);

export const usePreviewSubscription = createPreviewSubscriptionHook(config);

export const sanityClient = createClient(config);

export const previewClient = createClient({
...config,
useCdn: false,
token: process.env.SANITY_API_TOKEN,
withCredentials: true
});

export const getClient = (usePreview) => (usePreview ? previewClient : sanityClient);

export const useCurrentUser = createCurrentUserHook(config);
Loading

0 comments on commit def18d6

Please sign in to comment.