Skip to content

Commit ca6ef49

Browse files
authored
feat: edit buttons for streams and fixtures (#17)
* feat: edit buttons for streams and fixtures * fix: change edit buttons to links
1 parent 374eaef commit ca6ef49

File tree

16 files changed

+316
-43
lines changed

16 files changed

+316
-43
lines changed

.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
DATABASE_URL="postgres://postgres:postgres@localhost/radio_tx"
2+
PUBLIC_URL="http://localhost:3000"
3+
HLS_SEGMENTS_URL="http://localhost:3000"
4+
STREAM_CONTROLLER_TOKEN="changeme"
5+
DASHBOARD_USER="pass"
6+
DASHBOARD_PASS="word"
7+
NEXTAUTH_URL="http://localhost:3000"
8+
AUTH_SECRET="secret"

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ yarn-error.log*
3232

3333
# env files (can opt-in for committing if needed)
3434
.env*
35+
!.env.example
36+
!.envrc
3537

3638
# vercel
3739
.vercel

flake.nix

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,56 @@
77
flake-utils.url = "github:numtide/flake-utils";
88
};
99

10-
outputs = { self, nixpkgs, flake-utils, crane, ... }:
10+
outputs =
11+
{
12+
self,
13+
nixpkgs,
14+
flake-utils,
15+
crane,
16+
...
17+
}:
1118
{
1219
overlays.default = final: prev: {
1320
inherit (self.packages.${prev.system}) selector;
1421
};
15-
} // flake-utils.lib.eachDefaultSystem (system:
22+
}
23+
// flake-utils.lib.eachDefaultSystem (
24+
system:
1625
let
1726
pkgs = import nixpkgs {
1827
inherit system;
1928
};
2029

21-
deps = with pkgs; [
22-
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
23-
pkgs.libiconv
24-
];
30+
deps =
31+
with pkgs;
32+
[
33+
]
34+
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
35+
pkgs.libiconv
36+
];
2537

2638
craneLib = crane.mkLib pkgs;
2739
in
2840
{
2941
devShells.default = craneLib.devShell {
30-
packages = with pkgs; [
31-
rust-analyzer
32-
mpv
33-
ffmpeg_6
34-
liquidsoap
35-
yarn-berry
36-
ansible
37-
sshpass
38-
] ++ deps;
42+
packages =
43+
with pkgs;
44+
[
45+
rust-analyzer
46+
mpv
47+
ffmpeg_6
48+
liquidsoap
49+
yarn-berry
50+
ansible
51+
sshpass
52+
openssl
53+
]
54+
++ deps;
3955

4056
PRISMA_QUERY_ENGINE_LIBRARY = "${pkgs.prisma-engines}/lib/libquery_engine.node";
4157
PRISMA_QUERY_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/query-engine";
4258
PRISMA_SCHEMA_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/schema-engine";
4359
};
44-
});
60+
}
61+
);
4562
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use server';
2+
3+
import { prisma } from '@/lib/db';
4+
import { action } from '@/lib/forms';
5+
import { editIngestPointSchema } from './schema';
6+
import { notifyIngestUpdated } from '@/lib/stream-controller';
7+
import { redirect } from 'next/navigation';
8+
9+
export const editIngestPoint = action(editIngestPointSchema, async (edit) => {
10+
const ingestPoint = await prisma.ingestPoint.update({
11+
where: {
12+
id: edit.id,
13+
},
14+
data: {
15+
name: edit.name,
16+
icecastServer: edit.icecastServer,
17+
icecastMount: edit.icecastMount,
18+
},
19+
});
20+
await notifyIngestUpdated(ingestPoint.id);
21+
redirect(`/dashboard/ingest/${ingestPoint.id}`);
22+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use client';
2+
3+
import { useForm, zodResolver } from '@mantine/form';
4+
import { Button, Group, TextInput } from '@mantine/core';
5+
import { IngestPoint } from '@prisma/client';
6+
import { editIngestPoint } from './actions';
7+
import { editIngestPointSchema } from './schema';
8+
9+
export function EditIngestForm({ ingestPoint }: { ingestPoint: IngestPoint }) {
10+
const form = useForm({
11+
mode: 'controlled',
12+
initialValues: {
13+
id: ingestPoint.id,
14+
name: ingestPoint.name,
15+
icecastServer: ingestPoint.icecastServer,
16+
icecastMount: ingestPoint.icecastMount,
17+
},
18+
validate: zodResolver(editIngestPointSchema),
19+
});
20+
21+
return (
22+
<form
23+
onSubmit={async (e) => {
24+
e.preventDefault();
25+
form.validate();
26+
if (form.isValid()) {
27+
console.log(form.values);
28+
const result = await editIngestPoint(form.values);
29+
if (!result.ok) {
30+
console.error('Something went wrong', result);
31+
alert(
32+
'Something went wrong! Check the browser console for details.'
33+
);
34+
return;
35+
}
36+
}
37+
}}
38+
>
39+
<TextInput
40+
{...form.getInputProps('name')}
41+
label="Name"
42+
withAsterisk
43+
placeholder="ROB-5"
44+
/>
45+
<TextInput
46+
{...form.getInputProps('icecastServer')}
47+
label="Icecast server"
48+
withAsterisk
49+
placeholder="https://radio.ingest.roses.media"
50+
/>
51+
<TextInput
52+
{...form.getInputProps('icecastMount')}
53+
label="Icecast mountpoint"
54+
withAsterisk
55+
placeholder="ROB-5"
56+
/>
57+
58+
<Group justify="flex-end" mt="md">
59+
<Button type="submit">Create</Button>
60+
</Group>
61+
</form>
62+
);
63+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { prisma } from '@/lib/db';
2+
import { EditIngestForm } from './form';
3+
4+
export default async function EditIngest({
5+
params,
6+
}: {
7+
params: Promise<{ id: string }>;
8+
}) {
9+
const awaitedParams = await params;
10+
11+
const ingestPoint = await prisma.ingestPoint.findUniqueOrThrow({
12+
where: {
13+
id: awaitedParams.id,
14+
},
15+
});
16+
17+
return <EditIngestForm ingestPoint={ingestPoint} />;
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { z } from 'zod';
2+
3+
export const editIngestPointSchema = z.object({
4+
id: z.string(),
5+
name: z.string(),
6+
icecastServer: z.string(),
7+
icecastMount: z.string(),
8+
});

src/app/dashboard/ingest/[id]/page.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { prisma } from '@/lib/db';
2-
import { Space, Text, Title } from '@mantine/core';
2+
import { Button, Group, Space, Text, Title } from '@mantine/core';
33
import { notFound } from 'next/navigation';
44
import { DeleteButton } from './components';
5+
import Link from 'next/link';
56

67
export default async function StreamPage({
78
params,
@@ -21,7 +22,17 @@ export default async function StreamPage({
2122

2223
return (
2324
<>
24-
<Title order={1}>{ingest.name}</Title>
25+
<Group>
26+
<Title order={1}>{ingest.name}</Title>
27+
<Link
28+
href={`/dashboard/ingest/${id}/edit`}
29+
style={{
30+
marginLeft: 'auto',
31+
}}
32+
>
33+
<Button>Edit</Button>
34+
</Link>
35+
</Group>
2536

2637
<Space h="md" />
2738

src/app/dashboard/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default async function DashboardLayout({
1313
}) {
1414
const u = await getServerSession();
1515
if (!u) {
16-
redirect('/api/auth/login');
16+
redirect('/api/auth/signin');
1717
}
1818

1919
const isAnyStreamLive =

0 commit comments

Comments
 (0)