Skip to content

Commit d539a5a

Browse files
committed
chore(website): fix pwa update
1 parent 564c12e commit d539a5a

File tree

8 files changed

+35
-4
lines changed

8 files changed

+35
-4
lines changed

packages/hedgehog-website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"react-resize-detector": "^6.7.2",
3939
"react-router-dom": "6",
4040
"react-syntax-highlighter": "^15.4.5",
41+
"react-toastify": "^9.0.8",
4142
"react-use": "^17.3.1",
4243
"recoil": "^0.7.0",
4344
"swr": "^1.2.2",

packages/hedgehog-website/src/App.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {pageView} from "./utils/ga4";
1212
import {searchState} from "./states/RSnippetStates";
1313
import { HelmetProvider } from 'react-helmet-async';
1414
import Meta from './components/Meta/Meta';
15+
import {ToastContainer} from "react-toastify";
16+
import "react-toastify/dist/ReactToastify.css";
1517

1618
const ThemePage = () => {
1719
const resetSearch = useResetRecoilState(searchState)
@@ -35,6 +37,7 @@ const ThemePage = () => {
3537
const App = (): React.ReactElement => {
3638
return (
3739
<div className="App">
40+
<ToastContainer />
3841
{/*// @ts-ignore */}
3942
<RecoilRoot>
4043
<HelmetProvider>

packages/hedgehog-website/src/components/Snippet/List/SnippetList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ const SnippetList: React.FC<ISnippetListProps> = (props) => {
128128
{snippets.map((item: ISnippetsProps, index: number) => {
129129
return (
130130
<Box key={index}>
131-
<Grid container display={"flex"} justifyContent={"space-between"}
131+
<Grid container display={"flex"} justifyContent={"space-between"} alignItems={'center'}
132132
spacing={isExplorePage ? 0 : 1}>
133133
<Grid item>
134134
<Box alignItems={"center"} display={"flex"} sx={{

packages/hedgehog-website/src/pages/Home/Home.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React from "react";
1+
import React, {useEffect} from "react";
22
import GettingStarted from "./_gettingStarted";
33
import Community from "./_community";
44
import {Stack} from "@mui/material";
55
import Draft from "./_draft";
66
import Meta from '../../components/Meta/Meta';
7+
import {toast} from "react-toastify";
78

89
const Home = () => {
910
return (

packages/hedgehog-website/src/pages/Snippets/Snippets.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const Snippets = (): React.ReactElement => {
8181
const snippetMetaUrl = `/snippets/meta?user=${currentName}`
8282
await mutate(snippetMetaUrl)
8383
} catch (e) {
84-
console.log(e.response.data.message)
84+
console.log(e)
8585
} finally {
8686
setUpdateUserDescLoading(false)
8787
}

packages/hedgehog-website/src/pages/Timeline/Timeline.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const Timeline = () => {
8080
</Stack>
8181

8282
{item.snippet?.user.username &&
83-
<Card variant="outlined" sx={{mt: "5px", ml: 4, bgcolor: grey[50]}}>
83+
<Card variant="outlined" sx={{mt: "4px", ml: 4, bgcolor: grey[50]}}>
8484
<CardContent>
8585
<Grid container>
8686
<Grid item xs={12} md={10}>

packages/hedgehog-website/src/serviceWorkerRegistration.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// To learn more about the benefits of this model and instructions on how to
1111
// opt-in, read https://cra.link/PWA
1212

13+
import {toast} from "react-toastify";
14+
1315
const isLocalhost = Boolean(
1416
window.location.hostname === 'localhost' ||
1517
// [::1] is the IPv6 localhost address.
@@ -48,6 +50,10 @@ export function register(config?: Config) {
4850
'PWA: This web app is being served cache-first by a service ' +
4951
'worker. To learn more, visit https://cra.link/PWA'
5052
);
53+
54+
toast.info("PWA is available!", {
55+
position: toast.POSITION.BOTTOM_LEFT
56+
});
5157
});
5258
} else {
5359
// Is not localhost. Just register service worker
@@ -76,6 +82,15 @@ function registerValidSW(swUrl: string, config?: Config) {
7682
'PWA: New content is available and will be used when all '
7783
);
7884

85+
// registration?.waiting?.postMessage({ type: 'SKIP_WAITING' });
86+
toast.info("New content is available! Auto-updating...", {
87+
position: toast.POSITION.BOTTOM_LEFT,
88+
autoClose: false
89+
});
90+
91+
registration.waiting?.postMessage({ type: 'SKIP_WAITING' });
92+
registration.update();
93+
7994
// Execute callback
8095
if (config && config.onUpdate) {
8196
config.onUpdate(registration);
@@ -86,6 +101,10 @@ function registerValidSW(swUrl: string, config?: Config) {
86101
// "Content is cached for offline use." message.
87102
console.log('PWA: Content is cached for offline use.');
88103

104+
toast.info("PWA is available!", {
105+
position: toast.POSITION.BOTTOM_LEFT,
106+
});
107+
89108
// Execute callback
90109
if (config && config.onSuccess) {
91110
config.onSuccess(registration);

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17782,6 +17782,13 @@ react-syntax-highlighter@^15.4.5:
1778217782
prismjs "^1.25.0"
1778317783
refractor "^3.2.0"
1778417784

17785+
react-toastify@^9.0.8:
17786+
version "9.0.8"
17787+
resolved "https://registry.yarnpkg.com/react-toastify/-/react-toastify-9.0.8.tgz#3876c89fc6211a29027b3075010b5ec39ebe4f7e"
17788+
integrity sha512-EwM+teWt49HSHx+67qI08yLAW1zAsBxCXLCsUfxHYv1W7/R3ZLhrqKalh7j+kjgPna1h5LQMSMwns4tB4ww2yQ==
17789+
dependencies:
17790+
clsx "^1.1.1"
17791+
1778517792
react-transition-group@^4.4.2:
1778617793
version "4.4.2"
1778717794
resolved "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.2.tgz"

0 commit comments

Comments
 (0)