Skip to content

Commit

Permalink
Adding service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
arangates committed Aug 5, 2020
1 parent 181badd commit 1990d33
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 113 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ yarn-error.log*

# vercel
.vercel

# next-pwa

**/public/workbox-*.js
**/public/sw.js
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

All network requests are proxied via CORS Anywhere helps with accessing data from other websites that is normally forbidden by the same origin policy of web browsers

SWR - state management
SSR - NextJS
PWA - next-pwa
recharts - Charting library
idb-keyval - IndexedDB
- SWR - state management
- SSR - NextJS
- PWA - next-pwa
- recharts - Charting library
- idb-keyval - IndexedDB

App works Offline after initial load

Demo : https://comparecart.vercel.app/
2 changes: 1 addition & 1 deletion components/Analytics/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Chart = ({ items, title, colour, name }: chartProps) => {
{name}
</h2>
<LineChart width={400} height={400} data={data}>
<Line type='monotone' dataKey='uv' stroke='#8884d8' />
<Line dataKey='uv' stroke='#8884d8' />
</LineChart>
</div>
);
Expand Down
13 changes: 6 additions & 7 deletions components/SideBar/MenuOptions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
export interface MenuOptions {
'my store': Item[];
'Research Products': Item[];
'Learn': Item[];
'Settings': Item[];
id: number;
name: string;
options: Option[];
}

export interface Item {
id: number;
export interface Option {
id: number;
icon: string;
name: string;
}
}
16 changes: 8 additions & 8 deletions components/SideBar/OptionsList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import OptionsListItem from './OptionsListItem';
import OptionsListHeading from './OptionsListHeading';
import { MenuOptions, Item } from './MenuOptions';
import { MenuOptions, Option } from './MenuOptions';

interface Iprops {
menuOptions: MenuOptions;
menuOptions: MenuOptions[];
}

const OptionsList = ({ menuOptions }: Iprops) => {
Expand All @@ -15,15 +15,15 @@ const OptionsList = ({ menuOptions }: Iprops) => {
);
};

const renderOptions = (menuOptions: MenuOptions): React.ReactNode => {
return Object.entries(menuOptions).map(([heading, options]) => {
const renderOptions = (menuOptions: MenuOptions[]): React.ReactNode => {
return menuOptions.map((option: MenuOptions) => {
return (
<>
<OptionsListHeading key={heading.toString()} title={heading} />
{options.map((option: Item) => (
<div key={option.id}>
<OptionsListHeading title={option.name} />
{option.options.map((option: Option) => (
<OptionsListItem key={option.id} item={option} />
))}
</>
</div>
);
});
};
Expand Down
4 changes: 2 additions & 2 deletions components/SideBar/OptionsListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { Item } from './MenuOptions';
import { Option } from './MenuOptions';

interface Iprops {
item: Item;
item: Option;
}

const OptionsListItem = ({ item }: Iprops) => {
Expand Down
78 changes: 1 addition & 77 deletions components/SideBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,82 +1,6 @@
import React from 'react';
import OptionsList from './OptionsList';
import { MenuOptions } from './MenuOptions';

const MenuItems: MenuOptions = {
'my store': [
{
id: 1,
icon: 'some.svg',
name: 'Item Name',
},
{
id: 2,
icon: 'some.svg',
name: 'Item Name',
},
{
id: 3,
icon: 'some.svg',
name: 'Item Name',
},
{
id: 4,
icon: 'some.svg',
name: 'Item Name',
},
],
'Research Products': [
{
id: 5,
icon: 'some.svg',
name: 'Item Name',
},
{
id: 6,
icon: 'some.svg',
name: 'Item Name',
},
{
id: 7,
icon: 'some.svg',
name: 'Item Name',
},
{
id: 8,
icon: 'some.svg',
name: 'Item Name',
},
],
Learn: [
{
id: 9,
icon: 'some.svg',
name: 'Item Name',
},
{
id: 10,
icon: 'some.svg',
name: 'Item Name',
},
],
Settings: [
{
id: 11,
icon: 'some.svg',
name: 'Item Name',
},
{
id: 12,
icon: 'some.svg',
name: 'Item Name',
},
{
id: 13,
icon: 'some.svg',
name: 'Item Name',
},
],
};
import { MenuItems } from 'services/globals';

const SideBar = () => {
return (
Expand Down
4 changes: 2 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// const isProd = process.env.NODE_ENV === "production";
const isProd = process.env.NODE_ENV === "production";

const withPWA = require("next-pwa")

module.exports = withPWA({
pwa: {
// disable: !isProd,
disable: !isProd,
dest: "public"
}
})
7 changes: 0 additions & 7 deletions pages/_app.js

This file was deleted.

19 changes: 19 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import '../styles/index.css';
import Head from 'next/head';

import { AppProps } from 'next/app';

function MyApp({ Component, pageProps }: AppProps) {
return (
<>
<Head>
<title>CompareCart</title>
<meta name='viewport' content='initial-scale=1.0, width=device-width' />
<meta name='theme-color' content='#4553F0' />
</Head>
<Component {...pageProps} />
</>
);
}

export default MyApp;
4 changes: 1 addition & 3 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class MyDocument extends Document {
return (
<Html lang="en">
<Head>
<title>CompareCart</title>
<meta name='viewport' content='initial-scale=1.0, width=device-width' />
<meta name='theme-color' content='#4553F0' />

<meta
name='description'
content='The compare cart will show the difference between the sellers, rating and price.'
Expand Down
2 changes: 1 addition & 1 deletion public/sw.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 109 additions & 0 deletions services/globals.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { MenuOptions } from "components/SideBar/MenuOptions";

export const BOL_SERVER = 'https://api.bol.com';
export const PROXY_SERVER = 'https://cors-anywhere.herokuapp.com/';
export const baseURL = PROXY_SERVER + BOL_SERVER;
Expand Down Expand Up @@ -40,3 +42,110 @@ export const TableHeading = [
name: 'Action thing',
},
];

export const MenuItems: MenuOptions[] = [
{
"id":1,
"name":"my store",
"options":[
{
"id":1,
"icon":"some.svg",
"name":"Item Name"
},
{
"id":2,
"icon":"some.svg",
"name":"Item Name"
},
{
"id":3,
"icon":"some.svg",
"name":"Item Name"
},
{
"id":4,
"icon":"some.svg",
"name":"Item Name"
}
]
},
{
"id":2,
"name":"Research Products",
"options":[
{
"id":1,
"icon":"some.svg",
"name":"Item Name"
},
{
"id":2,
"icon":"some.svg",
"name":"Item Name"
},
{
"id":3,
"icon":"some.svg",
"name":"Item Name"
},
{
"id":4,
"icon":"some.svg",
"name":"Item Name"
}
]
},
{
"id":3,
"name":"Learn",
"options":[
{
"id":1,
"icon":"some.svg",
"name":"Item Name"
},
{
"id":2,
"icon":"some.svg",
"name":"Item Name"
},
{
"id":3,
"icon":"some.svg",
"name":"Item Name"
},
{
"id":4,
"icon":"some.svg",
"name":"Item Name"
}
]
},
{
"id":4,
"name":"Settings",
"options":[
{
"id":1,
"icon":"some.svg",
"name":"Item Name"
},
{
"id":2,
"icon":"some.svg",
"name":"Item Name"
},
{
"id":3,
"icon":"some.svg",
"name":"Item Name"
},
{
"id":4,
"icon":"some.svg",
"name":"Item Name"
}
]
}
];

0 comments on commit 1990d33

Please sign in to comment.