New: Table with List of redirections
All checks were successful
Build and Push Docker Image / build (push) Successful in 2m7s
All checks were successful
Build and Push Docker Image / build (push) Successful in 2m7s
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
import { For, Match, Switch } from "solid-js";
|
import { For, Match, Switch } from "solid-js";
|
||||||
import { listURLRedirections } from "~/gen/proto/shorten/v1/shorten-ShortenService_connectquery";
|
import { listURLRedirections } from "~/gen/proto/shorten/v1/shorten-ShortenService_connectquery";
|
||||||
|
import type { URLRedirection } from "~/gen/proto/shorten/v1/shorten_pb";
|
||||||
import { useConnectQuery } from "~/integrations/connect-query/solid";
|
import { useConnectQuery } from "~/integrations/connect-query/solid";
|
||||||
|
|
||||||
const ListRedirections = () => {
|
const ListRedirections = () => {
|
||||||
const query = useConnectQuery(listURLRedirections);
|
const query = useConnectQuery(listURLRedirections);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div class="bg-card p-4">
|
||||||
|
<h2 class="p-2 my-2">List of Redirections</h2>
|
||||||
<Switch fallback={<div>Loading...</div>}>
|
<Switch fallback={<div>Loading...</div>}>
|
||||||
<Match when={query.isError}>
|
<Match when={query.isError}>
|
||||||
<div>Error: {query.error?.message}</div>
|
<div>Error: {query.error?.message}</div>
|
||||||
@@ -15,13 +17,50 @@ const ListRedirections = () => {
|
|||||||
<div>Loading...</div>
|
<div>Loading...</div>
|
||||||
</Match>
|
</Match>
|
||||||
<Match when={query.data}>
|
<Match when={query.data}>
|
||||||
<For each={query.data?.urlRedirections}>
|
<table class="border w-full border-collapse p-2">
|
||||||
{(item) => <div>{item.url}</div>}
|
<thead>
|
||||||
</For>
|
<tr>
|
||||||
|
<td class="border p-2">Short Code</td>
|
||||||
|
<td class="border p-2">URL</td>
|
||||||
|
<td class="border p-2">Active</td>
|
||||||
|
<td class="border p-2">Created At</td>
|
||||||
|
<td class="border p-2">Expires At</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<For each={query.data?.urlRedirections}>
|
||||||
|
{(item) => <Redirection item={item} />}
|
||||||
|
</For>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</Match>
|
</Match>
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Redirection = (props: { item: URLRedirection }) => {
|
||||||
|
return (
|
||||||
|
<tr>
|
||||||
|
<td class="border p-2">{props.item.shortCode}</td>
|
||||||
|
<td class="border p-2">{props.item.url}</td>
|
||||||
|
<td class="border p-2">{props.item.isActive ? "Yes" : "No"}</td>
|
||||||
|
<td class="border p-2">
|
||||||
|
{props.item.createdAt
|
||||||
|
? new Date(
|
||||||
|
Number(props.item.createdAt.seconds) * 1000,
|
||||||
|
).toLocaleDateString()
|
||||||
|
: ""}
|
||||||
|
</td>
|
||||||
|
<td class="border p-2">
|
||||||
|
{props.item.createdAt
|
||||||
|
? new Date(
|
||||||
|
Number(props.item.expiresAt.seconds) * 1000,
|
||||||
|
).toLocaleDateString()
|
||||||
|
: ""}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default ListRedirections;
|
export default ListRedirections;
|
||||||
|
|||||||
Reference in New Issue
Block a user