My personal site hosted @ https://indexx.dev

feat: update music widget visualizer

Changed files
+9 -15
src
components
+9 -15
src/components/jsx/Tealfm.jsx
···
export default function Tealfm() {
const [data, setData] = useState(null);
const [error, setError] = useState(null);
+
const [isCurrentlyPlaying, setIsCurrentlyPlaying] = useState(false);
useEffect(() => {
const fetchStatus = async () => {
···
const lastPlayedCollection = "fm.teal.alpha.feed.play";
try {
-
// --- 1. Attempt to fetch the actor status record ---
const statusUrl =
`https://pds.indexx.dev/xrpc/com.atproto.repo.getRecord?repo=${repo}&collection=${statusCollection}&rkey=self`;
const statusRes = await fetch(statusUrl);
···
const statusData = await statusRes.json();
const statusValue = statusData?.value;
-
const nowTimestamp = Math.floor(Date.now() / 1000); // Current time in seconds
+
const nowTimestamp = Math.floor(Date.now() / 1000);
const isExpired = statusValue?.expiry &&
nowTimestamp > parseInt(statusValue.expiry, 10);
···
let status;
-
// Check if the status is valid (not expired and not empty)
if (statusValue && !isExpired && !isItemEmpty) {
-
// Status is valid, use it
const latest = statusValue.item;
status = {
···
artist: latest.artists.map((artist) =>
artist.artistName
).join(", "),
-
albumArt: latest.releaseMbId
-
? `https://coverartarchive.org/release/${latest.releaseMbId}/front-500`
-
: "/default-album-art.png", // Fallback image needed if not present
-
createdAt: parseInt(statusValue.time, 10) * 1000, // Convert seconds to milliseconds
+
createdAt: parseInt(statusValue.time, 10) * 1000,
link: latest.originUrl ?? "",
};
setData(status);
-
return; // Exit if a valid status is found
+
setIsCurrentlyPlaying(true);
+
return;
}
-
// --- 2. If status is expired or empty, fetch the last played record (Original Logic) ---
console.log(
"Status expired or empty. Falling back to last played record.",
);
···
link: latest.originUrl ?? "",
};
setData(status);
+
setIsCurrentlyPlaying(false);
} else {
console.log("No records found in last played collection.");
-
// Optionally set a specific state for 'no data found'
+
setIsCurrentlyPlaying(false);
}
} catch (err) {
console.error("Fetch failed:", err);
setError(err.message);
+
setIsCurrentlyPlaying(false);
}
};
···
if (error) return <span>Error: {error}</span>;
if (!data) return null;
-
// --- Time Ago and Styling Logic (Unchanged) ---
let timeAgo = "";
let oldStatusClasses = "";
-
// data.createdAt is either a string (from listRecords) or a number (from getRecord)
const date = new Date(data.createdAt);
const now = new Date();
const diff = now.getTime() - date.getTime();
···
oldStatusClasses = days > 3
? "opacity-75 text-decoration-line-through"
: "";
-
// --- End Time Ago and Styling Logic ---
return (
<a
···
target="_blank"
className={oldStatusClasses}
>
-
<AudioVisualizer isSilent={!data.nowPlaying} />
+
<AudioVisualizer isSilent={!isCurrentlyPlaying} />
<div
style={{
display: "flex",