Compare commits
3
Commits
df2a334d7c
...
b122cbb652
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b122cbb652 | ||
|
|
785cb6b7fc | ||
|
|
3368686201 |
@@ -3,22 +3,26 @@ import CodeInput from './components/CodeInput'
|
|||||||
import ProfileBar from './components/ProfileBar'
|
import ProfileBar from './components/ProfileBar'
|
||||||
import SearchScreen from './components/SearchScreen'
|
import SearchScreen from './components/SearchScreen'
|
||||||
import GameScreen from './components/GameScreen'
|
import GameScreen from './components/GameScreen'
|
||||||
import { useAuth } from './auth'
|
import { useAuth, useAuthModal } from './auth'
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const { token } = useAuth()
|
const { token } = useAuth()
|
||||||
|
const { openAuthModal } = useAuthModal()
|
||||||
const [screen, setScreen] = useState('menu') // 'menu' | 'search' | 'game'
|
const [screen, setScreen] = useState('menu') // 'menu' | 'search' | 'game'
|
||||||
const [gameSession, setGameSession] = useState(null)
|
const [gameSession, setGameSession] = useState(null)
|
||||||
|
|
||||||
const handleRandomBattle = () => {
|
const handleRandomBattle = () => {
|
||||||
|
if (!token) return openAuthModal()
|
||||||
setScreen('search')
|
setScreen('search')
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleInvite = () => {
|
const handleInvite = () => {
|
||||||
|
if (!token) return openAuthModal()
|
||||||
// TODO: создание приватной комнаты
|
// TODO: создание приватной комнаты
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleJoinByCode = (code) => {
|
const handleJoinByCode = (code) => {
|
||||||
|
if (!token) return openAuthModal()
|
||||||
// TODO: присоединение к комнате по коду
|
// TODO: присоединение к комнате по коду
|
||||||
console.log('join code:', code)
|
console.log('join code:', code)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,28 @@
|
|||||||
import { createContext, useContext, useEffect, useState, useCallback } from 'react'
|
import { createContext, useContext, useEffect, useState, useCallback } from 'react'
|
||||||
import { api } from './api'
|
import { api } from './api'
|
||||||
|
import AuthModal from './components/AuthModal'
|
||||||
|
|
||||||
const AuthContext = createContext(null)
|
const AuthContext = createContext(null)
|
||||||
|
const AuthModalContext = createContext(null)
|
||||||
const TOKEN_KEY = 'sea_battle_token'
|
const TOKEN_KEY = 'sea_battle_token'
|
||||||
|
|
||||||
|
export function AuthModalProvider({ children }) {
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
const openAuthModal = useCallback(() => setOpen(true), [])
|
||||||
|
const closeAuthModal = useCallback(() => setOpen(false), [])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AuthModalContext.Provider value={{ openAuthModal }}>
|
||||||
|
{children}
|
||||||
|
{open && <AuthModal onClose={closeAuthModal} />}
|
||||||
|
</AuthModalContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useAuthModal() {
|
||||||
|
return useContext(AuthModalContext)
|
||||||
|
}
|
||||||
|
|
||||||
export function AuthProvider({ children }) {
|
export function AuthProvider({ children }) {
|
||||||
const [user, setUser] = useState(null)
|
const [user, setUser] = useState(null)
|
||||||
const [token, setToken] = useState(() => localStorage.getItem(TOKEN_KEY))
|
const [token, setToken] = useState(() => localStorage.getItem(TOKEN_KEY))
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import { useState } from 'react'
|
import { useAuth, useAuthModal } from '../auth'
|
||||||
import { useAuth } from '../auth'
|
|
||||||
import AuthModal from './AuthModal'
|
|
||||||
|
|
||||||
export default function ProfileBar() {
|
export default function ProfileBar() {
|
||||||
const { user, loading, logout } = useAuth()
|
const { user, loading, logout } = useAuth()
|
||||||
const [showAuth, setShowAuth] = useState(false)
|
const { openAuthModal } = useAuthModal()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -26,12 +24,11 @@ export default function ProfileBar() {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<button className="btn btn-primary" onClick={() => setShowAuth(true)}>
|
<button className="btn btn-primary" onClick={openAuthModal}>
|
||||||
Войти
|
Войти
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{showAuth && <AuthModal onClose={() => setShowAuth(false)} />}
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import ReactDOM from 'react-dom/client'
|
import ReactDOM from 'react-dom/client'
|
||||||
import App from './App'
|
import App from './App'
|
||||||
import { AuthProvider } from './auth'
|
import { AuthProvider, AuthModalProvider } from './auth'
|
||||||
import './styles.css'
|
import './styles.css'
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<AuthProvider>
|
<AuthProvider>
|
||||||
<App />
|
<AuthModalProvider>
|
||||||
|
<App />
|
||||||
|
</AuthModalProvider>
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
</React.StrictMode>
|
</React.StrictMode>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ h1, h2, h3, h4, h5, h6 {
|
|||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input:not([type]), input[type="text"] {
|
||||||
font-size: 32px;
|
font-size: 32px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import (
|
|||||||
"github.com/ruby-sea-battle/game-server/internal/config"
|
"github.com/ruby-sea-battle/game-server/internal/config"
|
||||||
"github.com/ruby-sea-battle/game-server/internal/game"
|
"github.com/ruby-sea-battle/game-server/internal/game"
|
||||||
"github.com/ruby-sea-battle/game-server/internal/ws"
|
"github.com/ruby-sea-battle/game-server/internal/ws"
|
||||||
|
|
||||||
|
_ "github.com/joho/godotenv/autoload"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
@@ -6,3 +6,5 @@ require (
|
|||||||
github.com/coder/websocket v1.8.15
|
github.com/coder/websocket v1.8.15
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.1
|
github.com/golang-jwt/jwt/v5 v5.3.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require github.com/joho/godotenv v1.5.1 // indirect
|
||||||
|
|||||||
@@ -2,3 +2,5 @@ github.com/coder/websocket v1.8.15 h1:6B2JPeOGlpff2Uz6vOEH1Vzpi0iUz20A+lPVhPHtNU
|
|||||||
github.com/coder/websocket v1.8.15/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
|
github.com/coder/websocket v1.8.15/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
|
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
|
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
|
|||||||
@@ -51,3 +51,5 @@ gem "redis", "~> 6.0"
|
|||||||
group :test do
|
group :test do
|
||||||
gem "simplecov", require: false
|
gem "simplecov", require: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
gem "dotenv-rails", "~> 3.2", groups: [:development, :test]
|
||||||
|
|||||||
@@ -97,6 +97,9 @@ GEM
|
|||||||
reline (>= 0.3.8)
|
reline (>= 0.3.8)
|
||||||
diff-lcs (1.6.2)
|
diff-lcs (1.6.2)
|
||||||
dotenv (3.2.0)
|
dotenv (3.2.0)
|
||||||
|
dotenv-rails (3.2.0)
|
||||||
|
dotenv (= 3.2.0)
|
||||||
|
railties (>= 6.1)
|
||||||
drb (2.2.3)
|
drb (2.2.3)
|
||||||
ed25519 (1.4.0)
|
ed25519 (1.4.0)
|
||||||
erb (6.0.7)
|
erb (6.0.7)
|
||||||
@@ -378,6 +381,7 @@ DEPENDENCIES
|
|||||||
brakeman
|
brakeman
|
||||||
bundler-audit
|
bundler-audit
|
||||||
debug
|
debug
|
||||||
|
dotenv-rails (~> 3.2)
|
||||||
image_processing (~> 1.2)
|
image_processing (~> 1.2)
|
||||||
json (~> 2.19)
|
json (~> 2.19)
|
||||||
jwt (~> 2.10)
|
jwt (~> 2.10)
|
||||||
@@ -426,6 +430,7 @@ CHECKSUMS
|
|||||||
debug (1.11.1) sha256=2e0b0ac6119f2207a6f8ac7d4a73ca8eb4e440f64da0a3136c30343146e952b6
|
debug (1.11.1) sha256=2e0b0ac6119f2207a6f8ac7d4a73ca8eb4e440f64da0a3136c30343146e952b6
|
||||||
diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
|
diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
|
||||||
dotenv (3.2.0) sha256=e375b83121ea7ca4ce20f214740076129ab8514cd81378161f11c03853fe619d
|
dotenv (3.2.0) sha256=e375b83121ea7ca4ce20f214740076129ab8514cd81378161f11c03853fe619d
|
||||||
|
dotenv-rails (3.2.0) sha256=657e25554ba622ffc95d8c4f1670286510f47f2edda9f68293c3f661b303beab
|
||||||
drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373
|
drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373
|
||||||
ed25519 (1.4.0) sha256=16e97f5198689a154247169f3453ef4cfd3f7a47481fde0ae33206cdfdcac506
|
ed25519 (1.4.0) sha256=16e97f5198689a154247169f3453ef4cfd3f7a47481fde0ae33206cdfdcac506
|
||||||
erb (6.0.7) sha256=c5ca6dc25b0ef974a44dc8f59fe847577122483b1968a38dec305c60bf91ee92
|
erb (6.0.7) sha256=c5ca6dc25b0ef974a44dc8f59fe847577122483b1968a38dec305c60bf91ee92
|
||||||
|
|||||||
Reference in New Issue
Block a user