hooks#useAnalyzer TypeScript Examples

The following examples show how to use hooks#useAnalyzer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx    From livepeer-com with MIT License 5 votes vote down vote up
Logger = ({ stream, ...props }: { stream: Stream }) => {
  const { getEvents } = useAnalyzer();

  const { user } = useApi();
  const userIsAdmin = user && user.admin;

  const [logs, setLogs] = useState<LogData[]>([]);
  const addLogs = (newLogs: LogData[]) =>
    setLogs((currLogs) => {
      let logs = [...currLogs, ...newLogs];
      if (logs.length > maxLogs) {
        logs = logs.slice(logs.length - maxLogs);
      }
      return logs;
    });

  const handleEvent = createEventHandler();
  useEffect(() => {
    setLogs([]);
    if (!stream?.region) return;

    const handler = (evt: events.Any) => addLogs(handleEvent(evt, userIsAdmin));
    const from = Date.now() - pastLogsLookback;
    return getEvents(stream.region, stream.id, handler, from);
  }, [stream?.region, stream?.id, handleEvent]);

  return (
    <Box {...props}>
      <Box
        css={{
          borderBottom: "1px solid",
          borderColor: "$neutral6",
          pb: "$1",
          mb: "$4",
          width: "100%",
        }}>
        <Heading size="1" css={{ fontWeight: 500, mb: "$1" }}>
          Logs
        </Heading>
      </Box>
      <Box
        css={{
          overflow: "scroll",
          p: "$4",
          bc: "$neutral3",
          height: 300,
          borderRadius: 6,
        }}>
        {!logs.length ? (
          <Box css={{ fontSize: "$1", fontFamily: "$mono" }}>
            Waiting for events...
          </Box>
        ) : (
          logs.map((log) => <Log {...log} />)
        )}
      </Box>
    </Box>
  );
}
Example #2
Source File: index.tsx    From livepeer-com with MIT License 5 votes vote down vote up
StreamDetails = () => {
  const router = useRouter();
  const queryClient = useQueryClient();
  const { getStream } = useApi();
  const { getHealth } = useAnalyzer();
  const [currentTab, setCurrentTab] = useState<"Overview" | "Health">(
    "Overview"
  );

  const { query } = router;
  const id = query.id as string;

  const { data: stream } = useQuery([id], () => getStream(id), {
    refetchInterval,
  });

  const invalidateStream = useCallback(
    (optimistic?: Stream) => {
      if (optimistic) {
        queryClient.setQueryData([id], optimistic);
      }
      return queryClient.invalidateQueries([id]);
    },
    [queryClient, id]
  );

  const { data: streamHealth } = useQuery({
    queryKey: ["health", stream?.region, stream?.id, stream?.isActive],
    queryFn: async () =>
      !stream?.region ? null : await getHealth(stream.region, stream.id),
    refetchInterval,
  });

  return (
    <StreamDetail
      activeTab={currentTab}
      stream={stream}
      streamHealth={streamHealth}
      invalidateStream={invalidateStream}
      setSwitchTab={setCurrentTab}
      breadcrumbs={[
        { title: "Streams", href: "/dashboard/streams" },
        { title: stream?.name },
      ]}>
      {currentTab === "Overview" ? (
        <StreamOverviewTab
          id={id}
          stream={stream}
          streamHealth={streamHealth}
          invalidateStream={invalidateStream}
        />
      ) : (
        <StreamHealthTab
          stream={stream}
          streamHealth={streamHealth}
          invalidateStream={invalidateStream}
        />
      )}
    </StreamDetail>
  );
}