This repository has been archived by the owner on Jul 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, { useEffect } from 'react'; | ||
import useBuildId from '../hooks/useBuildId'; | ||
|
||
function NewUpdateAvailible() { | ||
const buildId = useBuildId(); | ||
|
||
useEffect(() => { | ||
if (buildId && process.env.BUILD_ID && buildId !== process.env.BUILD_ID) { | ||
// There's a new version deployed that we need to load | ||
// SHOW MODAL | ||
} | ||
}, [buildId]); | ||
|
||
return <div>NewUpdateAvailible</div>; | ||
} | ||
|
||
export default NewUpdateAvailible; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useState } from 'react'; | ||
import useInterval from './useInterval'; | ||
|
||
function useBuildId() { | ||
let [buildId, setBuildId] = useState('unknown'); | ||
|
||
useInterval(async () => { | ||
let id = await fetchId(); | ||
|
||
setBuildId(id); | ||
}, 30000); // 30 seconds | ||
|
||
return buildId; | ||
} | ||
|
||
async function fetchId() { | ||
let response = await fetch('/api/build-id'); | ||
|
||
if (!response.ok) return; | ||
|
||
let data = await response.json(); | ||
|
||
return data.buildId; | ||
} | ||
|
||
export default useBuildId; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useRef, useEffect } from 'react'; | ||
import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect'; | ||
|
||
function useInterval(callback: () => void, delay: number | null) { | ||
const savedCallback = useRef(callback); | ||
|
||
// Remember the latest callback if it changes. | ||
|
||
useIsomorphicLayoutEffect(() => { | ||
savedCallback.current = callback; | ||
}, [callback]); | ||
|
||
// Set up the interval. | ||
|
||
useEffect(() => { | ||
// Don't schedule if no delay is specified. | ||
|
||
// Note: 0 is a valid value for delay. | ||
|
||
if (!delay && delay !== 0) { | ||
return; | ||
} | ||
|
||
const id = setInterval(() => savedCallback.current(), delay); | ||
|
||
return () => clearInterval(id); | ||
}, [delay]); | ||
} | ||
|
||
export default useInterval; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useEffect, useLayoutEffect } from 'react'; | ||
|
||
const useIsomorphicLayoutEffect = | ||
typeof window !== 'undefined' ? useLayoutEffect : useEffect; | ||
|
||
export default useIsomorphicLayoutEffect; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextBuildId = require('next-build-id'); | ||
|
||
module.exports = { | ||
generateBuildId: () => nextBuildId({ dir: __dirname, describe: true }), | ||
reactStrictMode: true, | ||
images: { | ||
domains: ['images.unsplash.com'], | ||
}, | ||
|
||
webpack: (config) => { | ||
webpack: (config, { buildId, webpack }) => { | ||
config.module.rules.push({ | ||
test: /\.svg$/i, | ||
issuer: /\.[jt]sx?$/, | ||
use: ['@svgr/webpack'], | ||
}); | ||
|
||
config.plugins.push( | ||
new webpack.DefinePlugin({ | ||
'process.env': { | ||
BUILD_ID: JSON.stringify(buildId), | ||
}, | ||
}) | ||
); | ||
|
||
return config; | ||
}, | ||
}; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
// eslint-disable-next-line import/no-anonymous-default-export | ||
export default (_req: NextApiRequest, res: NextApiResponse): void => { | ||
res.status(200).json({ | ||
buildId: process.env.BUILD_ID, | ||
}); | ||
}; |
This file contains 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