Skip to content

Commit

Permalink
Merge pull request #642 from mikecao/dev
Browse files Browse the repository at this point in the history
v1.17.0
  • Loading branch information
mikecao authored Apr 28, 2021
2 parents c5d2386 + 20dc768 commit 5ecaf55
Show file tree
Hide file tree
Showing 19 changed files with 854 additions and 628 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"es2020": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:react/recommended", "prettier", "prettier/react"],
"extends": ["eslint:recommended", "plugin:react/recommended", "prettier"],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
Expand Down
1 change: 1 addition & 0 deletions assets/chart-bar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions components/common/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ import styles from './Checkbox.module.css';
function Checkbox({ name, value, label, onChange }) {
const ref = useRef();

const onClick = () => ref.current.click();

return (
<div className={styles.container}>
<div className={styles.checkbox} onClick={() => ref.current.click()}>
<div className={styles.checkbox} onClick={onClick}>
{value && <Icon icon={<Check />} size="small" />}
</div>
<label className={styles.label} htmlFor={name}>
<label className={styles.label} htmlFor={name} onClick={onClick}>
{label}
</label>
<input
ref={ref}
className={styles.input}
type="checkbox"
name={name}
value={value}
defaultChecked={value}
onChange={onChange}
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions components/common/Checkbox.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

.label {
margin-left: 10px;
user-select: none; /* disable text selection when clicking to toggle the checkbox */
}

.input {
Expand Down
2 changes: 1 addition & 1 deletion components/forms/WebsiteEditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function WebsiteEditForm({ values, onSave, onClose }) {
</div>
</FormRow>
<FormRow>
<label></label>
<label />
<Field name="enable_share_url">
{({ field }) => (
<Checkbox
Expand Down
20 changes: 14 additions & 6 deletions components/layout/Header.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
padding: 0 15px;
}

.title {
padding: 0.5rem;
margin-bottom: 0.5rem;
}

.nav {
font-size: var(--font-size-normal);
flex-wrap: wrap;
Expand Down Expand Up @@ -102,6 +107,9 @@
.burger {
display: block;
/* color: #4a4a4a; */
background: none;
border: 1px solid var(--gray900);
border-radius: 4px;
cursor: pointer;
height: 3.25rem;
width: 3.25rem;
Expand All @@ -112,20 +120,20 @@
}

.burger span {
transform: translateX(-50%);
transform: translateX(25%);
padding: 1px 0px;
margin: 6px 0;
width: 20px;
width: 65%;
display: block;
background-color: white;
background-color: var(--gray900);
}

.burger div {
height: 100%;
color: white;
/* height: 100%; */
color: var(--gray900);
text-align: center;
margin: auto;
font-size: 1.5rem;
transform: translateX(-50%);
/* transform: translateX(-50%); */
}
}
17 changes: 10 additions & 7 deletions components/metrics/WebsiteChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function WebsiteChart({
domain,
stickyHeader = false,
showLink = false,
hideChart = false,
onDataLoad = () => {},
}) {
const shareToken = useShareToken();
Expand Down Expand Up @@ -91,13 +92,15 @@ export default function WebsiteChart({
<div className="row">
<div className="col">
{error && <ErrorMessage />}
<PageviewsChart
websiteId={websiteId}
data={chartData}
unit={unit}
records={getDateLength(startDate, endDate, unit)}
loading={loading}
/>
{!hideChart && (
<PageviewsChart
websiteId={websiteId}
data={chartData}
unit={unit}
records={getDateLength(startDate, endDate, unit)}
loading={loading}
/>
)}
</div>
</div>
</div>
Expand Down
37 changes: 27 additions & 10 deletions components/pages/WebsiteList.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import React from 'react';
import React, { useState } from 'react';
import { FormattedMessage } from 'react-intl';
import Link from 'components/common/Link';
import WebsiteChart from 'components/metrics/WebsiteChart';
import Page from 'components/layout/Page';
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
import Button from 'components/common/Button';
import useFetch from 'hooks/useFetch';
import Arrow from 'assets/arrow-right.svg';
import Chart from 'assets/chart-bar.svg';
import styles from './WebsiteList.module.css';

export default function WebsiteList({ userId }) {
const { data } = useFetch('/api/websites', { params: { user_id: userId } });
const [hideCharts, setHideCharts] = useState(false);

if (!data) {
return null;
}

return (
<Page>
{data.map(({ website_id, name, domain }) => (
<div key={website_id} className={styles.website}>
<WebsiteChart websiteId={website_id} title={name} domain={domain} showLink />
</div>
))}
{data.length === 0 && (
if (data.length === 0) {
return (
<Page>
<EmptyPlaceholder
msg={
<FormattedMessage
Expand All @@ -35,7 +33,26 @@ export default function WebsiteList({ userId }) {
<FormattedMessage id="message.go-to-settings" defaultMessage="Go to settings" />
</Link>
</EmptyPlaceholder>
)}
</Page>
);
}

return (
<Page>
<div className={styles.menubar}>
<Button icon={<Chart />} onClick={() => setHideCharts(!hideCharts)} />
</div>
{data.map(({ website_id, name, domain }) => (
<div key={website_id} className={styles.website}>
<WebsiteChart
websiteId={website_id}
title={name}
domain={domain}
hideChart={hideCharts}
showLink
/>
</div>
))}
</Page>
);
}
7 changes: 7 additions & 0 deletions components/pages/WebsiteList.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@
border-bottom: 0;
margin-bottom: 0;
}

.menubar {
display: flex;
align-items: center;
justify-content: flex-end;
padding-top: 10px;
}
8 changes: 7 additions & 1 deletion hooks/useTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { THEME_CONFIG } from 'lib/constants';
import { useEffect } from 'react';

export default function useTheme() {
const theme = useSelector(state => state.app.theme || getItem(THEME_CONFIG) || 'light');
const defaultTheme =
typeof window !== 'undefined'
? window?.matchMedia('prefers-color-scheme: dark')?.matches
? 'dark'
: 'light'
: 'light';
const theme = useSelector(state => state.app.theme || getItem(THEME_CONFIG) || defaultTheme);
const dispatch = useDispatch();

function saveTheme(value) {
Expand Down
1 change: 1 addition & 0 deletions lang/nl-NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"label.administrator": "Administrator",
"label.all": "Alles",
"label.all-websites": "Alle websites",
"label.all-events": "Alle gebeurtenissen",
"label.back": "Terug",
"label.cancel": "Annuleren",
"label.change-password": "Wachtwoord wijzigen",
Expand Down
1 change: 1 addition & 0 deletions lang/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"label.administrator": "Администратор",
"label.all": "Все",
"label.all-websites": "Все сайты",
"label.all-events": "Все события",
"label.back": "Назад",
"label.cancel": "Отменить",
"label.change-password": "Изменить пароль",
Expand Down
1 change: 1 addition & 0 deletions lang/uk-UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"label.administrator": "Адміністратор",
"label.all": "Всі",
"label.all-websites": "Всі сайти",
"label.all-events": "Всі події",
"label.back": "Назад",
"label.cancel": "Відмінити",
"label.change-password": "Змінити пароль",
Expand Down
6 changes: 3 additions & 3 deletions lib/crypto.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import crypto from 'crypto';
import { v4, v5, validate } from 'uuid';
import bcrypt from 'bcrypt';
import bcrypt from 'bcryptjs';
import { JWT, JWE, JWK } from 'jose';
import { startOfMonth } from 'date-fns';

Expand Down Expand Up @@ -40,11 +40,11 @@ export function getRandomChars(n) {
}

export async function hashPassword(password) {
return bcrypt.hash(password, SALT_ROUNDS);
return bcrypt.hashSync(password, SALT_ROUNDS);
}

export async function checkPassword(password, hash) {
return bcrypt.compare(password, hash);
return bcrypt.compareSync(password, hash);
}

export async function createToken(payload) {
Expand Down
2 changes: 1 addition & 1 deletion lib/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const urlFilter = (data, { raw }) => {
return `${pathname}${search}`;
}

return removeTrailingSlash(pathname);
return pathname;
} catch {
return null;
}
Expand Down
6 changes: 5 additions & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
MOBILE_SCREEN_WIDTH,
} from './constants';

let lookup;

export function getIpAddress(req) {
// Cloudflare
if (req.headers['cf-connecting-ip']) {
Expand Down Expand Up @@ -61,7 +63,9 @@ export async function getCountry(req, ip) {
}

// Database lookup
const lookup = await maxmind.open(path.resolve('./public/geo/GeoLite2-Country.mmdb'));
if (!lookup) {
lookup = await maxmind.open(path.resolve('./public/geo/GeoLite2-Country.mmdb'));
}

const result = lookup.get(ip);

Expand Down
Loading

1 comment on commit 5ecaf55

@vercel
Copy link

@vercel vercel bot commented on 5ecaf55 Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.