mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
added useRandomFeaturedWallpaperUrl
hook
This commit is contained in:
parent
b45091ce6d
commit
997685dac9
@ -0,0 +1,26 @@
|
|||||||
|
import React from "react"
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
const [wallpaperData, setWallpaperData] = React.useState(null)
|
||||||
|
|
||||||
|
const setRandomWallpaper = async () => {
|
||||||
|
const { data: featuredWallpapers } = await app.cores.api.customRequest({
|
||||||
|
method: "GET",
|
||||||
|
url: "/featured_wallpapers"
|
||||||
|
}).catch((err) => {
|
||||||
|
console.error(err)
|
||||||
|
return []
|
||||||
|
})
|
||||||
|
|
||||||
|
// get random wallpaper from array
|
||||||
|
const randomWallpaper = featuredWallpapers[Math.floor(Math.random() * featuredWallpapers.length)]
|
||||||
|
|
||||||
|
setWallpaperData(randomWallpaper)
|
||||||
|
}
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
setRandomWallpaper()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return wallpaperData
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user