Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
style: prettify json test value
Browse files Browse the repository at this point in the history
  • Loading branch information
saeidex committed Nov 5, 2024
1 parent 504f9d2 commit 72bd70b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
17 changes: 17 additions & 0 deletions apps/next/src/app/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { ReactNode } from "react";

import { MqttProvider } from "@ubus/mqtt";

interface DashboardLayoutProps {
children: ReactNode | JSX.Element;
}

const DashboardLayout = (props: DashboardLayoutProps) => {
return (
<MqttProvider>
<main className="h-full w-full border">{props.children}</main>
</MqttProvider>
);
};

export default DashboardLayout;
30 changes: 15 additions & 15 deletions apps/next/src/app/dashboard/test/[busId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { MqttProvider, useBusLocationQuery } from "@ubus/mqtt";
import { useBusLocationQuery } from "@ubus/mqtt";

interface BusLocationPageProps {
params: {
Expand All @@ -10,31 +10,31 @@ interface BusLocationPageProps {

const BusLocationPage = (props: BusLocationPageProps) => {
return (
<MqttProvider>
<BusLocationContent {...props} />
</MqttProvider>
<div className="grid h-dvh place-content-center place-items-center gap-4">
<h1>Bus Location</h1>
<Location busId={props.params.busId} />
</div>
);
};

const BusLocationContent = (props: BusLocationPageProps) => {
const { data: location, error } = useBusLocationQuery(props.params.busId);
export const Location = (props: { busId: string }) => {
const { data: location, isLoading, error } = useBusLocationQuery(props.busId);

// if (isLoading) return <p>Loading...</p>;
if (isLoading) return <p>Waiting for bus location...</p>;
if (error)
return (
<p className="grid h-dvh place-content-center place-items-center gap-4 text-destructive">
An error has occurred: {error.message}
</p>
);

return (
<div className="grid h-dvh place-content-center place-items-center gap-4">
<h1>Bus Location</h1>
<p>
{location ? `Current Location: ${location}` : "Waiting for location..."}
</p>
</div>
);
if (location) {
return (
<div className="rounded-sm bg-destructive p-4 text-destructive-foreground">
<pre>{JSON.stringify(JSON.parse(location), null, 2)}</pre>
</div>
);
}
};

export default BusLocationPage;
2 changes: 2 additions & 0 deletions packages/mqtt/src/provider.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import React from "react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";

Expand Down

0 comments on commit 72bd70b

Please sign in to comment.