Skip to content

Commit 2326432

Browse files
authored
refactor: export { EditorMap, PreviewMap } (#147)
1 parent 8a11e99 commit 2326432

File tree

18 files changed

+23
-56
lines changed

18 files changed

+23
-56
lines changed

src/components/Preview/index.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@ import { useRouter } from 'next/router';
33
import { ref, onValue, DataSnapshot } from '@firebase/database';
44

55
import { db } from '@/lib/firebase';
6-
import { TextWidget } from '@/components/TextWidget';
7-
import { TimeWidget } from '@/components/TimeWidget';
8-
import { IFrameWidget } from '@/components/IFrameWidget';
9-
10-
const Widgets = {
11-
'text': TextWidget,
12-
'time': TimeWidget,
13-
'iframe': IFrameWidget,
14-
};
6+
import { PreviewMap } from '@/components/widgets';
157

168
type Widget = {
179
name: string;
@@ -42,7 +34,7 @@ const Preview = ({ profile }: PreviewProps) => {
4234
{
4335
Object.keys(widgets).map((id) => {
4436
const widget: any = widgets[id];
45-
const Widget = Widgets[widget.name];
37+
const Widget = PreviewMap[widget.name];
4638
return <Widget key={id} {...widget.props} />
4739
})
4840
}

src/components/admin/Dialog/AddWidgetDialog.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@ import {
1414
} from '@mui/material';
1515
import { ref, set, onValue } from '@firebase/database';
1616
import { db } from '@/lib/firebase';
17-
import { TextWidgetEditor } from '@/components/TextWidget';
18-
import { TimeWidgetEditor } from '@/components/TimeWidget';
19-
import { IFrameWidgetEditor } from '@/components/IFrameWidget';
20-
21-
const Editors = {
22-
text: TextWidgetEditor,
23-
time: TimeWidgetEditor,
24-
iframe: IFrameWidgetEditor,
25-
};
17+
import { EditorMap } from '@/components/widgets';
2618

2719
type AddWidgetDialogProps = {
2820
profile: string;
@@ -94,7 +86,7 @@ const AddWidgetDialog = ({ profile, open, onClose }: AddWidgetDialogProps) => {
9486
<Button color="primary" variant="contained" onClick={() => {
9587
set(ref(db, `/profiles/${profile}/widgets/${widgetId}`), {
9688
name: widgetType,
97-
props: Editors[widgetType].defaultProps
89+
props: EditorMap[widgetType].defaultProps
9890
});
9991

10092
setWidgetId("");

src/components/admin/Editors/index.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
import { useEffect, useState } from 'react';
22
import { ref, onValue, DataSnapshot } from '@firebase/database';
33
import { db } from '@/lib/firebase';
4-
import { TextWidgetEditor } from '@/components/TextWidget';
5-
import { TimeWidgetEditor } from '@/components/TimeWidget';
6-
import { IFrameWidgetEditor } from '@/components/IFrameWidget';
7-
8-
const EditorMap = {
9-
text: TextWidgetEditor,
10-
time: TimeWidgetEditor,
11-
iframe: IFrameWidgetEditor,
12-
};
4+
import { EditorMap } from '@/components/widgets';
135

146
type Widget = {
157
name: string;

src/components/TextWidget/editor.tsx renamed to src/components/widgets/TextWidget/editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import styled from 'styled-components';
1010
import { Property } from 'csstype';
1111
import { ref, set, onValue } from '@firebase/database';
1212
import { db } from '@/lib/firebase';
13-
import type { TextWidgetProps } from '@/components/TextWidget/types';
13+
import type { TextWidgetProps } from './types';
1414

1515
type Props = {
1616
profile: string;

0 commit comments

Comments
 (0)