Skip to content

Commit

Permalink
Added object dump
Browse files Browse the repository at this point in the history
  • Loading branch information
matvp91 committed Dec 10, 2024
1 parent 03ab89c commit a0f4ae7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 71 deletions.
Binary file modified bun.lockb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@ import type { ReactNode } from "react";

type Data = string | number | object | null | undefined;

interface DataDump2Props {
data: object;
parent?: string;
}

export function DataDump2({
name,
data,
parent,
redacted,
}: {
interface ObjectDumpProps {
name?: string | number;
data: Data | Data[];
parent?: string;
redacted?: string[];
}) {
}

export function ObjectDump({ name, data, parent, redacted }: ObjectDumpProps) {
const id = `${parent}.${name}`;

for (const check of redacted ?? []) {
Expand All @@ -32,7 +24,7 @@ export function DataDump2({
<Label name={name} />
{"["}
{data.map((child, index) => (
<DataDump2
<ObjectDump
key={`${id}.${index}`}
parent={`${id}.${index}`}
name={index}
Expand All @@ -51,7 +43,7 @@ export function DataDump2({
{"{"}
{Object.entries(data).map(([name, value]) => {
return (
<DataDump2
<ObjectDump
key={`${id}.${name}`}
parent={`${id}.${name}`}
name={name}
Expand All @@ -70,54 +62,6 @@ export function DataDump2({
return null;
}

export function DataDump2_({ data }: DataDump2Props) {
return (
<div className="text-sm">
<Tree data={data} />
</div>
);
}

function Tree({ data, parent = "" }: { data: object; parent?: string }) {
return Object.entries(data).map(([name, value]) => {
const id = `${parent}.${name}`;

if (id.includes("levels") || id.includes(".track")) {
return null;
}

if (value !== Object(value)) {
return <Primitive key={id} name={name} value={value} />;
}

if (Array.isArray(value)) {
return (
<div key={id} className="ml-2">
<Label name={name} />
{"["}
{value.map((child, index) => (
<Tree key={`${id}.${index}`} parent={id} data={child} />
))}
{"]"}
</div>
);
}

if (typeof value === "object") {
return (
<div key={id} className="ml-2">
<Label name={name} />
{"{"}
<Tree parent={id} data={value} />
{"}"}
</div>
);
}

return null;
});
}

function Primitive({ name, value }: { name: string | number; value: Data }) {
let className = "";
let child: ReactNode = String(value);
Expand Down
18 changes: 12 additions & 6 deletions packages/app/src/components/Player.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Card } from "@nextui-org/react";
import { HlsPlayer } from "@superstreamer/player";
import { useEffect, useRef, useState } from "react";
import { DataDump2 } from "./DataDump2";
import { ObjectDump } from "./ObjectDump";

interface PlayerProps {
url?: string | null;
Expand Down Expand Up @@ -47,12 +47,18 @@ export function Player({ url }: PlayerProps) {
}, [player, url]);

return (
<div className="flex h-full gap-4">
<div className="grow">
<div className="relative aspect-video bg-black" ref={ref} />
<div className="flex flex-col grow gap-4 h-full">
<div className="flex items-center">
<div
className="relative aspect-video bg-black max-h-[300px] grow"
ref={ref}
/>
</div>
<Card className="w-full h-full max-w-[360px] p-4 text-sm overflow-y-auto">
<DataDump2 data={state} redacted={["levels", ".track"]} />
<Card className="grow w-full h-full p-4 text-sm overflow-y-auto">
<ObjectDump
data={state}
redacted={["levels", ".track", "asset.player"]}
/>
</Card>
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/components/Uniqolor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export function Uniqolor({ value }: UniqolorProps) {
function hexToRGB(hex: string, alpha: number) {
return (
"rgba(" +
parseInt(hex.slice(1, 3), 16) +
Number.parseInt(hex.slice(1, 3), 16) +
", " +
parseInt(hex.slice(3, 5), 16) +
Number.parseInt(hex.slice(3, 5), 16) +
", " +
parseInt(hex.slice(5, 7), 16) +
Number.parseInt(hex.slice(5, 7), 16) +
", " +
alpha +
")"
Expand Down
4 changes: 4 additions & 0 deletions packages/player/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ export class State implements StateProperties {
const oldDuration = target.duration;
target.duration = preciseFloat(timing.duration);

if (target.time > target.duration) {
target.time = target.duration;
}

return oldTime !== target.time || oldDuration !== target.duration;
}

Expand Down

0 comments on commit a0f4ae7

Please sign in to comment.