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
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@
},
"dependencies": {
"@material-ui/core": "^4.12.3",
"firebase": "^8.9.1",
"firebase": "^9.1.2",
"next": "^11.1.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"styled-components": "^5.3.1"
},
"devDependencies": {
"@firebase/app-types": "^0.7.0",
"@firebase/auth-types": "^0.11.0",
"@firebase/database-types": "^0.9.1",
"@types/node": "^16.10.3",
"@types/react": "^17.0.27",
"@types/react-dom": "^17.0.9",
Expand Down
3 changes: 2 additions & 1 deletion src/components/IFrameWidget/editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component, MouseEvent } from 'react';
import styled from 'styled-components';
import { ref, set } from '@firebase/database';
import { db } from '@/lib/firebase';
import {
TextField,
Expand Down Expand Up @@ -31,7 +32,7 @@ class IFrameWidgetEditor extends Component<Props, IFrameWidgetProps> {

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

render() {
Expand Down
3 changes: 2 additions & 1 deletion src/components/TextWidget/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@material-ui/core';
import styled from 'styled-components';
import { Property } from 'csstype';
import { ref, set } from '@firebase/database';
import { db } from '@/lib/firebase';
import type { TextWidgetProps } from '@/components/TextWidget/types';

Expand Down Expand Up @@ -90,7 +91,7 @@ class TextWidgetEditor extends Component<Props, TextWidgetProps> {

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

render() {
Expand Down
3 changes: 2 additions & 1 deletion src/components/TimeWidget/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
FormControlLabel,
Checkbox,
} from '@material-ui/core';
import { ref, set } from '@firebase/database';
import { db } from '@/lib/firebase';
import type { TimeWidgetProps } from './types';

Expand Down Expand Up @@ -36,7 +37,7 @@ class TimeWidgetEditor extends Component<Props, TimeWidgetProps> {

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

render() {
Expand Down
10 changes: 7 additions & 3 deletions src/components/admin/SignInForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { VFC, useEffect, useState } from 'react';
import { useEffect, useState } from 'react';
import { useRouter } from 'next/router';
import styled from 'styled-components';
import { signInWithEmailAndPassword } from '@firebase/auth';
import { TextField, Button } from '@material-ui/core';
import { auth } from '@/lib/firebase';

Expand All @@ -19,14 +21,16 @@ type SignInFormProps = {
redirectTo: string;
};

const SignInForm: VFC<SignInFormProps> = ({ redirectTo }) => {
const SignInForm = ({ redirectTo }: SignInFormProps) => {
const router = useRouter();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");

const signin = async (e: React.SyntheticEvent) => {
e.preventDefault();
try {
await auth.signInWithEmailAndPassword(email, password);
await signInWithEmailAndPassword(auth, email, password);
router.push(redirectTo);
} catch (err) {
alert(err.message);
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/AuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { User } from '@firebase/auth-types';
import React, { FC, createContext, useEffect, useState } from 'react';
import { User, onAuthStateChanged } from '@firebase/auth';
import { FC, createContext, useEffect, useState } from 'react';
import { auth } from '@/lib/firebase';

type AuthContextProps = {
Expand All @@ -12,7 +12,7 @@ const AuthProvider: FC = ({ children }) => {
const [currentUser, setCurrentUser] = useState<User | null | undefined>(undefined);

useEffect(() => {
auth.onAuthStateChanged((user) => {
onAuthStateChanged(auth, (user) => {
setCurrentUser(user);
});
});
Expand Down
19 changes: 7 additions & 12 deletions src/lib/firebase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'firebase/auth';
import 'firebase/database';
import firebase from 'firebase/app';
import { getAuth } from 'firebase/auth';
import { getDatabase } from 'firebase/database';
import { initializeApp } from 'firebase/app';

const config = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
Expand All @@ -12,13 +12,8 @@ const config = {
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
};

let auth;
let db;
if (firebase.apps.length === 0) {
firebase.initializeApp(config);
auth = firebase.app().auth();
db = firebase.database();
}
const app = initializeApp(config);
const auth = getAuth(app);
const db = getDatabase(app);

export default firebase;
export { auth, db };
export { app, auth, db };
7 changes: 4 additions & 3 deletions src/pages/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
Typography,
Button
} from '@material-ui/core';
import { User } from '@firebase/auth-types';
import { DataSnapshot } from '@firebase/database-types';
import { User } from '@firebase/auth';
import { ref, onValue, DataSnapshot } from '@firebase/database';

import { AuthProvider } from '@/lib/AuthProvider';
import { auth, db } from '@/lib/firebase';
Expand Down Expand Up @@ -53,7 +53,8 @@ const Widgets = () => {
const [widgets, setWidgets] = useState<WidgetList>({});

useEffect(() => {
db.ref('/widgets').on('value', (snap: DataSnapshot) => {
const widgetsRef = ref(db, '/widgets');
onValue(widgetsRef, (snap: DataSnapshot) => {
if (snap?.val()) {
setWidgets(snap.val());
}
Expand Down
5 changes: 3 additions & 2 deletions src/pages/preview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import { DataSnapshot } from '@firebase/database-types';
import { ref, onValue, DataSnapshot } from '@firebase/database';

import { db } from '@/lib/firebase';
import { TextWidget } from '@/components/TextWidget';
Expand All @@ -23,7 +23,8 @@ const PreviewPage = () => {
const [widgets, setWidgets] = useState<WidgetList>({});

useEffect(() => {
db.ref('/widgets').on('value', (snap: DataSnapshot) => {
const widgetsRef = ref(db, '/widgets');
onValue(widgetsRef, (snap: DataSnapshot) => {
if (snap?.val()) {
setWidgets(snap.val());
}
Expand Down
Loading