import React, { Fragment, useMemo, useCallback, useState } from 'react';
import PlayDisplay from "../components/PlayDisplay";
import { recentIncludes } from "../../core/Atomic";
import { useSearchParams } from "react-router-dom";
import { useGetRecentQuery } from "./recentDucks";
import Tooltip from "../components/Tooltip";
import { faQuestionCircle, faBug } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useCopyToClipboard } from '../components/copyToClipboardHook';
import clsx from "clsx";
import {patch} from 'jsondiffpatch';
const displayOpts = {
include: recentIncludes,
includeWeb: true
}
const apiTipContent =
Data that is directly returned by the Source API.
If you do not see your recent plays in this data it is likely the Source's data is lagging behind your
actual activity.
;
const tsTip =
(C) - Scrobble timestamped when listen was completed
(S) - Scrobble timestamped when listen was started
;
const recent = () => {
let [searchParams, setSearchParams] = useSearchParams();
const {
data = [],
error,
isLoading,
isSuccess
} = useGetRecentQuery({
name: searchParams.get('name'),
type: searchParams.get('type'),
upstream: searchParams.get('upstream')
});
const { copy, isCopied } = useCopyToClipboard();
const [copiedIndex, setIndex] = useState(null);
const copyActionCB = useCallback((obj, index) => {
copy(JSON.stringify(obj, null, 2));
setIndex(index);
},[copy, setIndex]);
const baseClass = ['mr-3'];
const isUpstream = searchParams.get('upstream') === '1';
const tipContents = useMemo(() => {
return
{isUpstream ? apiTipContent : null}
{tsTip}
}, [isUpstream]);
return (
Recently Played{isUpstream ? ' from Source API' : null}
{/*{isUpstream ?
Below is data directly returned by the Source API. MS uses : null}*/}
{isSuccess && !isLoading && data.length === 0 ? 'No recently played tracks!' : null}
{data.map(x => {
const classes = [...baseClass].concat(copiedIndex !== x.index ? ['underline','cursor-pointer'] : []);
// let last = x.meta.lifecycle.original;
// x.meta.lifecycle.steps = x.meta.lifecycle.steps.map(y => {
// if(y.patch !== undefined) {
// // @ts-ignore
// y.full = patch(last, y.patch);
// // @ts-ignore
// last = y.full;
// }
// return y;
// });
return
copyActionCB(x.meta.lifecycle, x.index)}>{copiedIndex === x.index ? 'Copied!' : }
})}
);
}
export default recent;