Skip to content

Commit c369fb6

Browse files
committed
Fix issues with EPG
1 parent 4ab9605 commit c369fb6

File tree

10 files changed

+153
-767
lines changed

10 files changed

+153
-767
lines changed

index.tsx

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Context, Hono} from 'hono';
22
import {serve} from '@hono/node-server';
3+
import {serveStatic} from '@hono/node-server/serve-static';
34
import {BlankEnv, BlankInput} from 'hono/types';
45
import {html} from 'hono/html';
56

@@ -10,6 +11,8 @@ import {scheduleEntries} from './services/build-schedule';
1011
import {cleanEntries} from './services/shared-helpers';
1112
import {SERVER_PORT} from './services/port';
1213
import { miscDbHandler } from './services/misc-db';
14+
import { db } from './services/database';
15+
import { IChannel, IMisc } from './services/shared-interfaces';
1316

1417
import {peacockHandler} from './services/peacock-handler';
1518
import {abcHandler} from './services/abc-handler';
@@ -19,14 +22,12 @@ import { Header } from './views/Header';
1922
import {Main} from './views/Main';
2023
import { Links } from './views/Links';
2124
import { Prefix } from './views/Prefix';
25+
import {Providers} from './views/Providers';
26+
import {Provider} from './views/Provider';
27+
import {Style} from './views/Style';
28+
import {Script} from './views/Script';
2229

2330
import {version} from './package.json';
24-
import { Providers } from './views/Providers';
25-
import { db } from './services/database';
26-
import { IChannel, IMisc } from './services/shared-interfaces';
27-
import { Provider } from './views/Provider';
28-
import { Style } from './views/Style';
29-
import { Toast } from './views/Toast';
3031

3132
const notFound = (c: Context<BlankEnv, '', BlankInput>) => c.text('404 not found', 404, {});
3233

@@ -46,6 +47,8 @@ const schedule = async () => {
4647

4748
const app = new Hono();
4849

50+
app.use('/node_modules/*', serveStatic({root: './'}));
51+
4952
app.get('/', async c => {
5053
// For Links
5154
const protocol = c.req.header('x-forwarded-proto') || 'http';
@@ -77,26 +80,9 @@ app.get('/', async c => {
7780
</Providers>
7881
</Main>
7982
<Style />
83+
<Script />
8084
</Layout>
81-
)}
82-
<script>
83-
function removeToasts() {
84-
const toasts = document.querySelectorAll('.alert');
85-
toasts.forEach(toast => {
86-
setTimeout(() => {
87-
toast.remove();
88-
}, 5000);
89-
});
90-
}
91-
92-
document.addEventListener('DOMContentLoaded', function () {
93-
removeToasts();
94-
});
95-
96-
document.body.addEventListener('htmx:afterSwap', function (event) {
97-
removeToasts();
98-
});
99-
</script>`,
85+
)}`,
10086
);
10187
});
10288

@@ -113,10 +99,13 @@ app.put('/update-prefix', async c => {
11399
}
114100

115101
return c.html(
116-
<>
117-
<Prefix currentPrefix={prefix} invalid={invalid} />
118-
{invalid && <Toast message="Invalid URI" type="error" />}
119-
</>,
102+
<Prefix currentPrefix={prefix} invalid={invalid} />,
103+
200,
104+
{
105+
...(invalid && {
106+
'HX-Trigger': `{"HXToast":{"type":"error","body":"Invalid URI"}}`,
107+
}),
108+
},
120109
);
121110
});
122111

@@ -131,10 +120,13 @@ app.put('/provider/toggle/:provider', async c => {
131120
const providerChannels = await db.channels.find<IChannel>({from: {$regex: regex}});
132121

133122
return c.html(
134-
<>
135-
<Provider channels={providerChannels} name={provider} enabled={enabled} />
136-
<Toast message={`${provider} ${enabled ? 'enabled' : 'disabled'}`} type="success" />
137-
</>,
123+
<Provider channels={providerChannels} name={provider} enabled={enabled} />,
124+
200,
125+
{
126+
...(enabled && {
127+
'HX-Trigger': `{"HXToast":{"type":"success","body":"Successfully enabled ${provider}"}}`,
128+
}),
129+
},
138130
);
139131
});
140132

@@ -143,21 +135,25 @@ app.put('/channel/toggle/:id', async c => {
143135
const body = await c.req.parseBody();
144136
const enabled = body['channel-enabled'] === 'on';
145137

146-
await db.channels.update({id: channelId}, {$set: {enabled}});
138+
const {name} = await db.channels.update<IChannel>({id: channelId}, {$set: {enabled}}, {returnUpdatedDocs: true});
147139

148140
return c.html(
149-
<>
150-
<input
151-
hx-target="this"
152-
hx-swap="outerHTML"
153-
type="checkbox"
154-
checked={enabled ? true : false}
155-
hx-put={`/channel/toggle/${channelId}`}
156-
hx-trigger="change"
157-
name="channel-enabled"
158-
/>
159-
<Toast message={`Channel ${enabled ? 'enabled' : 'disabled'}`} type="success" />
160-
</>,
141+
<input
142+
hx-target="this"
143+
hx-swap="outerHTML"
144+
type="checkbox"
145+
checked={enabled ? true : false}
146+
data-enabled={enabled ? 'true': 'false'}
147+
hx-put={`/channel/toggle/${channelId}`}
148+
hx-trigger="change"
149+
name="channel-enabled"
150+
/>,
151+
200,
152+
{
153+
...(enabled && {
154+
'HX-Trigger': `{"HXToast":{"type":"success","body":"Successfully enabled ${name}"}}`,
155+
}),
156+
},
161157
);
162158
});
163159

0 commit comments

Comments
 (0)