This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import canvasSize from "canvas-size"; | |
const getMaxTextureSize = () => { | |
const canvas = document.createElement("canvas"); | |
const gl = canvas.getContext("experimental-webgl"); | |
if (!gl) return 2048; | |
return gl.getParameter(gl.MAX_TEXTURE_SIZE) || 2048; | |
}; | |
const maxTextureSize = getMaxTextureSize(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useRef, useState, useEffect } from "react"; | |
import Hls from "hls.js"; | |
function getPosterSrc(playbackId, options = {}) { | |
const width = options.width || 640; | |
const height = options.height || ""; | |
const time = options.time || 0; | |
const fitMode = | |
typeof options.fitMode === "undefined" ? "smartcrop" : options.fitMode; | |
let url = `https://image.mux.com/${playbackId}/thumbnail.png?width=${width}&fit_mode=${fitMode}&time=${time}`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const config = { | |
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || "production", | |
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID, | |
apiVersion: "2021-03-25", | |
/** | |
* Set useCdn to `false` if your application require the freshest possible | |
* data always (potentially slightly slower and a bit more expensive). | |
* Authenticated request (like preview) will always bypass the CDN | |
**/ | |
useCdn: process.env.NODE_ENV === "production", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lib/sanity.js | |
import { | |
createImageUrlBuilder, | |
createPortableTextComponent, | |
createPreviewSubscriptionHook, | |
createCurrentUserHook, | |
} from "next-sanity"; | |
import { config } from "./config"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lib/sanity.server.js | |
import { createClient } from "next-sanity"; | |
import { config } from "./config"; | |
// Set up the client for fetching data in the getProps page functions | |
export const sanityClient = createClient(config); | |
// Set up a preview client with serverless authentication for drafts | |
export const previewClient = createClient({ | |
...config, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pages/index.js | |
import React from "react"; | |
import { groq } from "next-sanity"; | |
import { usePreviewSubscription, urlFor, PortableText } from "../lib/sanity"; | |
import { getClient } from "../lib/sanity.server"; | |
import { useRouter } from "next/router"; | |
import ErrorPage from './ErrorPage'; | |
import HomeComponent from '../components/HomeComponent'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useMemo, useContext } from "react"; | |
import immer from "immer"; | |
export default function makeStore() { | |
// This is basically a factory for a new store instance | |
const loggerActive = false; | |
// Create a new context for this store instance | |
const context = React.createContext(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from "axios"; | |
async function request(request) { | |
if (!request) { | |
return { data: undefined, error: "no request" }; | |
} | |
const data = typeof FormData !== "undefined" ? new FormData() : {}; | |
if (request.data) { | |
Object.entries(request.data).forEach(([key, value]) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Use IntelliSense to learn about possible attributes. | |
// Hover to view descriptions of existing attributes. | |
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"type": "chrome", | |
"request": "launch", | |
"name": "Next: Chrome", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
useRef, useCallback, useEffect, useState | |
} from 'react'; | |
import smoothscroll from 'smoothscroll-polyfill'; | |
smoothscroll.polyfill(); | |
function useSmoothScroll() { | |
const scrollRafPending = useRef(false); | |
const scrollRafInstance = useRef(false); |
NewerOlder