···
export default function Tealfm() {
const [data, setData] = useState(null);
const [error, setError] = useState(null);
7
+
const [isCurrentlyPlaying, setIsCurrentlyPlaying] = useState(false);
const fetchStatus = async () => {
···
const lastPlayedCollection = "fm.teal.alpha.feed.play";
15
-
// --- 1. Attempt to fetch the actor status record ---
`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;
26
-
const nowTimestamp = Math.floor(Date.now() / 1000); // Current time in seconds
26
+
const nowTimestamp = Math.floor(Date.now() / 1000);
const isExpired = statusValue?.expiry &&
nowTimestamp > parseInt(statusValue.expiry, 10);
···
34
-
// Check if the status is valid (not expired and not empty)
if (statusValue && !isExpired && !isItemEmpty) {
36
-
// Status is valid, use it
const latest = statusValue.item;
···
artist: latest.artists.map((artist) =>
44
-
albumArt: latest.releaseMbId
45
-
? `https://coverartarchive.org/release/${latest.releaseMbId}/front-500`
46
-
: "/default-album-art.png", // Fallback image needed if not present
47
-
createdAt: parseInt(statusValue.time, 10) * 1000, // Convert seconds to milliseconds
42
+
createdAt: parseInt(statusValue.time, 10) * 1000,
link: latest.originUrl ?? "",
51
-
return; // Exit if a valid status is found
46
+
setIsCurrentlyPlaying(true);
54
-
// --- 2. If status is expired or empty, fetch the last played record (Original Logic) ---
"Status expired or empty. Falling back to last played record.",
···
link: latest.originUrl ?? "",
82
+
setIsCurrentlyPlaying(false);
console.log("No records found in last played collection.");
89
-
// Optionally set a specific state for 'no data found'
85
+
setIsCurrentlyPlaying(false);
console.error("Fetch failed:", err);
90
+
setIsCurrentlyPlaying(false);
···
if (error) return <span>Error: {error}</span>;
103
-
// --- Time Ago and Styling Logic (Unchanged) ---
let oldStatusClasses = "";
107
-
// data.createdAt is either a string (from listRecords) or a number (from getRecord)
const date = new Date(data.createdAt);
const diff = now.getTime() - date.getTime();
···
oldStatusClasses = days > 3
? "opacity-75 text-decoration-line-through"
124
-
// --- End Time Ago and Styling Logic ---
···
className={oldStatusClasses}
133
-
<AudioVisualizer isSilent={!data.nowPlaying} />
127
+
<AudioVisualizer isSilent={!isCurrentlyPlaying} />