Skip to content

Commit 9f5b1c6

Browse files
committed
Refactor frontend organization
1 parent 499a0fc commit 9f5b1c6

File tree

7 files changed

+45
-33
lines changed

7 files changed

+45
-33
lines changed

custom_components/maint/frontend/dist/main.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

custom_components/maint/frontend/src/api.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
1-
import type { HassConnection, MaintEntry, MaintTask, TaskPayload } from "./types.js";
1+
export type FrequencyUnit = "days" | "weeks" | "months";
2+
3+
export interface MaintEntry {
4+
entry_id: string;
5+
title: string;
6+
}
7+
8+
export interface MaintTask {
9+
task_id: string;
10+
description: string;
11+
frequency: number;
12+
frequency_unit: FrequencyUnit;
13+
last_completed: string | null;
14+
next_scheduled?: string | null;
15+
}
16+
17+
export interface TaskPayload {
18+
description: string;
19+
frequency: number;
20+
frequency_unit: FrequencyUnit;
21+
last_completed: string;
22+
}
23+
24+
export interface HassConnection {
25+
callWS<T>(params: Record<string, unknown>): Promise<T>;
26+
}
227

328
const DOMAIN = "maint";
429

custom_components/maint/frontend/src/formatting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { FrequencyUnit, MaintTask } from "./types.js";
1+
import type { FrequencyUnit, MaintTask } from "./api.js";
22

33
export const normalizeFrequencyUnit = (value: string): FrequencyUnit => {
44
const normalized = (value ?? "").toString().trim();

custom_components/maint/frontend/src/forms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parseDate, parseFrequency, parseFrequencyUnit } from "./formatting.js";
2-
import type { FrequencyUnit, TaskPayload } from "./types.js";
2+
import type { FrequencyUnit, TaskPayload } from "./api.js";
33

44
export interface ValidationResult {
55
values?: TaskPayload;

custom_components/maint/frontend/src/main.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import { html, LitElement, nothing } from "lit";
22
import { customElement, property, state } from "lit/decorators.js";
33

4-
import { createTask, deleteTask, fetchEntries, fetchTasks, updateTask } from "./api.js";
4+
import {
5+
createTask,
6+
deleteTask,
7+
fetchEntries,
8+
fetchTasks,
9+
updateTask,
10+
type FrequencyUnit,
11+
type HassConnection,
12+
type MaintEntry,
13+
type MaintTask
14+
} from "./api.js";
515
import { validateTaskFields } from "./forms.js";
616
import {
717
formatDate,
@@ -12,7 +22,6 @@ import {
1222
normalizeTask
1323
} from "./formatting.js";
1424
import { styles } from "./styles.js";
15-
import type { FrequencyUnit, HassConnection, MaintEntry, MaintTask } from "./types.js";
1625

1726
@customElement("maint-panel")
1827
export class MaintPanel extends LitElement {

custom_components/maint/frontend/src/types.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

scripts/develop

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
set -e
44

5+
# Move into the root directory.
56
cd "$(dirname "$0")/.."
67

78
# Create config dir if not present
@@ -16,5 +17,8 @@ fi
1617
## without resulting to symlinks.
1718
export PYTHONPATH="${PYTHONPATH}:${PWD}/custom_components"
1819

20+
# Build the frontend.
21+
./scripts/frontend
22+
1923
# Start Home Assistant
2024
hass --config "${PWD}/config" --debug

0 commit comments

Comments
 (0)