diff --git a/src/equicordplugins/spotifyActivityToggle/index.tsx b/src/equicordplugins/spotifyActivityToggle/index.tsx index a9f3b2831..ebee29f76 100644 --- a/src/equicordplugins/spotifyActivityToggle/index.tsx +++ b/src/equicordplugins/spotifyActivityToggle/index.tsx @@ -4,12 +4,11 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -import { definePluginSettings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { EquicordDevs } from "@utils/constants"; -import definePlugin, { OptionType } from "@utils/types"; +import definePlugin from "@utils/types"; import { findComponentByCodeLazy } from "@webpack"; -import { Constants, React, RestAPI } from "@webpack/common"; +import { Constants, React, RestAPI, useEffect, useState } from "@webpack/common"; const Button = findComponentByCodeLazy(".NONE,disabled:", ".PANEL_BUTTON"); @@ -35,55 +34,54 @@ function makeSpotifyIcon(enabled: boolean) { ); } -async function setSpotifyActivity(value: boolean) { - const { body } = await RestAPI.get({ - url: Constants.Endpoints.CONNECTIONS - }); - - if (!body) return; - const spotifyId = body.find(conn => conn.type === "spotify")?.id; - - await RestAPI.patch({ - url: Constants.Endpoints.CONNECTION("spotify", spotifyId), - body: { - show_activity: value, - }, - }); -} - function SpotifyActivityToggleButton() { - const { spotifyConnection } = settings.store; + const [loading, setLoading] = useState(true); + const [id, setId] = useState(null); + const [showActivity, setShowActivity] = useState(null); + + useEffect(() => { + (async () => { + const { body } = await RestAPI.get({ + url: Constants.Endpoints.CONNECTIONS, + }); + if (!body) return; + + const spotifyConn = body.find(c => c.type === "spotify"); + if (spotifyConn) { + setId(spotifyConn.id); + setShowActivity(spotifyConn.show_activity); + } + setLoading(false); + })(); + }, []); + + if (loading || !id || showActivity === null) return null; return (