Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/components/Preview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ import { useRouter } from 'next/router';
import { ref, onValue, DataSnapshot } from '@firebase/database';

import { db } from '@/lib/firebase';
import { TextWidget } from '@/components/TextWidget';
import { TimeWidget } from '@/components/TimeWidget';
import { IFrameWidget } from '@/components/IFrameWidget';

const Widgets = {
'text': TextWidget,
'time': TimeWidget,
'iframe': IFrameWidget,
};
import { PreviewMap } from '@/components/widgets';

type Widget = {
name: string;
Expand Down Expand Up @@ -42,7 +34,7 @@ const Preview = ({ profile }: PreviewProps) => {
{
Object.keys(widgets).map((id) => {
const widget: any = widgets[id];
const Widget = Widgets[widget.name];
const Widget = PreviewMap[widget.name];
return <Widget key={id} {...widget.props} />
})
}
Expand Down
12 changes: 2 additions & 10 deletions src/components/admin/Dialog/AddWidgetDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@ import {
} from '@mui/material';
import { ref, set, onValue } from '@firebase/database';
import { db } from '@/lib/firebase';
import { TextWidgetEditor } from '@/components/TextWidget';
import { TimeWidgetEditor } from '@/components/TimeWidget';
import { IFrameWidgetEditor } from '@/components/IFrameWidget';

const Editors = {
text: TextWidgetEditor,
time: TimeWidgetEditor,
iframe: IFrameWidgetEditor,
};
import { EditorMap } from '@/components/widgets';

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

setWidgetId("");
Expand Down
10 changes: 1 addition & 9 deletions src/components/admin/Editors/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { useEffect, useState } from 'react';
import { ref, onValue, DataSnapshot } from '@firebase/database';
import { db } from '@/lib/firebase';
import { TextWidgetEditor } from '@/components/TextWidget';
import { TimeWidgetEditor } from '@/components/TimeWidget';
import { IFrameWidgetEditor } from '@/components/IFrameWidget';

const EditorMap = {
text: TextWidgetEditor,
time: TimeWidgetEditor,
iframe: IFrameWidgetEditor,
};
import { EditorMap } from '@/components/widgets';

type Widget = {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import styled from 'styled-components';
import { Property } from 'csstype';
import { ref, set, onValue } from '@firebase/database';
import { db } from '@/lib/firebase';
import type { TextWidgetProps } from '@/components/TextWidget/types';
import type { TextWidgetProps } from './types';

type Props = {
profile: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { VFC, CSSProperties } from 'react';
import type { TextWidgetProps } from '@/components/TextWidget/types';
import type { TextWidgetProps } from './types';

const calcTextShadow = (weight, color) => {
const edge = [
Expand Down
15 changes: 15 additions & 0 deletions src/components/widgets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { TextWidget, TextWidgetEditor } from './TextWidget';
import { TimeWidget, TimeWidgetEditor } from './TimeWidget';
import { IFrameWidget, IFrameWidgetEditor } from './IFrameWidget';

export const PreviewMap = {
text: TextWidget,
time: TimeWidget,
iframe: IFrameWidget,
};

export const EditorMap = {
text: TextWidgetEditor,
time: TimeWidgetEditor,
iframe: IFrameWidgetEditor,
};
10 changes: 1 addition & 9 deletions src/pages/admin/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,7 @@ import { auth, db } from '@/lib/firebase';
import { Signin } from '@/components/admin/signin';
import { Navbar } from '@/components/admin/Navbar';
import { LeftSideBar } from '@/components/admin/LeftSideNav';
import { TextWidgetEditor } from '@/components/TextWidget';
import { TimeWidgetEditor } from '@/components/TimeWidget';
import { IFrameWidgetEditor } from '@/components/IFrameWidget';

const EditorMap = {
text: TextWidgetEditor,
time: TimeWidgetEditor,
iframe: IFrameWidgetEditor,
};
import { EditorMap } from '@/components/widgets';

type Widget = {
name: string;
Expand Down
16 changes: 0 additions & 16 deletions src/pages/preview/[id]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
import Head from 'next/head';
import { useRouter } from 'next/router';

import { TextWidget } from '@/components/TextWidget';
import { TimeWidget } from '@/components/TimeWidget';
import { IFrameWidget } from '@/components/IFrameWidget';
import { Preview } from '@/components/Preview';

const Widgets = {
'text': TextWidget,
'time': TimeWidget,
'iframe': IFrameWidget,
};

type Widget = {
name: string;
props: any;
}

type WidgetList = { [key: string]: Widget }

const PreviewPage = () => {
const router = useRouter();
const profile = router.query.id as string;
Expand Down