Skip to content

Commit 00ad348

Browse files
authored
refactor/remove unused code (#148)
* refactor: remove Preview component * refactor: remove unused import
1 parent 2326432 commit 00ad348

File tree

10 files changed

+48
-56
lines changed

10 files changed

+48
-56
lines changed

src/components/Preview/index.tsx

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

src/components/admin/Dialog/AddWidgetDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
TextField,
1313
MenuItem,
1414
} from '@mui/material';
15-
import { ref, set, onValue } from '@firebase/database';
15+
import { ref, set } from '@firebase/database';
1616
import { db } from '@/lib/firebase';
1717
import { EditorMap } from '@/components/widgets';
1818

src/components/admin/LeftSideNav/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect, MouseEvent } from 'react';
1+
import { useState, useEffect } from 'react';
22
import {
33
Drawer,
44
Toolbar,

src/components/admin/SignInForm/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react';
1+
import { useState } from 'react';
22
import { useRouter } from 'next/router';
33
import styled from 'styled-components';
44
import { signInWithEmailAndPassword } from '@firebase/auth';

src/components/admin/signin.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { VFC } from 'react';
1+
import { VFC } from 'react';
22
import styled from 'styled-components';
33

44
import { SignInForm } from "@/components/admin/SignInForm";

src/components/widgets/TextWidget/widget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { VFC, CSSProperties } from 'react';
1+
import { VFC, CSSProperties } from 'react';
22
import type { TextWidgetProps } from './types';
33

44
const calcTextShadow = (weight, color) => {

src/components/widgets/TimeWidget/widget.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React, { CSSProperties } from 'react';
1+
import { Component, CSSProperties } from 'react';
22
import type { TimeWidgetProps } from './types';
33

44
interface TimeWidgetState {
55
time: Date;
66
};
77

8-
class TimeWidget extends React.Component<TimeWidgetProps, TimeWidgetState> {
8+
class TimeWidget extends Component<TimeWidgetProps, TimeWidgetState> {
99
interval: NodeJS.Timer | null;
1010

1111
constructor(props: TimeWidgetProps) {

src/pages/admin/[id]/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '@mui/material';
99
import { User } from '@firebase/auth';
1010
import { AuthProvider } from '@/lib/AuthProvider';
11-
import { auth, db } from '@/lib/firebase';
11+
import { auth } from '@/lib/firebase';
1212
import { Signin } from '@/components/admin/signin';
1313
import { Navbar } from '@/components/admin/Navbar';
1414
import { LeftSideBar } from '@/components/admin/LeftSideNav';

src/pages/admin/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import {
77
Box,
88
Typography,
99
Stack,
10-
Paper,
1110
} from '@mui/material';
12-
import { styled } from '@mui/material/styles';
1311
import { User } from '@firebase/auth';
1412
import { ref, onValue, DataSnapshot } from '@firebase/database';
1513
import { AuthProvider } from '@/lib/AuthProvider';

src/pages/preview/[id]/index.tsx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,46 @@
1+
import { useEffect, useState } from 'react';
12
import Head from 'next/head';
23
import { useRouter } from 'next/router';
4+
import { ref, onValue, DataSnapshot } from '@firebase/database';
35

4-
import { Preview } from '@/components/Preview';
6+
import { db } from '@/lib/firebase';
7+
import { PreviewMap } from '@/components/widgets';
8+
9+
type Widget = {
10+
name: string;
11+
props: any;
12+
}
13+
14+
type WidgetList = { [key: string]: Widget }
15+
16+
type PreviewProps = {
17+
profile: string;
18+
}
19+
20+
const Preview = ({ profile }: PreviewProps) => {
21+
const [widgets, setWidgets] = useState<WidgetList>({});
22+
23+
useEffect(() => {
24+
const widgetsRef = ref(db, `/profiles/${profile}/widgets`);
25+
onValue(widgetsRef, (snap: DataSnapshot) => {
26+
if (snap?.val()) {
27+
setWidgets(snap.val());
28+
}
29+
});
30+
}, [profile]);
31+
32+
return (
33+
<div>
34+
{
35+
Object.keys(widgets).map((id) => {
36+
const widget: any = widgets[id];
37+
const Widget = PreviewMap[widget.name];
38+
return <Widget key={id} {...widget.props} />
39+
})
40+
}
41+
</div>
42+
);
43+
};
544

645
const PreviewPage = () => {
746
const router = useRouter();

0 commit comments

Comments
 (0)