-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Showing
34 changed files
with
362 additions
and
57 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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,31 @@ | ||
import { v4 as uuid } from 'uuid'; | ||
import { postHogId } from './posthog'; | ||
import { sendHeartbeat } from './send-heartbeat'; | ||
import { AppDb } from '../db/db'; | ||
|
||
export interface AppInfo { | ||
_id: string; | ||
value: string; | ||
} | ||
|
||
export const AppInfos = () => AppDb.db.collection<AppInfo>('app-info'); | ||
|
||
const appInfoKey = 'install_id'; | ||
|
||
export async function initPosthog() { | ||
// id | ||
const appInfo = await AppInfos().findOne({ _id: appInfoKey }); | ||
if (appInfo) { | ||
postHogId.id = appInfo.value; | ||
} else { | ||
postHogId.id = uuid(); | ||
await AppInfos().insertOne({ | ||
_id: appInfoKey, | ||
value: postHogId.id, | ||
}); | ||
} | ||
|
||
// heartbeat | ||
sendHeartbeat(); | ||
setInterval(sendHeartbeat, 86400000); // every day | ||
} |
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,14 @@ | ||
import PostHog from 'posthog-node'; | ||
import { env } from '../env/env'; | ||
|
||
export const postHog = new PostHog( | ||
'-BcCDFlG6nIchkTWROH5C3iplPWRjdEwrb6wpQKKwDg', | ||
{ | ||
host: 'https://posthog.meli.sh', | ||
enable: env.MELI_POSTHOG_ENABLED, | ||
}, | ||
); | ||
|
||
export const postHogId = { | ||
id: undefined, | ||
}; |
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,15 @@ | ||
import { postHog, postHogId } from './posthog'; | ||
import { Logger } from '../commons/logger/logger'; | ||
|
||
const logger = new Logger('app.posthog:sendHeartbeat'); | ||
|
||
export function sendHeartbeat() { | ||
logger.debug('sending heartbeat'); | ||
postHog.capture({ | ||
event: 'heartbeat', | ||
distinctId: postHogId.id, | ||
properties: { | ||
version: BUILD_INFO.version, | ||
}, | ||
}); | ||
} |
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
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
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
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,30 @@ | ||
@import "src/styles/variables"; | ||
|
||
.container { | ||
padding: 3rem; | ||
background: linear-gradient(180deg, #200c39, #220f3f); | ||
color: $light; | ||
} | ||
|
||
.logos { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.message { | ||
margin-top: 3rem; | ||
} | ||
|
||
.posthogLogo { | ||
height: 35px; | ||
} | ||
|
||
.plus { | ||
margin: 0 2rem; | ||
font-size: 2rem; | ||
} | ||
|
||
.meliLogo { | ||
height: 35px; | ||
} |
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,37 @@ | ||
import React from "react"; | ||
import { ExternalLink } from '../commons/components/ExternalLink'; | ||
import { useLocalStorage } from '../utils/use-local-storage'; | ||
import styles from './PosthogWarning.module.scss'; | ||
import classNames from 'classnames'; | ||
import { AppModal } from '../commons/components/modals/AppModal'; | ||
import postHogLogo from './posthog.svg'; | ||
import meliLogo from './meli.svg'; | ||
import { faPlus } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
|
||
export function PosthogWarning({ className }: { | ||
className?: string; | ||
}) { | ||
const [show, setShow] = useLocalStorage('posthog.warning.show', true); | ||
return ( | ||
<AppModal isOpen={show}> | ||
<div className={classNames(styles.container, className)}> | ||
<div className={styles.logos}> | ||
<img src={postHogLogo} alt="posthog" className={styles.posthogLogo}/> | ||
<FontAwesomeIcon icon={faPlus} className={styles.plus}/> | ||
<img src={meliLogo} alt="meli" className={styles.meliLogo}/> | ||
</div> | ||
<div className="mt-4 text-center"> | ||
We've added <ExternalLink href="https://github.com/PostHog/posthog">PostHog</ExternalLink> to Meli. | ||
It helps us know which versions are being used in production and how many active installations are being deployed across the world. | ||
You may opt-out of this feature. Please review <ExternalLink href="https://github.com/getmeli/meli/issues/220">this thread</ExternalLink> for more info. | ||
</div> | ||
<div className="mt-4 text-center"> | ||
<button type="button" className="btn btn-success" onClick={() => setShow(false)}> | ||
I've read the thread | ||
</button> | ||
</div> | ||
</div> | ||
</AppModal> | ||
) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,3 @@ | ||
.blur { | ||
filter: blur(8px); | ||
} |
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,32 @@ | ||
import React, { createContext, useContext, useState } from "react"; | ||
import styles from './BlurProvider.module.scss'; | ||
import classNames from 'classnames'; | ||
|
||
interface Context { | ||
isBlurred: boolean; | ||
blur: () => void; | ||
unblur: () => void; | ||
} | ||
|
||
const context = createContext(undefined); | ||
export const useBlur = () => useContext<Context>(context); | ||
|
||
export function BlurProvider({ children, ...props }) { | ||
const [enabled, setEnabled] = useState(false); | ||
return ( | ||
<context.Provider | ||
value={{ | ||
isBlurred: enabled, | ||
blur: () => setEnabled(true), | ||
unblur: () => setEnabled(false), | ||
}} | ||
{...props} | ||
> | ||
<div className={classNames({ | ||
[styles.blur]: enabled, | ||
})}> | ||
{children} | ||
</div> | ||
</context.Provider> | ||
) | ||
} |
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,43 @@ | ||
import { useState } from 'react'; | ||
|
||
function readFromStorage(key: string): any { | ||
try { | ||
const item = localStorage.getItem(key); | ||
return JSON.parse(item); | ||
} catch (e) { | ||
console.log(`Could not read ${key} from local storage`, e); | ||
return undefined; | ||
} | ||
} | ||
|
||
function writeToStorage(key: string, value: any): void { | ||
try { | ||
const val = JSON.stringify(value); | ||
localStorage.setItem(key, val); | ||
} catch (e) { | ||
console.log(`Could not write ${key} to local storage`, value, e); | ||
} | ||
} | ||
|
||
function storageHasKey(key: string): boolean { | ||
return !!localStorage.getItem(key); | ||
} | ||
|
||
function init(key: string, value: any): any { | ||
if (storageHasKey(key)) { | ||
return readFromStorage(key); | ||
} | ||
writeToStorage(key, value); | ||
return value; | ||
} | ||
|
||
export function useLocalStorage<T>(key: string, initialValue?: T): [T, (value: T) => void] { | ||
const [value, setValue] = useState<T>(init(key, initialValue)); | ||
|
||
const setValueProxy = (newValue: T) => { | ||
setValue(newValue); | ||
writeToStorage(key, newValue); | ||
}; | ||
|
||
return [value, setValueProxy]; | ||
} |