Skip to content

Commit 1dccf01

Browse files
authored
feat: delete widget (#106)
1 parent 48d9e0c commit 1dccf01

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/components/IFrameWidget/editor.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,21 @@ class IFrameWidgetEditor extends Component<Props, IFrameWidgetProps> {
2828
super(props);
2929
this.state = this.props.props;
3030
this.save = this.save.bind(this);
31+
this.delete = this.delete.bind(this);
3132
}
3233

3334
save(e: MouseEvent<HTMLButtonElement>) {
3435
e.preventDefault();
3536
set(ref(db, `/widgets/${this.props.id}/props`), this.state);
3637
}
3738

39+
delete(e: MouseEvent<HTMLButtonElement>) {
40+
e.preventDefault();
41+
if (confirm('本当に削除してよろしいですか?')) {
42+
set(ref(db, `/widgets/${this.props.id}`), null);
43+
}
44+
}
45+
3846
render() {
3947
return (
4048
<div>
@@ -191,6 +199,15 @@ class IFrameWidgetEditor extends Component<Props, IFrameWidgetProps> {
191199
>
192200
Save
193201
</Button>
202+
<Button
203+
sx={{ ml: 1 }}
204+
type="button"
205+
color="error"
206+
variant="outlined"
207+
onClick={this.delete}
208+
>
209+
Delete
210+
</Button>
194211
</FormGroup>
195212
</div>
196213
);

src/components/TextWidget/editor.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,21 @@ class TextWidgetEditor extends Component<Props, TextWidgetProps> {
8888
super(props);
8989
this.state = this.props.props;
9090
this.save = this.save.bind(this);
91+
this.delete = this.delete.bind(this);
9192
}
9293

9394
save(e: MouseEvent<HTMLButtonElement>) {
9495
e.preventDefault();
9596
set(ref(db, `/widgets/${this.props.id}/props`), this.state);
9697
}
9798

99+
delete(e: MouseEvent<HTMLButtonElement>) {
100+
e.preventDefault();
101+
if (confirm('本当に削除してよろしいですか?')) {
102+
set(ref(db, `/widgets/${this.props.id}`), null);
103+
}
104+
}
105+
98106
render() {
99107
return (
100108
<div>
@@ -339,6 +347,15 @@ class TextWidgetEditor extends Component<Props, TextWidgetProps> {
339347
>
340348
Save
341349
</Button>
350+
<Button
351+
sx={{ ml: 1 }}
352+
type="button"
353+
color="error"
354+
variant="outlined"
355+
onClick={this.delete}
356+
>
357+
Delete
358+
</Button>
342359
</FormGroup>
343360
</div>
344361
);

src/components/TimeWidget/editor.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,21 @@ class TimeWidgetEditor extends Component<Props, TimeWidgetProps> {
3333
super(props);
3434
this.state = this.props.props;
3535
this.save = this.save.bind(this);
36+
this.delete = this.delete.bind(this);
3637
}
3738

3839
save(e: MouseEvent<HTMLButtonElement>) {
3940
e.preventDefault();
4041
set(ref(db, `/widgets/${this.props.id}/props`), this.state);
4142
}
4243

44+
delete(e: MouseEvent<HTMLButtonElement>) {
45+
e.preventDefault();
46+
if (confirm('本当に削除してよろしいですか?')) {
47+
set(ref(db, `/widgets/${this.props.id}`), null);
48+
}
49+
}
50+
4351
render() {
4452
return (
4553
<div>
@@ -85,6 +93,15 @@ class TimeWidgetEditor extends Component<Props, TimeWidgetProps> {
8593
>
8694
Save
8795
</Button>
96+
<Button
97+
sx={{ ml: 1 }}
98+
type="button"
99+
color="error"
100+
variant="outlined"
101+
onClick={this.delete}
102+
>
103+
Delete
104+
</Button>
88105
</FormGroup>
89106
</div>
90107
);

0 commit comments

Comments
 (0)