Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add editorconfig #38

Merged
merged 6 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
indent_size = unset
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test

on:
push:
pull_request:

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout commit
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
cache: npm

- name: Install dependencies
run: npm ci
env:
NODE_ENV: development
CI: true

- name: Run linting
run: npm run lint

- name: Build extension
run: npm run build
3 changes: 2 additions & 1 deletion .idea/scopes/Extension.xml

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

1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.13.0
38 changes: 19 additions & 19 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true,
"**/*.css": true
},
"hide-files.files": [],
"workbench.colorCustomizations": {
"activityBar.background": "#3A254A",
"titleBar.activeBackground": "#513368",
"titleBar.activeForeground": "#FCFBFD"
}
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true,
"**/*.css": true
},
"hide-files.files": [],
"workbench.colorCustomizations": {
"activityBar.background": "#3A254A",
"titleBar.activeBackground": "#513368",
"titleBar.activeForeground": "#FCFBFD"
}
}
2 changes: 1 addition & 1 deletion Alveus Ambassadors.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@
"name": "Alveus Animals",
"usingRandomFrontendHostingPort": false,
"version": 3
}
}
21 changes: 21 additions & 0 deletions package-lock.json

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

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "npm-run-all --parallel watch serve",
"start": "npm-run-all --parallel sass:watch serve",
"serve": "env-cmd -f .env react-app-rewired start",
"watch": "sass --no-source-map --watch src:src",
"build": "react-app-rewired build",
"sass:build": "sass --no-source-map src:src",
"sass:watch": "npm run sass:build -- --watch",
"build": "npm run sass:build && react-app-rewired build",
"test": "react-app-rewired test",
"lint": "npm run lint:editorconfig",
"lint:editorconfig": "editorconfig-checker",
"eject": "react-scripts eject"
},
"eslintConfig": {
Expand All @@ -60,6 +63,7 @@
"devDependencies": {
"@types/cors": "^2.8.12",
"@types/tmi.js": "^1.8.2",
"editorconfig-checker": "^5.0.1",
"react-app-rewire-multiple-entry": "^2.2.2",
"react-app-rewired": "^2.2.1"
}
Expand Down
10 changes: 5 additions & 5 deletions src/index.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//Global styles
@import './variables.scss';

*{
margin: 0;
padding: 0;
* {
margin: 0;
padding: 0;
}

body {
font-family: $font-family;
color: $primary-text;

display: flex;
justify-content: center;
overflow-x: hidden; // no horizontal scrollbar
}
}
168 changes: 83 additions & 85 deletions src/pages/overlay/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,101 +9,99 @@ import OverlaySettings from "./components/overlaySettings/OverlaySettings"
import styles from "./App.module.css"

interface Settings {
disableChatPopup: boolean
disableChatPopup: boolean
}

export default function App(){
const [overlaySettings, setOverlaySettings] = useState<Settings>(() => {
// Load settings from local storage, merging with defaults
const settings = JSON.parse(localStorage.getItem("settings") || "{}")
return {
disableChatPopup: false,
...settings
}
})
export default function App() {
const [overlaySettings, setOverlaySettings] = useState<Settings>(() => {
// Load settings from local storage, merging with defaults
const settings = JSON.parse(localStorage.getItem("settings") || "{}")
return {
disableChatPopup: false,
...settings
}
})

useEffect(() => {
// save settings to local storage
localStorage.setItem("settings", JSON.stringify(overlaySettings))
}, [overlaySettings])
useEffect(() => {
// save settings to local storage
localStorage.setItem("settings", JSON.stringify(overlaySettings))
}, [overlaySettings])

const toggleDisableChatPopup = useCallback(() => {
setOverlaySettings((current: Settings) => ({
...current,
disableChatPopup: !current.disableChatPopup
}))
}, [])
const toggleDisableChatPopup = useCallback(() => {
setOverlaySettings((current: Settings) => ({
...current,
disableChatPopup: !current.disableChatPopup
}))
}, [])

// Show/hide the overlay based on mouse movement
const appRef = useRef<HTMLDivElement>(null)
const sleepTimer = useRef<NodeJS.Timeout | undefined>(undefined)
const [sleeping, setSleeping] = useState(false)
// Show/hide the overlay based on mouse movement
const appRef = useRef<HTMLDivElement>(null)
const sleepTimer = useRef<NodeJS.Timeout | undefined>(undefined)
const [sleeping, setSleeping] = useState(false)

// Allow children to know when we have been woken up
const [awoken, setAwoken] = useState<(() => void)[]>([])
const addAwoken = useCallback((callback: () => void) => {
setAwoken(current => [...current, callback])
}, [])
const removeAwoken = useCallback((callback: () => void) => {
setAwoken(current => current.filter(c => c !== callback))
}, [])
const awokenObj = useMemo(() => ({ add: addAwoken, remove: removeAwoken }), [addAwoken, removeAwoken])
// Allow children to know when we have been woken up
const [awoken, setAwoken] = useState<(() => void)[]>([])
const addAwoken = useCallback((callback: () => void) => {
setAwoken(current => [...current, callback])
}, [])
const removeAwoken = useCallback((callback: () => void) => {
setAwoken(current => current.filter(c => c !== callback))
}, [])
const awokenObj = useMemo(() => ({ add: addAwoken, remove: removeAwoken }), [addAwoken, removeAwoken])

// Wake the overlay for x milliseconds
const wake = useCallback((time: number) => {
setSleeping(false)
awoken.forEach(fn => fn())
if (sleepTimer.current) clearTimeout(sleepTimer.current)
sleepTimer.current = setTimeout(() => {
setSleeping(true)
}, time)
}, [awoken])
// Wake the overlay for x milliseconds
const wake = useCallback((time: number) => {
setSleeping(false)
awoken.forEach(fn => fn())
if (sleepTimer.current) clearTimeout(sleepTimer.current)
sleepTimer.current = setTimeout(() => {
setSleeping(true)
}, time)
}, [awoken])

// When the user interacts, have a 5s timeout before hiding the overlay
const interacted = useCallback(() => {
wake(5000)
}, [wake])
// When the user interacts, have a 5s timeout before hiding the overlay
const interacted = useCallback(() => {
wake(5000)
}, [wake])

// Bind a capturing event listener for scrolling (so we can see scrolling for children)
useEffect(() => {
appRef.current?.addEventListener("scroll", interacted, true)
return () => appRef.current?.removeEventListener("scroll", interacted, true)
}, [interacted])
// Bind a capturing event listener for scrolling (so we can see scrolling for children)
useEffect(() => {
if (!appRef.current) return
const node = appRef.current
node.addEventListener("scroll", interacted, true)
return () => node.removeEventListener("scroll", interacted, true)
}, [interacted])

// Immediately sleep the overlay
const sleep = useCallback(() => {
setSleeping(true)
if (sleepTimer.current) clearTimeout(sleepTimer.current)
}, [])
// Immediately sleep the overlay
const sleep = useCallback(() => {
setSleeping(true)
if (sleepTimer.current) clearTimeout(sleepTimer.current)
}, [])

// When we unmount, clear the sleep timer
useEffect(() => () => {
if (sleepTimer.current) clearTimeout(sleepTimer.current)
}, [])
// When we unmount, clear the sleep timer
useEffect(() => () => {
if (sleepTimer.current) clearTimeout(sleepTimer.current)
}, [])

return (
<div
ref={appRef}
className={`${styles.app} ${sleeping ? styles.hidden : styles.visible}`}
onMouseEnter={interacted}
onMouseMove={interacted}
onMouseLeave={sleep}
>
<Overlay
sleeping={sleeping}
awoken={awokenObj}
wake={wake}
settings={{
disableChatPopup: overlaySettings.disableChatPopup
}}
/>
<OverlaySettings
sleeping={sleeping}
settings={{
disableChatPopup: overlaySettings.disableChatPopup
}}
toggleDisableChatPopup={toggleDisableChatPopup}
/>
</div>
)
return (
<div
ref={appRef}
className={`${styles.app} ${sleeping ? styles.hidden : styles.visible}`}
onMouseEnter={interacted}
onMouseMove={interacted}
onMouseLeave={sleep}
>
<Overlay
sleeping={sleeping}
awoken={awokenObj}
wake={wake}
settings={overlaySettings}
/>
<OverlaySettings
sleeping={sleeping}
settings={overlaySettings}
toggleDisableChatPopup={toggleDisableChatPopup}
/>
</div>
)
}
Loading