-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for randomized backgounds
- Loading branch information
1 parent
20699be
commit 2c0358a
Showing
127 changed files
with
212 additions
and
79 deletions.
There are no files selected for viewing
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { useEffect, useState } from 'react'; | ||
import PauseIcon from '@mui/icons-material/Pause'; | ||
import PlayArrowIcon from '@mui/icons-material/PlayArrow'; | ||
import RefreshIcon from '@mui/icons-material/Refresh'; | ||
import { GlobalStyles, Stack } from '@mui/material'; | ||
import IconButton from '@mui/material/IconButton'; | ||
import Tooltip from '@mui/material/Tooltip'; | ||
|
||
function getImageUrl(name: string | number) { | ||
// note that this does not include files in subdirectories | ||
if (import.meta.env.MODE === 'development') { | ||
return `/public/bg/${name}.png`; | ||
} else { | ||
return `/bg/${name}`; | ||
} | ||
} | ||
|
||
const randBGNum = () => { | ||
const numberOfBgImages = 115; | ||
|
||
return Math.floor(Math.random() * numberOfBgImages); | ||
}; | ||
|
||
const getPausedState = () => { | ||
const bgPaused = localStorage.getItem('bg_paused'); | ||
if (!bgPaused) { | ||
return false; | ||
} | ||
|
||
return bgPaused == 'true'; | ||
}; | ||
|
||
const savePausedState = (state: boolean) => { | ||
localStorage.setItem('bg_paused', state.toString()); | ||
}; | ||
|
||
const saveBGNum = (num: number) => { | ||
localStorage.setItem('bg_num', num.toString()); | ||
}; | ||
|
||
const getBGNum = () => { | ||
return Number(localStorage.getItem('bg_num')); | ||
}; | ||
|
||
export const BackgroundImageProvider = () => { | ||
const [paused, setPaused] = useState(getPausedState()); | ||
const [num, setNum] = useState(() => { | ||
if (paused) { | ||
return getBGNum(); | ||
} | ||
return randBGNum(); | ||
}); | ||
|
||
const setBG = (num: number) => { | ||
setNum(num); | ||
saveBGNum(num); | ||
}; | ||
|
||
const togglePaused = () => { | ||
setPaused((prev) => { | ||
savePausedState(!prev); | ||
return !prev; | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
saveBGNum(num); | ||
}, [num]); | ||
|
||
return ( | ||
<> | ||
<div | ||
style={{ | ||
position: 'absolute', | ||
top: 50, | ||
right: 0 | ||
}} | ||
> | ||
<Stack direction={'row'} spacing={1}> | ||
<Tooltip title={'Randomly select a background image'}> | ||
<IconButton | ||
onClick={() => { | ||
setBG(randBGNum()); | ||
}} | ||
> | ||
<RefreshIcon /> | ||
</IconButton> | ||
</Tooltip> | ||
<Tooltip title={'Pause randomly selecting new backgrounds'}> | ||
<IconButton | ||
onClick={() => { | ||
togglePaused(); | ||
}} | ||
> | ||
{paused ? <PlayArrowIcon /> : <PauseIcon />} | ||
</IconButton> | ||
</Tooltip> | ||
</Stack> | ||
</div> | ||
<GlobalStyles | ||
styles={{ | ||
body: { | ||
backgroundColor: '#fff', | ||
backgroundImage: `url(${getImageUrl(num)})`, | ||
backgroundRepeat: 'repeat' | ||
} | ||
}} | ||
/> | ||
</> | ||
); | ||
}; |
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
Diff not rendered.
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
Oops, something went wrong.