-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eliminado cookies e implementado contexto para o modo história
- Loading branch information
1 parent
4deb059
commit f10761b
Showing
16 changed files
with
824 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Faça uma cópia desse arquivo alterando o nome para .env.local | ||
# e insira aqui as suas configurações do firebase | ||
REACT_APP_API_KEY= | ||
REACT_APP_AUTH_DOMAIN= | ||
REACT_APP_DATABASE_URL= | ||
REACT_APP_PROJECT_ID= | ||
REACT_APP_STORAGE_BUCKET= | ||
REACT_APP_MESSAGING_SENDER_ID= | ||
REACT_APP_APP_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"projects": { | ||
"default": "react-battle-rpg" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"database": { | ||
"rules": "database.rules.json" | ||
}, | ||
"hosting": { | ||
"public": "build", | ||
"ignore": [ | ||
"firebase.json", | ||
"**/.*", | ||
"**/node_modules/**" | ||
], | ||
"rewrites": [ | ||
{ | ||
"source": "**", | ||
"destination": "/index.html" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { createContext, ReactNode, useEffect, useState } from "react"; | ||
import { auth, firebase } from "../services/firebase"; | ||
|
||
type User = { | ||
id: string; | ||
name: string; | ||
avatar: string; | ||
} | ||
|
||
type AuthContextType = { | ||
user: User | undefined; | ||
signInWithGoogle: () => Promise<void>; | ||
} | ||
|
||
type AuthContextProviderProps = { | ||
children: ReactNode; | ||
} | ||
|
||
export const AuthContext = createContext({} as AuthContextType); | ||
|
||
export function AuthContextProvider(props: AuthContextProviderProps) { | ||
const [user, setUser ] = useState<User>(); | ||
|
||
useEffect(() => { | ||
const unsubscribe = auth.onAuthStateChanged(user => { | ||
if (user) { | ||
const { displayName, photoURL, uid } = user; | ||
|
||
if (!displayName || !photoURL) { | ||
throw new Error('Missing information from Google Account.'); | ||
} | ||
|
||
setUser({ | ||
id: uid, | ||
name: displayName, | ||
avatar: photoURL | ||
}) | ||
} | ||
}) | ||
|
||
return () => { | ||
unsubscribe(); | ||
} | ||
}, []); | ||
|
||
async function signInWithGoogle() { | ||
const provider = new firebase.auth.GoogleAuthProvider(); | ||
|
||
const result = await auth.signInWithPopup(provider); | ||
|
||
if (result.user) { | ||
const { displayName, photoURL, uid } = result.user; | ||
|
||
if (!displayName || !photoURL) { | ||
throw new Error('Missing information from Google Account.'); | ||
} | ||
|
||
setUser({ | ||
id: uid, | ||
name: displayName, | ||
avatar: photoURL | ||
}) | ||
} | ||
} | ||
|
||
return ( | ||
<AuthContext.Provider value={{ user, signInWithGoogle }}> | ||
{props.children} | ||
</AuthContext.Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useState, createContext, ReactNode } from "react"; | ||
|
||
type StoryType = { | ||
remedy: number; | ||
maximumPower: number; | ||
yourMonsterNumber: number; | ||
opponentMonsterNumber: number; | ||
storyNumber: number; | ||
inGame: boolean; | ||
} | ||
|
||
type UpdateStoryContextType = { | ||
storyValue: StoryType | ||
updateStoryValue: any //@todo corrigir; | ||
} | ||
|
||
type StoryContextProviderProps = { | ||
children: ReactNode; | ||
} | ||
|
||
export const StoryContext = createContext({} as UpdateStoryContextType); | ||
|
||
export function StoryContextProvider(props: StoryContextProviderProps) { | ||
const [storyValue, setStoryValue] = useState<StoryType>({ | ||
remedy: 2, | ||
maximumPower: 2, | ||
yourMonsterNumber: 0, | ||
opponentMonsterNumber: 0, | ||
storyNumber: 0, | ||
inGame: false | ||
}); | ||
|
||
function updateStoryValue(value: StoryType) { | ||
const updateValues = { | ||
remedy: value.remedy, | ||
maximumPower: value.maximumPower, | ||
yourMonsterNumber: value.yourMonsterNumber, | ||
opponentMonsterNumber: value.opponentMonsterNumber, | ||
storyNumber: value.storyNumber, | ||
inGame: value.inGame, | ||
}; | ||
setStoryValue(updateValues); | ||
} | ||
|
||
return ( | ||
<StoryContext.Provider value={{ storyValue, updateStoryValue }}> | ||
{props.children} | ||
</StoryContext.Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useContext } from "react"; | ||
import { AuthContext } from "../contexts/AuthContext"; | ||
|
||
export function useAuth() { | ||
const value = useContext(AuthContext); | ||
|
||
return value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useContext } from "react"; | ||
import { StoryContext } from "../contexts/StoryContext"; | ||
|
||
export function useStory() { | ||
const value = useContext(StoryContext); | ||
|
||
return value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.