Test
This commit is contained in:
parent
546fdc497f
commit
0bae41f0af
35 changed files with 18052 additions and 1447 deletions
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"singleQuote": true,
|
||||
"tabWidth": 4
|
||||
}
|
16756
package-lock.json
generated
Normal file
16756
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
85
package.json
85
package.json
|
@ -1,44 +1,45 @@
|
|||
{
|
||||
"name": "dashboard",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.3.2",
|
||||
"@testing-library/user-event": "^7.1.2",
|
||||
"http-server": "^0.12.3",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-scripts": "3.4.1",
|
||||
"react-select": "^3.1.0",
|
||||
"styled-components": "^5.1.0"
|
||||
},
|
||||
"scripts": {
|
||||
"serveAppData": "http-server ./ -c-1",
|
||||
"serveProductionApp": "http-server ./build --proxy http://localhost:8080 --port 3000",
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"serve:dev": "npm-run-all --parallel serveAppData start",
|
||||
"serve:production": "npm-run-all --parallel serveAppData serveProductionApp",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "react-app"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"npm-run-all": "^4.1.5"
|
||||
}
|
||||
"name": "dashboard",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.3.2",
|
||||
"@testing-library/user-event": "^7.1.2",
|
||||
"@types/jest": "^24.0.0",
|
||||
"@types/node": "^12.0.0",
|
||||
"@types/react-dom": "^16.9.8",
|
||||
"@types/react-select": "^3.0.14",
|
||||
"@types/styled-components": "^5.1.1",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-scripts": "3.4.1",
|
||||
"react-select": "^3.1.0",
|
||||
"styled-components": "^5.1.1",
|
||||
"typescript": "~3.7.2"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "react-app"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^16.9.41"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css?family=Roboto:400,500,700,900"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link
|
||||
href="https://fonts.googleapis.com/icon?family=Material+Icons"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<title>Dashboard</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css?family=Roboto:400,500,700,900"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link
|
||||
href="https://fonts.googleapis.com/icon?family=Material+Icons"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<title>Dashboard</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
37
src/app.js
37
src/app.js
|
@ -1,37 +0,0 @@
|
|||
import React from 'react';
|
||||
import styled, { createGlobalStyle } from 'styled-components';
|
||||
|
||||
import SearchBar from './components/searchBar';
|
||||
import Greeter from './components/greeter';
|
||||
import AppList from './components/appList';
|
||||
import BookmarkList from './components/bookmarkList';
|
||||
import SettingsModal from './components/settingsModal';
|
||||
|
||||
import selectedTheme from './components/themeManager';
|
||||
|
||||
const GlobalStyle = createGlobalStyle`
|
||||
body {
|
||||
background-color: ${selectedTheme.backgroundColor};
|
||||
font-family: Roboto, sans-serif;
|
||||
}
|
||||
`;
|
||||
|
||||
const AppContainer = styled.div`
|
||||
max-width: 85%;
|
||||
margin: auto;
|
||||
`;
|
||||
|
||||
const App = () => (
|
||||
<>
|
||||
<GlobalStyle />
|
||||
<AppContainer>
|
||||
<SearchBar />
|
||||
<SettingsModal />
|
||||
<Greeter />
|
||||
<AppList />
|
||||
<BookmarkList />
|
||||
</AppContainer>
|
||||
</>
|
||||
);
|
||||
|
||||
export default App;
|
37
src/app.tsx
Normal file
37
src/app.tsx
Normal file
|
@ -0,0 +1,37 @@
|
|||
import React from "react";
|
||||
import styled, { createGlobalStyle } from "styled-components";
|
||||
|
||||
import SearchBar from "./components/searchBar";
|
||||
import Greeter from "./components/greeter";
|
||||
import AppList from "./components/appList";
|
||||
import BookmarkList from "./components/bookmarkList";
|
||||
import SettingsModal from "./components/settingsModal";
|
||||
|
||||
import selectedTheme from "./components/themeManager";
|
||||
|
||||
const GlobalStyle = createGlobalStyle`
|
||||
body {
|
||||
background-color: ${selectedTheme.backgroundColor};
|
||||
font-family: Roboto, sans-serif;
|
||||
}
|
||||
`;
|
||||
|
||||
const AppContainer = styled.div`
|
||||
max-width: 85%;
|
||||
margin: auto;
|
||||
`;
|
||||
|
||||
const App = () => (
|
||||
<>
|
||||
<GlobalStyle />
|
||||
<AppContainer>
|
||||
<SearchBar />
|
||||
<SettingsModal />
|
||||
<Greeter />
|
||||
<AppList />
|
||||
<BookmarkList />
|
||||
</AppContainer>
|
||||
</>
|
||||
);
|
||||
|
||||
export default App;
|
|
@ -1,53 +0,0 @@
|
|||
import React from 'react';
|
||||
import Icon from './icon';
|
||||
import styled from 'styled-components';
|
||||
import selectedTheme from './themeManager';
|
||||
|
||||
const AppContainer = styled.div`
|
||||
display: flex;
|
||||
flex: auto 25%;
|
||||
padding: 1rem;
|
||||
`;
|
||||
|
||||
const IconContainer = styled.div`
|
||||
margin-right: 0.5rem;
|
||||
`;
|
||||
|
||||
const DetailsContainer = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
`;
|
||||
|
||||
const AppLink = styled.a`
|
||||
flex: 1 0 auto;
|
||||
color: ${selectedTheme.mainColor};
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
margin: 0;
|
||||
text-decoration: none;
|
||||
font-size: 1rem;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
`;
|
||||
|
||||
const AppDescription = styled.p`
|
||||
text-transform: uppercase;
|
||||
margin: 0;
|
||||
font-size: 0.65rem;
|
||||
font-weight: 400;
|
||||
color: ${selectedTheme.accentColor};
|
||||
`;
|
||||
|
||||
export const App = ({ name, icon, url, displayURL }) => (
|
||||
<AppContainer>
|
||||
<IconContainer>
|
||||
<Icon name={icon} color={selectedTheme.mainColor} />
|
||||
</IconContainer>
|
||||
<DetailsContainer>
|
||||
<AppLink href={url}>{name}</AppLink>
|
||||
<AppDescription>{displayURL}</AppDescription>
|
||||
</DetailsContainer>
|
||||
</AppContainer>
|
||||
);
|
60
src/components/app.tsx
Normal file
60
src/components/app.tsx
Normal file
|
@ -0,0 +1,60 @@
|
|||
import React from "react";
|
||||
import Icon from "./icon";
|
||||
import styled from "styled-components";
|
||||
import selectedTheme from "./themeManager";
|
||||
|
||||
const AppContainer = styled.div`
|
||||
display: flex;
|
||||
flex: auto 25%;
|
||||
padding: 1rem;
|
||||
`;
|
||||
|
||||
const IconContainer = styled.div`
|
||||
margin-right: 0.5rem;
|
||||
`;
|
||||
|
||||
const DetailsContainer = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
`;
|
||||
|
||||
const AppLink = styled.a`
|
||||
flex: 1 0 auto;
|
||||
color: ${selectedTheme.mainColor};
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
margin: 0;
|
||||
text-decoration: none;
|
||||
font-size: 1rem;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
`;
|
||||
|
||||
const AppDescription = styled.p`
|
||||
text-transform: uppercase;
|
||||
margin: 0;
|
||||
font-size: 0.65rem;
|
||||
font-weight: 400;
|
||||
color: ${selectedTheme.accentColor};
|
||||
`;
|
||||
|
||||
export interface IAppProps {
|
||||
name: string;
|
||||
icon: string;
|
||||
url: string;
|
||||
displayURL: string;
|
||||
}
|
||||
|
||||
export const App = ({ name, icon, url, displayURL }: IAppProps) => (
|
||||
<AppContainer>
|
||||
<IconContainer>
|
||||
<Icon>{icon}</Icon>
|
||||
</IconContainer>
|
||||
<DetailsContainer>
|
||||
<AppLink href={url}>{name}</AppLink>
|
||||
<AppDescription>{displayURL}</AppDescription>
|
||||
</DetailsContainer>
|
||||
</AppContainer>
|
||||
);
|
|
@ -1,30 +0,0 @@
|
|||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { App } from './app';
|
||||
import { ItemList, Item, SubHeadline } from './elements';
|
||||
|
||||
const CategoryHeadline = styled(SubHeadline)`
|
||||
padding-top: 1rem;
|
||||
`;
|
||||
|
||||
const CategoryContainer = styled.div`
|
||||
width: 100%;
|
||||
`;
|
||||
|
||||
export const AppCategory = ({ name, items }) => (
|
||||
<CategoryContainer>
|
||||
{name && <CategoryHeadline>{name}</CategoryHeadline>}
|
||||
<ItemList>
|
||||
{items.map((app, idx) => (
|
||||
<Item key={[app.name, idx].join('')}>
|
||||
<App
|
||||
name={app.name}
|
||||
icon={app.icon}
|
||||
url={app.url}
|
||||
displayURL={app.displayURL}
|
||||
/>
|
||||
</Item>
|
||||
))}
|
||||
</ItemList>
|
||||
</CategoryContainer>
|
||||
);
|
35
src/components/appCategory.tsx
Normal file
35
src/components/appCategory.tsx
Normal file
|
@ -0,0 +1,35 @@
|
|||
import React from "react";
|
||||
import styled from "styled-components";
|
||||
import { App, IAppProps } from "./app";
|
||||
import { ItemList, Item, SubHeadline } from "./elements";
|
||||
|
||||
const CategoryHeadline = styled(SubHeadline)`
|
||||
padding-top: 1rem;
|
||||
`;
|
||||
|
||||
const CategoryContainer = styled.div`
|
||||
width: 100%;
|
||||
`;
|
||||
|
||||
interface IAppCategoryProps {
|
||||
name: string;
|
||||
items: Array<IAppProps>;
|
||||
}
|
||||
|
||||
export const AppCategory = ({ name, items }: IAppCategoryProps) => (
|
||||
<CategoryContainer>
|
||||
{name && <CategoryHeadline>{name}</CategoryHeadline>}
|
||||
<ItemList>
|
||||
{items.map((app, idx) => (
|
||||
<Item key={[app.name, idx].join("")}>
|
||||
<App
|
||||
name={app.name}
|
||||
icon={app.icon}
|
||||
url={app.url}
|
||||
displayURL={app.displayURL}
|
||||
/>
|
||||
</Item>
|
||||
))}
|
||||
</ItemList>
|
||||
</CategoryContainer>
|
||||
);
|
|
@ -1,58 +0,0 @@
|
|||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import { AppCategory } from './appCategory';
|
||||
|
||||
import {
|
||||
handleResponse,
|
||||
Headline,
|
||||
ListContainer,
|
||||
ErrorMessage
|
||||
} from './elements';
|
||||
|
||||
const useAppData = () => {
|
||||
const [appData, setAppData] = useState({ apps: [], error: false });
|
||||
const fetchAppData = useCallback(() => {
|
||||
(process.env.NODE_ENV === 'production'
|
||||
? fetch('/data/apps.json').then(handleResponse)
|
||||
: import('./data/apps.json')
|
||||
)
|
||||
.then(jsonResponse => {
|
||||
setAppData({ ...jsonResponse, error: false });
|
||||
})
|
||||
.catch(error => {
|
||||
setAppData({ categories: [], apps: [], error: error.message });
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchAppData();
|
||||
}, [fetchAppData]);
|
||||
return { appData, fetchAppData };
|
||||
};
|
||||
|
||||
const AppList = () => {
|
||||
const {
|
||||
appData: { categories, apps, error }
|
||||
} = useAppData();
|
||||
return (
|
||||
<ListContainer>
|
||||
<Headline>Applications</Headline>
|
||||
{error && <ErrorMessage>{error}</ErrorMessage>}
|
||||
{categories &&
|
||||
categories.map(({ name, items }, idx) => (
|
||||
<AppCategory
|
||||
key={[name, idx].join('')}
|
||||
name={name}
|
||||
items={items}
|
||||
/>
|
||||
))}
|
||||
{apps && (
|
||||
<AppCategory
|
||||
name={categories ? 'Uncategorized apps' : null}
|
||||
items={apps}
|
||||
/>
|
||||
)}
|
||||
</ListContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default AppList;
|
58
src/components/appList.tsx
Normal file
58
src/components/appList.tsx
Normal file
|
@ -0,0 +1,58 @@
|
|||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import { AppCategory } from "./appCategory";
|
||||
|
||||
import {
|
||||
handleResponse,
|
||||
Headline,
|
||||
ListContainer,
|
||||
ErrorMessage
|
||||
} from "./elements";
|
||||
|
||||
const useAppData = () => {
|
||||
const [appData, setAppData] = useState({
|
||||
categories: [],
|
||||
apps: [],
|
||||
error: false
|
||||
});
|
||||
const fetchAppData = useCallback(() => {
|
||||
(process.env.NODE_ENV === "production"
|
||||
? fetch("/data/apps.json").then(handleResponse)
|
||||
: import("./data/apps.json")
|
||||
)
|
||||
.then(jsonResponse => {
|
||||
setAppData({ ...jsonResponse, error: false });
|
||||
})
|
||||
.catch(error => {
|
||||
setAppData({ categories: [], apps: [], error: error.message });
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchAppData();
|
||||
}, [fetchAppData]);
|
||||
return { appData, fetchAppData };
|
||||
};
|
||||
|
||||
const AppList = () => {
|
||||
const {
|
||||
appData: { categories, apps, error }
|
||||
} = useAppData();
|
||||
return (
|
||||
<ListContainer>
|
||||
<Headline>Applications</Headline>
|
||||
{error && <ErrorMessage>{error}</ErrorMessage>}
|
||||
{categories &&
|
||||
categories.map(({ name, items }, idx) => (
|
||||
<AppCategory key={[name, idx].join("")} name={name} items={items} />
|
||||
))}
|
||||
{apps && (
|
||||
<AppCategory
|
||||
name={categories.length > 0 ? "Uncategorized apps" : ""}
|
||||
items={apps}
|
||||
/>
|
||||
)}
|
||||
</ListContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default AppList;
|
|
@ -1,36 +0,0 @@
|
|||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { Item, SubHeadline } from './elements';
|
||||
import selectedTheme from './themeManager';
|
||||
|
||||
const GroupContainer = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 2 1 auto;
|
||||
padding: 1rem 0;
|
||||
`;
|
||||
|
||||
const Bookmark = styled.a`
|
||||
font-weight: 400;
|
||||
text-decoration: none;
|
||||
color: ${selectedTheme.accentColor};
|
||||
padding-top: 0.75rem;
|
||||
font-size: 0.9rem;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
`;
|
||||
|
||||
export const BookmarkGroup = ({ name: groupName, items }) => (
|
||||
<Item>
|
||||
<GroupContainer>
|
||||
<SubHeadline>{groupName}</SubHeadline>
|
||||
{items.map(({ name, url }, idx) => (
|
||||
<Bookmark key={[name, idx].join('')} href={url}>
|
||||
{name}
|
||||
</Bookmark>
|
||||
))}
|
||||
</GroupContainer>
|
||||
</Item>
|
||||
);
|
49
src/components/bookmarkGroup.tsx
Normal file
49
src/components/bookmarkGroup.tsx
Normal file
|
@ -0,0 +1,49 @@
|
|||
import React from "react";
|
||||
import styled from "styled-components";
|
||||
import { Item, SubHeadline } from "./elements";
|
||||
import selectedTheme from "./themeManager";
|
||||
|
||||
const GroupContainer = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 2 1 auto;
|
||||
padding: 1rem 0;
|
||||
`;
|
||||
|
||||
const Bookmark = styled.a`
|
||||
font-weight: 400;
|
||||
text-decoration: none;
|
||||
color: ${selectedTheme.accentColor};
|
||||
padding-top: 0.75rem;
|
||||
font-size: 0.9rem;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
`;
|
||||
|
||||
interface IBookmarkProps {
|
||||
name: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
interface IBookmarkGroupProps {
|
||||
name: string;
|
||||
items: [IBookmarkProps];
|
||||
}
|
||||
|
||||
export const BookmarkGroup = ({
|
||||
name: groupName,
|
||||
items
|
||||
}: IBookmarkGroupProps) => (
|
||||
<Item>
|
||||
<GroupContainer>
|
||||
<SubHeadline>{groupName}</SubHeadline>
|
||||
{items.map(({ name, url }, idx) => (
|
||||
<Bookmark key={[name, idx].join("")} href={url}>
|
||||
{name}
|
||||
</Bookmark>
|
||||
))}
|
||||
</GroupContainer>
|
||||
</Item>
|
||||
);
|
|
@ -1,38 +1,8 @@
|
|||
{
|
||||
"categories": [
|
||||
{
|
||||
"name": "Test",
|
||||
"name": "Networking",
|
||||
"items": [
|
||||
{
|
||||
"name": "Pihole",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "vpn_lock"
|
||||
},
|
||||
{
|
||||
"name": "Plex",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "tv"
|
||||
},
|
||||
{
|
||||
"name": "NextCloud",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "filter_drama"
|
||||
},
|
||||
{
|
||||
"name": "Ghost",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "rss_feed"
|
||||
},
|
||||
{
|
||||
"name": "Minecraft",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "games"
|
||||
},
|
||||
{
|
||||
"name": "pfSense",
|
||||
"displayURL": "example.com",
|
||||
|
@ -40,70 +10,16 @@
|
|||
"icon": "security"
|
||||
},
|
||||
{
|
||||
"name": "ESXi",
|
||||
"name": "Pihole",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "dns"
|
||||
},
|
||||
{
|
||||
"name": "Tautulli",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "bar_chart"
|
||||
},
|
||||
{
|
||||
"name": "Grafana",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "show_chart"
|
||||
"icon": "vpn_lock"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Test again",
|
||||
"name": "Monitoring",
|
||||
"items": [
|
||||
{
|
||||
"name": "Pihole",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "vpn_lock"
|
||||
},
|
||||
{
|
||||
"name": "Plex",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "tv"
|
||||
},
|
||||
{
|
||||
"name": "NextCloud",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "filter_drama"
|
||||
},
|
||||
{
|
||||
"name": "Ghost",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "rss_feed"
|
||||
},
|
||||
{
|
||||
"name": "Minecraft",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "games"
|
||||
},
|
||||
{
|
||||
"name": "pfSense",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "security"
|
||||
},
|
||||
{
|
||||
"name": "ESXi",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "dns"
|
||||
},
|
||||
{
|
||||
"name": "Tautulli",
|
||||
"displayURL": "example.com",
|
||||
|
@ -120,12 +36,6 @@
|
|||
}
|
||||
],
|
||||
"apps": [
|
||||
{
|
||||
"name": "Pihole",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "vpn_lock"
|
||||
},
|
||||
{
|
||||
"name": "Plex",
|
||||
"displayURL": "example.com",
|
||||
|
@ -150,29 +60,12 @@
|
|||
"URL": "https://example.com",
|
||||
"icon": "games"
|
||||
},
|
||||
{
|
||||
"name": "pfSense",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "security"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "ESXi",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "dns"
|
||||
},
|
||||
{
|
||||
"name": "Tautulli",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "bar_chart"
|
||||
},
|
||||
{
|
||||
"name": "Grafana",
|
||||
"displayURL": "example.com",
|
||||
"URL": "https://example.com",
|
||||
"icon": "show_chart"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,102 +0,0 @@
|
|||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import selectedTheme from './themeManager';
|
||||
import MaterialIcon from 'material-icons-react';
|
||||
|
||||
// File for elements that are/can be reused across the entire site.
|
||||
|
||||
export const handleResponse = (response) => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
throw new Error('Failed to load data.');
|
||||
};
|
||||
|
||||
export const ListContainer = styled.div`
|
||||
padding: 2rem 0;
|
||||
`;
|
||||
|
||||
export const Headline = styled.h2`
|
||||
display: inline-block;
|
||||
font-weight: 900;
|
||||
text-transform: uppercase;
|
||||
margin: 0;
|
||||
font-size: 1.5rem;
|
||||
color: ${selectedTheme.mainColor};
|
||||
`;
|
||||
|
||||
export const SubHeadline = styled.h3`
|
||||
display: inline-block;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
margin: 0;
|
||||
color: ${selectedTheme.mainColor};
|
||||
`;
|
||||
|
||||
export const ItemList = styled.ul`
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
grid-gap: 1rem;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
`;
|
||||
|
||||
export const Item = styled.li`
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
list-style: none;
|
||||
`;
|
||||
|
||||
export const Button = styled.button`
|
||||
text-transform: uppercase;
|
||||
font-weight: 400;
|
||||
border: 1px solid ${selectedTheme.mainColor};
|
||||
color: ${selectedTheme.mainColor};
|
||||
background: none;
|
||||
min-height: 3em;
|
||||
height: 100%;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
`;
|
||||
|
||||
const StyledButton = styled.button`
|
||||
float: right;
|
||||
border: none;
|
||||
background: none;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
`;
|
||||
|
||||
export const RefreshButton = styled(Button)`
|
||||
display: relative;
|
||||
top: 0;
|
||||
float: right;
|
||||
`;
|
||||
|
||||
export const ErrorMessage = styled.p`
|
||||
color: red;
|
||||
`;
|
||||
|
||||
export const IconButton = (props) => {
|
||||
if (
|
||||
props.icon &&
|
||||
props.icon !== '' &&
|
||||
props.icon !== undefined &&
|
||||
props.onClick &&
|
||||
props.onClick !== '' &&
|
||||
props.onClick !== undefined
|
||||
) {
|
||||
return (
|
||||
<StyledButton onClick={props.onClick}>
|
||||
<MaterialIcon
|
||||
icon={props.icon}
|
||||
color={selectedTheme.mainColor}
|
||||
/>
|
||||
</StyledButton>
|
||||
);
|
||||
}
|
||||
};
|
99
src/components/elements.tsx
Normal file
99
src/components/elements.tsx
Normal file
|
@ -0,0 +1,99 @@
|
|||
import React from "react";
|
||||
import styled from "styled-components";
|
||||
import selectedTheme from "./themeManager";
|
||||
import Icon from "./icon";
|
||||
|
||||
// File for elements that are/can be reused across the entire site.
|
||||
|
||||
export const handleResponse = (response: any) => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
throw new Error("Failed to load data.");
|
||||
};
|
||||
|
||||
export const ListContainer = styled.div`
|
||||
padding: 2rem 0;
|
||||
`;
|
||||
|
||||
export const Headline = styled.h2`
|
||||
display: inline-block;
|
||||
font-weight: 900;
|
||||
text-transform: uppercase;
|
||||
margin: 0;
|
||||
font-size: 1.5rem;
|
||||
color: ${selectedTheme.mainColor};
|
||||
`;
|
||||
|
||||
export const SubHeadline = styled.h3`
|
||||
display: inline-block;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
margin: 0;
|
||||
color: ${selectedTheme.mainColor};
|
||||
`;
|
||||
|
||||
export const ItemList = styled.ul`
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
grid-gap: 1rem;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
`;
|
||||
|
||||
export const Item = styled.li`
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
list-style: none;
|
||||
`;
|
||||
|
||||
export const Button = styled.button`
|
||||
text-transform: uppercase;
|
||||
font-weight: 400;
|
||||
border: 1px solid ${selectedTheme.mainColor};
|
||||
color: ${selectedTheme.mainColor};
|
||||
background: none;
|
||||
min-height: 3em;
|
||||
height: 100%;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
`;
|
||||
|
||||
const StyledButton = styled.button`
|
||||
float: right;
|
||||
border: none;
|
||||
background: none;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
`;
|
||||
|
||||
export const RefreshButton = styled(Button)`
|
||||
display: relative;
|
||||
top: 0;
|
||||
float: right;
|
||||
`;
|
||||
|
||||
export const ErrorMessage = styled.p`
|
||||
color: red;
|
||||
`;
|
||||
|
||||
interface IIconButtonProps {
|
||||
icon: String;
|
||||
onClick: any;
|
||||
}
|
||||
|
||||
export const IconButton = ({ icon, onClick }: IIconButtonProps) => {
|
||||
let StyledIcon = styled(Icon)`
|
||||
text-color: ${selectedTheme.mainColor};
|
||||
`;
|
||||
|
||||
return (
|
||||
<StyledButton onClick={onClick}>
|
||||
<StyledIcon>{icon}</StyledIcon>
|
||||
</StyledButton>
|
||||
);
|
||||
};
|
|
@ -1,108 +0,0 @@
|
|||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import selectedTheme from './themeManager';
|
||||
|
||||
const GreeterContainer = styled.div`
|
||||
padding: 2rem 0;
|
||||
`;
|
||||
|
||||
const GreetText = styled.h1`
|
||||
font-weight: 900;
|
||||
font-size: 3rem;
|
||||
margin: 0.5rem 0;
|
||||
color: ${selectedTheme.mainColor};
|
||||
`;
|
||||
|
||||
const DateText = styled.h3`
|
||||
font-weight: 400;
|
||||
font-size: 1rem;
|
||||
text-transform: uppercase;
|
||||
margin: 0;
|
||||
color: ${selectedTheme.accentColor};
|
||||
`;
|
||||
|
||||
const getGreeting = () => {
|
||||
switch (Math.floor(new Date().getHours() / 6)) {
|
||||
case 0:
|
||||
return 'Goor night!';
|
||||
case 1:
|
||||
return 'Good morning!';
|
||||
case 2:
|
||||
return 'Good afternoon!';
|
||||
case 3:
|
||||
return 'Good evening!';
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const getExtension = (day) => {
|
||||
let extension = '';
|
||||
|
||||
if ((day > 4 && day <= 20) || (day > 20 && day % 10 >= 4)) {
|
||||
extension = 'th';
|
||||
} else if (day % 10 === 1) {
|
||||
extension = 'st';
|
||||
} else if (day % 10 === 2) {
|
||||
extension = 'nd';
|
||||
} else if (day % 10 === 3) {
|
||||
extension = 'rd';
|
||||
}
|
||||
|
||||
return extension;
|
||||
};
|
||||
|
||||
const monthNames = [
|
||||
'January',
|
||||
'February',
|
||||
'March',
|
||||
'April',
|
||||
'May',
|
||||
'June',
|
||||
'July',
|
||||
'August',
|
||||
'September',
|
||||
'October',
|
||||
'November',
|
||||
'December',
|
||||
];
|
||||
|
||||
const weekDayNames = [
|
||||
'Sunday',
|
||||
'Monday',
|
||||
'Tuesday',
|
||||
'Wednesday',
|
||||
'Thursday',
|
||||
'Friday',
|
||||
'Saturday',
|
||||
];
|
||||
|
||||
const getDateString = () => {
|
||||
let currentDate = new Date();
|
||||
|
||||
return (
|
||||
weekDayNames[currentDate.getUTCDay()] +
|
||||
', ' +
|
||||
monthNames[currentDate.getUTCMonth()] +
|
||||
' ' +
|
||||
currentDate.getDate() +
|
||||
getExtension(currentDate.getDate()) +
|
||||
' ' +
|
||||
currentDate.getFullYear()
|
||||
);
|
||||
};
|
||||
|
||||
const Greeter = () => {
|
||||
let date = getDateString();
|
||||
let greeting = getGreeting();
|
||||
|
||||
return (
|
||||
<GreeterContainer>
|
||||
<DateText>{date}</DateText>
|
||||
<GreetText>{greeting}</GreetText>
|
||||
</GreeterContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default Greeter;
|
108
src/components/greeter.tsx
Normal file
108
src/components/greeter.tsx
Normal file
|
@ -0,0 +1,108 @@
|
|||
import React from "react";
|
||||
import styled from "styled-components";
|
||||
|
||||
import selectedTheme from "./themeManager";
|
||||
|
||||
const GreeterContainer = styled.div`
|
||||
padding: 2rem 0;
|
||||
`;
|
||||
|
||||
const GreetText = styled.h1`
|
||||
font-weight: 900;
|
||||
font-size: 3rem;
|
||||
margin: 0.5rem 0;
|
||||
color: ${selectedTheme.mainColor};
|
||||
`;
|
||||
|
||||
const DateText = styled.h3`
|
||||
font-weight: 400;
|
||||
font-size: 1rem;
|
||||
text-transform: uppercase;
|
||||
margin: 0;
|
||||
color: ${selectedTheme.accentColor};
|
||||
`;
|
||||
|
||||
const getGreeting = () => {
|
||||
switch (Math.floor(new Date().getHours() / 6)) {
|
||||
case 0:
|
||||
return "Goor night!";
|
||||
case 1:
|
||||
return "Good morning!";
|
||||
case 2:
|
||||
return "Good afternoon!";
|
||||
case 3:
|
||||
return "Good evening!";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const getExtension = (day: number) => {
|
||||
let extension = "";
|
||||
|
||||
if ((day > 4 && day <= 20) || (day > 20 && day % 10 >= 4)) {
|
||||
extension = "th";
|
||||
} else if (day % 10 === 1) {
|
||||
extension = "st";
|
||||
} else if (day % 10 === 2) {
|
||||
extension = "nd";
|
||||
} else if (day % 10 === 3) {
|
||||
extension = "rd";
|
||||
}
|
||||
|
||||
return extension;
|
||||
};
|
||||
|
||||
const monthNames = [
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"
|
||||
];
|
||||
|
||||
const weekDayNames = [
|
||||
"Sunday",
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday"
|
||||
];
|
||||
|
||||
const getDateString = () => {
|
||||
let currentDate = new Date();
|
||||
|
||||
return (
|
||||
weekDayNames[currentDate.getUTCDay()] +
|
||||
", " +
|
||||
monthNames[currentDate.getUTCMonth()] +
|
||||
" " +
|
||||
currentDate.getDate() +
|
||||
getExtension(currentDate.getDate()) +
|
||||
" " +
|
||||
currentDate.getFullYear()
|
||||
);
|
||||
};
|
||||
|
||||
const Greeter = () => {
|
||||
let date = getDateString();
|
||||
let greeting = getGreeting();
|
||||
|
||||
return (
|
||||
<GreeterContainer>
|
||||
<DateText>{date}</DateText>
|
||||
<GreetText>{greeting}</GreetText>
|
||||
</GreeterContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default Greeter;
|
|
@ -1,42 +0,0 @@
|
|||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
const IconContainer = styled.i`
|
||||
font-family: 'Material Icons';
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
font-size: 24px;
|
||||
display: inline-block;
|
||||
line-height: 1;
|
||||
text-transform: none;
|
||||
letter-spacing: normal;
|
||||
word-wrap: normal;
|
||||
white-space: nowrap;
|
||||
direction: ltr;
|
||||
|
||||
/* Support for all WebKit browsers. */
|
||||
-webkit-font-smoothing: antialiased;
|
||||
/* Support for Safari and Chrome. */
|
||||
text-rendering: optimizeLegibility;
|
||||
|
||||
/* Support for Firefox. */
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
|
||||
/* Support for IE. */
|
||||
font-feature-settings: 'liga';
|
||||
`;
|
||||
|
||||
export const Icon = ({ name, color, size }) => {
|
||||
let Container = IconContainer;
|
||||
|
||||
if (size) {
|
||||
Container = styled(IconContainer)`
|
||||
text-color: ${color};
|
||||
font-size: ${size};
|
||||
`;
|
||||
}
|
||||
|
||||
return <Container>{name}</Container>;
|
||||
};
|
||||
|
||||
export default Icon;
|
31
src/components/icon.tsx
Normal file
31
src/components/icon.tsx
Normal file
|
@ -0,0 +1,31 @@
|
|||
import styled from "styled-components";
|
||||
import selectedTheme from "./themeManager";
|
||||
|
||||
const Icon = styled.i`
|
||||
font-family: "Material Icons";
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
font-size: 24px;
|
||||
display: inline-block;
|
||||
line-height: 1;
|
||||
text-transform: none;
|
||||
letter-spacing: normal;
|
||||
word-wrap: normal;
|
||||
white-space: nowrap;
|
||||
direction: ltr;
|
||||
|
||||
text-color: ${selectedTheme.mainColor};
|
||||
|
||||
/* Support for all WebKit browsers. */
|
||||
-webkit-font-smoothing: antialiased;
|
||||
/* Support for Safari and Chrome. */
|
||||
text-rendering: optimizeLegibility;
|
||||
|
||||
/* Support for Firefox. */
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
|
||||
/* Support for IE. */
|
||||
font-feature-settings: "liga";
|
||||
`;
|
||||
|
||||
export default Icon;
|
|
@ -1,95 +0,0 @@
|
|||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { handleResponse, ErrorMessage } from './elements';
|
||||
|
||||
import selectedTheme from './themeManager';
|
||||
|
||||
const SearchInput = styled.input`
|
||||
width: 100%;
|
||||
font-size: 1rem;
|
||||
border: none;
|
||||
border-bottom: 1px solid ${selectedTheme.accentColor};
|
||||
background: none;
|
||||
border-radius: 0;
|
||||
color: ${selectedTheme.mainColor};
|
||||
`;
|
||||
|
||||
const useSearchProviders = () => {
|
||||
const [searchProviders, setSearchProviders] = useState({
|
||||
providers: [],
|
||||
error: false,
|
||||
});
|
||||
|
||||
const fetchSearchProviders = useCallback(() => {
|
||||
(process.env.NODE_ENV === 'production'
|
||||
? fetch('/data/search.json').then(handleResponse)
|
||||
: import('./data/search.json')
|
||||
)
|
||||
.then((jsonResponse) => {
|
||||
setSearchProviders({ ...jsonResponse, error: false });
|
||||
})
|
||||
.catch((error) => {
|
||||
setSearchProviders({ providers: [], error: error.message });
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchSearchProviders();
|
||||
}, [fetchSearchProviders]);
|
||||
return { searchProviders, fetchSearchProviders };
|
||||
};
|
||||
|
||||
const SearchBar = () => {
|
||||
const {
|
||||
searchProviders: { providers, error },
|
||||
} = useSearchProviders();
|
||||
|
||||
let [input, setInput] = useState();
|
||||
|
||||
const handleSearchQuery = (e) => {
|
||||
var query = input;
|
||||
|
||||
console.log(query);
|
||||
|
||||
if (query.split(' ')[0].includes('/')) {
|
||||
handleQueryWithProvider(query);
|
||||
} else {
|
||||
window.location = 'https://google.com/search?q=' + query;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
const handleQueryWithProvider = (query) => {
|
||||
let queryArray = query.split(' ');
|
||||
let prefix = queryArray[0];
|
||||
queryArray.shift();
|
||||
|
||||
let searchQuery = queryArray.join(' ');
|
||||
|
||||
let providerFound = false;
|
||||
providers.forEach((provider) => {
|
||||
if (provider.prefix === prefix) {
|
||||
providerFound = true;
|
||||
window.location = provider.url + searchQuery;
|
||||
}
|
||||
});
|
||||
|
||||
if (!providerFound)
|
||||
window.location = 'https://google.com/search?q=' + query;
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={(e) => handleSearchQuery(e)}>
|
||||
{error && <ErrorMessage>{error}</ErrorMessage>}
|
||||
<SearchInput
|
||||
type="text"
|
||||
onChange={(e) => setInput(e.target.value)}
|
||||
></SearchInput>
|
||||
<button type="submit" hidden />
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
export default SearchBar;
|
93
src/components/searchBar.tsx
Normal file
93
src/components/searchBar.tsx
Normal file
|
@ -0,0 +1,93 @@
|
|||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import styled from "styled-components";
|
||||
|
||||
import { handleResponse, ErrorMessage } from "./elements";
|
||||
|
||||
import selectedTheme from "./themeManager";
|
||||
|
||||
const SearchInput = styled.input`
|
||||
width: 100%;
|
||||
font-size: 1rem;
|
||||
border: none;
|
||||
border-bottom: 1px solid ${selectedTheme.accentColor};
|
||||
background: none;
|
||||
border-radius: 0;
|
||||
color: ${selectedTheme.mainColor};
|
||||
`;
|
||||
|
||||
const useSearchProviders = () => {
|
||||
const [searchProviders, setSearchProviders] = useState({
|
||||
providers: [{ prefix: "", url: "" }],
|
||||
error: false
|
||||
});
|
||||
|
||||
const fetchSearchProviders = useCallback(() => {
|
||||
(process.env.NODE_ENV === "production"
|
||||
? fetch("/data/search.json").then(handleResponse)
|
||||
: import("./data/search.json")
|
||||
)
|
||||
.then(jsonResponse => {
|
||||
setSearchProviders({ ...jsonResponse, error: false });
|
||||
})
|
||||
.catch(error => {
|
||||
setSearchProviders({ providers: [], error: error.message });
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchSearchProviders();
|
||||
}, [fetchSearchProviders]);
|
||||
return { searchProviders, fetchSearchProviders };
|
||||
};
|
||||
|
||||
const SearchBar = () => {
|
||||
const {
|
||||
searchProviders: { providers, error }
|
||||
} = useSearchProviders();
|
||||
|
||||
let [input, setInput] = useState();
|
||||
|
||||
const handleSearchQuery = (e: React.FormEvent) => {
|
||||
var query = input;
|
||||
|
||||
if (query.split(" ")[0].includes("/")) {
|
||||
handleQueryWithProvider(query);
|
||||
} else {
|
||||
window.location.href = "https://google.com/search?q=" + query;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
const handleQueryWithProvider = (query: string) => {
|
||||
let queryArray = query.split(" ");
|
||||
let prefix = queryArray[0];
|
||||
queryArray.shift();
|
||||
|
||||
let searchQuery = queryArray.join(" ");
|
||||
|
||||
let providerFound = false;
|
||||
providers.forEach(provider => {
|
||||
if (provider.prefix === prefix) {
|
||||
providerFound = true;
|
||||
window.location.href = provider.url + searchQuery;
|
||||
}
|
||||
});
|
||||
|
||||
if (!providerFound)
|
||||
window.location.href = "https://google.com/search?q=" + query;
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={e => handleSearchQuery(e)}>
|
||||
{error && <ErrorMessage>{error}</ErrorMessage>}
|
||||
<SearchInput
|
||||
type="text"
|
||||
onChange={e => setInput(e.target.value)}
|
||||
></SearchInput>
|
||||
<button type="submit" hidden />
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
export default SearchBar;
|
|
@ -1,187 +0,0 @@
|
|||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import Select from 'react-select';
|
||||
|
||||
import searchData from './data/search.json';
|
||||
|
||||
import selectedTheme, { setTheme } from './themeManager';
|
||||
import {
|
||||
handleResponse,
|
||||
Button,
|
||||
IconButton,
|
||||
ErrorMessage,
|
||||
Headline as hl,
|
||||
} from './elements';
|
||||
|
||||
const Headline = styled(hl)`
|
||||
padding: 0.5rem 0;
|
||||
`;
|
||||
|
||||
const Modal = styled.div`
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
padding: 1rem;
|
||||
transform: translate(-50%, -50%);
|
||||
z-index: 10;
|
||||
border: 1px solid ${selectedTheme.mainColor};
|
||||
background-color: ${selectedTheme.backgroundColor};
|
||||
`;
|
||||
|
||||
const SelectContainer = styled.div`
|
||||
padding-bottom: 1rem;
|
||||
`;
|
||||
|
||||
const FormContainer = styled.div`
|
||||
display: grid;
|
||||
grid-template-columns: auto auto auto;
|
||||
`;
|
||||
|
||||
const Table = styled.table`
|
||||
font-weight: 400;
|
||||
background: none;
|
||||
color: ${selectedTheme.mainColor};
|
||||
`;
|
||||
|
||||
const TableRow = styled.tr`
|
||||
border-bottom: 1px solid ${selectedTheme.mainColor};
|
||||
`;
|
||||
|
||||
const TableCell = styled.td`
|
||||
background: none;
|
||||
padding-top: 0.5rem;
|
||||
`;
|
||||
|
||||
const HeadCell = styled.th`
|
||||
font-weight: 700;
|
||||
background: none;
|
||||
`;
|
||||
|
||||
const SelectorStyle = {
|
||||
control: (provided) => ({
|
||||
...provided,
|
||||
fontWeight: '500',
|
||||
color: selectedTheme.mainColor,
|
||||
textTransform: 'uppercase',
|
||||
width: '12rem',
|
||||
background: 'none',
|
||||
borderRadius: '0px',
|
||||
border: '1px solid ' + selectedTheme.mainColor,
|
||||
boxShadow: 0,
|
||||
'&:hover': {
|
||||
border: '1px solid ' + selectedTheme.mainColor,
|
||||
},
|
||||
}),
|
||||
menu: (provided) => ({
|
||||
...provided,
|
||||
backgroundColor: selectedTheme.backgroundColor,
|
||||
border: '1px solid ' + selectedTheme.mainColor,
|
||||
borderRadius: 0,
|
||||
boxShadow: 0,
|
||||
}),
|
||||
option: (provided) => ({
|
||||
...provided,
|
||||
fontWeight: '500',
|
||||
color: selectedTheme.mainColor,
|
||||
textTransform: 'uppercase',
|
||||
borderRadius: 0,
|
||||
boxShadow: 0,
|
||||
backgroundColor: selectedTheme.backgroundColor,
|
||||
'&:hover': {
|
||||
backgroundColor: selectedTheme.mainColor,
|
||||
color: selectedTheme.backgroundColor,
|
||||
},
|
||||
}),
|
||||
singleValue: (provided) => {
|
||||
return {
|
||||
...provided,
|
||||
color: selectedTheme.mainColor,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
const useThemeData = () => {
|
||||
const [themeData, setThemeData] = useState({ themes: [], error: false });
|
||||
|
||||
const fetchThemeData = useCallback(() => {
|
||||
(process.env.NODE_ENV === 'production'
|
||||
? fetch('/data/themes.json').then(handleResponse)
|
||||
: import('./data/themes.json')
|
||||
)
|
||||
.then((jsonResponse) => {
|
||||
setThemeData({ ...jsonResponse, error: false });
|
||||
})
|
||||
.catch((error) => {
|
||||
setThemeData({ themes: [], error: error.message });
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchThemeData();
|
||||
}, [fetchThemeData]);
|
||||
return { themeData, fetchThemeData };
|
||||
};
|
||||
|
||||
const SettingsModal = () => {
|
||||
const [modalHidden, setModalHidden] = useState(true);
|
||||
const [newTheme, setNewTheme] = useState();
|
||||
|
||||
const {
|
||||
themeData: { themes, error },
|
||||
} = useThemeData();
|
||||
|
||||
return (
|
||||
<>
|
||||
<IconButton
|
||||
icon="settings"
|
||||
onClick={() => setModalHidden(!modalHidden)}
|
||||
/>
|
||||
<Modal hidden={modalHidden}>
|
||||
<IconButton
|
||||
icon="close"
|
||||
onClick={() => setModalHidden(!modalHidden)}
|
||||
/>
|
||||
{error && <ErrorMessage>{error}</ErrorMessage>}
|
||||
<SelectContainer>
|
||||
<Headline>Theme:</Headline>
|
||||
<FormContainer>
|
||||
<Select
|
||||
options={themes}
|
||||
defaultValue={selectedTheme}
|
||||
onChange={(e) => {
|
||||
setNewTheme(e);
|
||||
}}
|
||||
styles={SelectorStyle}
|
||||
/>
|
||||
|
||||
<Button
|
||||
onClick={() => setTheme(JSON.stringify(newTheme))}
|
||||
>
|
||||
Apply
|
||||
</Button>
|
||||
<Button onClick={() => window.location.reload()}>
|
||||
Refresh
|
||||
</Button>
|
||||
</FormContainer>
|
||||
</SelectContainer>
|
||||
<Table>
|
||||
<tbody>
|
||||
<TableRow>
|
||||
<HeadCell>Search Provider</HeadCell>
|
||||
<HeadCell>Prefix</HeadCell>
|
||||
</TableRow>
|
||||
{searchData.providers.map((provider, index) => (
|
||||
<TableRow key={provider.name + index}>
|
||||
<TableCell>{provider.name}</TableCell>
|
||||
<TableCell>{provider.prefix}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</tbody>
|
||||
</Table>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SettingsModal;
|
180
src/components/settingsModal.tsx
Normal file
180
src/components/settingsModal.tsx
Normal file
|
@ -0,0 +1,180 @@
|
|||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import styled from "styled-components";
|
||||
|
||||
import Select from "react-select";
|
||||
|
||||
import searchData from "./data/search.json";
|
||||
|
||||
import selectedTheme, { setTheme } from "./themeManager";
|
||||
import {
|
||||
handleResponse,
|
||||
Button,
|
||||
IconButton,
|
||||
ErrorMessage,
|
||||
Headline as hl
|
||||
} from "./elements";
|
||||
|
||||
const Headline = styled(hl)`
|
||||
padding: 0.5rem 0;
|
||||
`;
|
||||
|
||||
const Modal = styled.div`
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
padding: 1rem;
|
||||
transform: translate(-50%, -50%);
|
||||
z-index: 10;
|
||||
border: 1px solid ${selectedTheme.mainColor};
|
||||
background-color: ${selectedTheme.backgroundColor};
|
||||
`;
|
||||
|
||||
const SelectContainer = styled.div`
|
||||
padding-bottom: 1rem;
|
||||
`;
|
||||
|
||||
const FormContainer = styled.div`
|
||||
display: grid;
|
||||
grid-template-columns: auto auto auto;
|
||||
`;
|
||||
|
||||
const Table = styled.table`
|
||||
font-weight: 400;
|
||||
background: none;
|
||||
color: ${selectedTheme.mainColor};
|
||||
`;
|
||||
|
||||
const TableRow = styled.tr`
|
||||
border-bottom: 1px solid ${selectedTheme.mainColor};
|
||||
`;
|
||||
|
||||
const TableCell = styled.td`
|
||||
background: none;
|
||||
padding-top: 0.5rem;
|
||||
`;
|
||||
|
||||
const HeadCell = styled.th`
|
||||
font-weight: 700;
|
||||
background: none;
|
||||
`;
|
||||
|
||||
const SelectorStyle = {
|
||||
control: (provided: any) => ({
|
||||
...provided,
|
||||
fontWeight: "500",
|
||||
color: selectedTheme.mainColor,
|
||||
textTransform: "uppercase",
|
||||
width: "12rem",
|
||||
background: "none",
|
||||
borderRadius: "0px",
|
||||
border: "1px solid " + selectedTheme.mainColor,
|
||||
boxShadow: 0,
|
||||
"&:hover": {
|
||||
border: "1px solid " + selectedTheme.mainColor
|
||||
}
|
||||
}),
|
||||
menu: (provided: any) => ({
|
||||
...provided,
|
||||
backgroundColor: selectedTheme.backgroundColor,
|
||||
border: "1px solid " + selectedTheme.mainColor,
|
||||
borderRadius: 0,
|
||||
boxShadow: 0
|
||||
}),
|
||||
option: (provided: any) => ({
|
||||
...provided,
|
||||
fontWeight: "500",
|
||||
color: selectedTheme.mainColor,
|
||||
textTransform: "uppercase",
|
||||
borderRadius: 0,
|
||||
boxShadow: 0,
|
||||
backgroundColor: selectedTheme.backgroundColor,
|
||||
"&:hover": {
|
||||
backgroundColor: selectedTheme.mainColor,
|
||||
color: selectedTheme.backgroundColor
|
||||
}
|
||||
}),
|
||||
singleValue: (provided: any) => {
|
||||
return {
|
||||
...provided,
|
||||
color: selectedTheme.mainColor
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const useThemeData = () => {
|
||||
const [themeData, setThemeData] = useState({ themes: [], error: false });
|
||||
|
||||
const fetchThemeData = useCallback(() => {
|
||||
(process.env.NODE_ENV === "production"
|
||||
? fetch("/data/themes.json").then(handleResponse)
|
||||
: import("./data/themes.json")
|
||||
)
|
||||
.then(jsonResponse => {
|
||||
setThemeData({ ...jsonResponse, error: false });
|
||||
})
|
||||
.catch(error => {
|
||||
setThemeData({ themes: [], error: error.message });
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchThemeData();
|
||||
}, [fetchThemeData]);
|
||||
return { themeData, fetchThemeData };
|
||||
};
|
||||
|
||||
const SettingsModal = () => {
|
||||
const [modalHidden, setModalHidden] = useState(true);
|
||||
const [newTheme, setNewTheme] = useState();
|
||||
|
||||
const {
|
||||
themeData: { themes, error }
|
||||
} = useThemeData();
|
||||
|
||||
return (
|
||||
<>
|
||||
<IconButton
|
||||
icon="settings"
|
||||
onClick={() => setModalHidden(!modalHidden)}
|
||||
/>
|
||||
<Modal hidden={modalHidden}>
|
||||
<IconButton icon="close" onClick={() => setModalHidden(!modalHidden)} />
|
||||
{error && <ErrorMessage>{error}</ErrorMessage>}
|
||||
<SelectContainer>
|
||||
<Headline>Theme:</Headline>
|
||||
<FormContainer>
|
||||
<Select
|
||||
options={themes}
|
||||
defaultValue={selectedTheme}
|
||||
onChange={e => {
|
||||
setNewTheme(e);
|
||||
}}
|
||||
styles={SelectorStyle}
|
||||
/>
|
||||
|
||||
<Button onClick={() => setTheme(JSON.stringify(newTheme))}>
|
||||
Apply
|
||||
</Button>
|
||||
<Button onClick={() => window.location.reload()}>Refresh</Button>
|
||||
</FormContainer>
|
||||
</SelectContainer>
|
||||
<Table>
|
||||
<tbody>
|
||||
<TableRow>
|
||||
<HeadCell>Search Provider</HeadCell>
|
||||
<HeadCell>Prefix</HeadCell>
|
||||
</TableRow>
|
||||
{searchData.providers.map((provider, index) => (
|
||||
<TableRow key={provider.name + index}>
|
||||
<TableCell>{provider.name}</TableCell>
|
||||
<TableCell>{provider.prefix}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</tbody>
|
||||
</Table>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SettingsModal;
|
|
@ -1,38 +0,0 @@
|
|||
const defaultTheme = {
|
||||
label: 'Classic',
|
||||
value: 0,
|
||||
mainColor: '#000000',
|
||||
accentColor: '#1e272e',
|
||||
backgroundColor: '#ffffff'
|
||||
};
|
||||
|
||||
const setTheme = theme => {
|
||||
if (theme !== undefined) {
|
||||
localStorage.setItem('theme', theme);
|
||||
}
|
||||
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
const resetTheme = () => {
|
||||
localStorage.removeItem('theme');
|
||||
};
|
||||
|
||||
const getTheme = () => {
|
||||
let selectedTheme = defaultTheme;
|
||||
|
||||
if (
|
||||
localStorage.getItem('theme') &&
|
||||
localStorage.getItem('theme') !== undefined
|
||||
) {
|
||||
selectedTheme = JSON.parse(localStorage.getItem('theme'));
|
||||
}
|
||||
|
||||
return selectedTheme;
|
||||
};
|
||||
|
||||
const selectedTheme = getTheme();
|
||||
|
||||
export { setTheme, resetTheme };
|
||||
|
||||
export default selectedTheme;
|
35
src/components/themeManager.tsx
Normal file
35
src/components/themeManager.tsx
Normal file
|
@ -0,0 +1,35 @@
|
|||
const defaultTheme = {
|
||||
label: "Classic",
|
||||
value: 0,
|
||||
mainColor: "#000000",
|
||||
accentColor: "#1e272e",
|
||||
backgroundColor: "#ffffff"
|
||||
};
|
||||
|
||||
const setTheme = (theme: string) => {
|
||||
if (theme !== undefined) {
|
||||
localStorage.setItem("theme", theme);
|
||||
}
|
||||
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
const resetTheme = () => {
|
||||
localStorage.removeItem("theme");
|
||||
};
|
||||
|
||||
const getTheme = () => {
|
||||
let selectedTheme = defaultTheme;
|
||||
|
||||
if (localStorage.getItem("theme") != null) {
|
||||
selectedTheme = JSON.parse(localStorage.getItem("theme") || "{}");
|
||||
}
|
||||
|
||||
return selectedTheme;
|
||||
};
|
||||
|
||||
const selectedTheme = getTheme();
|
||||
|
||||
export { setTheme, resetTheme };
|
||||
|
||||
export default selectedTheme;
|
|
@ -1,13 +1,13 @@
|
|||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import App from './app';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import App from "./app";
|
||||
import * as serviceWorker from "./serviceWorker";
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
document.getElementById('root')
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
document.getElementById("root")
|
||||
);
|
||||
|
||||
// If you want your app to work offline and load faster, you can change
|
1
src/react-app-env.d.ts
vendored
Normal file
1
src/react-app-env.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/// <reference types="react-scripts" />
|
|
@ -1,142 +0,0 @@
|
|||
// This optional code is used to register a service worker.
|
||||
// register() is not called by default.
|
||||
|
||||
// This lets the app load faster on subsequent visits in production, and gives
|
||||
// it offline capabilities. However, it also means that developers (and users)
|
||||
// will only see deployed updates on subsequent visits to a page, after all the
|
||||
// existing tabs open on the page have been closed, since previously cached
|
||||
// resources are updated in the background.
|
||||
|
||||
// To learn more about the benefits of this model and instructions on how to
|
||||
// opt-in, read https://bit.ly/CRA-PWA
|
||||
|
||||
const isLocalhost = Boolean(
|
||||
window.location.hostname === 'localhost' ||
|
||||
// [::1] is the IPv6 localhost address.
|
||||
window.location.hostname === '[::1]' ||
|
||||
// 127.0.0.0/8 are considered localhost for IPv4.
|
||||
window.location.hostname.match(
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||
)
|
||||
);
|
||||
|
||||
export function register(config) {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
if (isLocalhost) {
|
||||
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||
checkValidServiceWorker(swUrl, config);
|
||||
|
||||
// Add some additional logging to localhost, pointing developers to the
|
||||
// service worker/PWA documentation.
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://bit.ly/CRA-PWA'
|
||||
);
|
||||
});
|
||||
} else {
|
||||
// Is not localhost. Just register service worker
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function registerValidSW(swUrl, config) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then((registration) => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker == null) {
|
||||
return;
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// At this point, the updated precached content has been fetched,
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
console.log(
|
||||
'New content is available and will be used when all ' +
|
||||
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
|
||||
);
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onUpdate) {
|
||||
config.onUpdate(registration);
|
||||
}
|
||||
} else {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.');
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onSuccess) {
|
||||
config.onSuccess(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl, config) {
|
||||
// Check if the service worker can be found. If it can't reload the page.
|
||||
fetch(swUrl, {
|
||||
headers: { 'Service-Worker': 'script' },
|
||||
})
|
||||
.then((response) => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (
|
||||
response.status === 404 ||
|
||||
(contentType != null &&
|
||||
contentType.indexOf('javascript') === -1)
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then((registration) => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Service worker found. Proceed as normal.
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready
|
||||
.then((registration) => {
|
||||
registration.unregister();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error.message);
|
||||
});
|
||||
}
|
||||
}
|
149
src/serviceWorker.ts
Normal file
149
src/serviceWorker.ts
Normal file
|
@ -0,0 +1,149 @@
|
|||
// This optional code is used to register a service worker.
|
||||
// register() is not called by default.
|
||||
|
||||
// This lets the app load faster on subsequent visits in production, and gives
|
||||
// it offline capabilities. However, it also means that developers (and users)
|
||||
// will only see deployed updates on subsequent visits to a page, after all the
|
||||
// existing tabs open on the page have been closed, since previously cached
|
||||
// resources are updated in the background.
|
||||
|
||||
// To learn more about the benefits of this model and instructions on how to
|
||||
// opt-in, read https://bit.ly/CRA-PWA
|
||||
|
||||
const isLocalhost = Boolean(
|
||||
window.location.hostname === 'localhost' ||
|
||||
// [::1] is the IPv6 localhost address.
|
||||
window.location.hostname === '[::1]' ||
|
||||
// 127.0.0.0/8 are considered localhost for IPv4.
|
||||
window.location.hostname.match(
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||
)
|
||||
);
|
||||
|
||||
type Config = {
|
||||
onSuccess?: (registration: ServiceWorkerRegistration) => void;
|
||||
onUpdate?: (registration: ServiceWorkerRegistration) => void;
|
||||
};
|
||||
|
||||
export function register(config?: Config) {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(
|
||||
process.env.PUBLIC_URL,
|
||||
window.location.href
|
||||
);
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
if (isLocalhost) {
|
||||
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||
checkValidServiceWorker(swUrl, config);
|
||||
|
||||
// Add some additional logging to localhost, pointing developers to the
|
||||
// service worker/PWA documentation.
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://bit.ly/CRA-PWA'
|
||||
);
|
||||
});
|
||||
} else {
|
||||
// Is not localhost. Just register service worker
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function registerValidSW(swUrl: string, config?: Config) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then(registration => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker == null) {
|
||||
return;
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// At this point, the updated precached content has been fetched,
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
console.log(
|
||||
'New content is available and will be used when all ' +
|
||||
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
|
||||
);
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onUpdate) {
|
||||
config.onUpdate(registration);
|
||||
}
|
||||
} else {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.');
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onSuccess) {
|
||||
config.onSuccess(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl: string, config?: Config) {
|
||||
// Check if the service worker can be found. If it can't reload the page.
|
||||
fetch(swUrl, {
|
||||
headers: { 'Service-Worker': 'script' }
|
||||
})
|
||||
.then(response => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (
|
||||
response.status === 404 ||
|
||||
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Service worker found. Proceed as normal.
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready
|
||||
.then(registration => {
|
||||
registration.unregister();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error.message);
|
||||
});
|
||||
}
|
||||
}
|
25
tsconfig.json
Normal file
25
tsconfig.json
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue