Skip to content

Commit

Permalink
feature: configure new games
Browse files Browse the repository at this point in the history
  • Loading branch information
wilcorrea committed Apr 10, 2024
1 parent 6787b22 commit c8184e0
Show file tree
Hide file tree
Showing 11 changed files with 621 additions and 557 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ VITE_BASE_PATH=/quiz
VITE_IN_MEMORY_TIMEOUT=200
VITE_GAME_QUESTION_TIMEOUT=30

VITE_BACKEND_MODE=supabase
VITE_BACKEND_MODE=memory

VITE_SUPABASE_URL=https://<project>.supabase.co
VITE_SUPABASE_ANON_KEY=<your-anon-key>
Expand Down
5 changes: 5 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
display: block;
background-color: #ffffff;
color: #565656;
padding: 4px 6px;
border-radius: 6px;
}

.PublicLayout .GamePlaySessionQuestionUnanswered > .card > .card-header code {
Expand Down
31 changes: 31 additions & 0 deletions src/app/Infrastructure/InMemory/InMemoryAuthRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import AuthRepository from '../../Domain/Auth/AuthRepository.ts'
import { Session } from '../../Domain/Auth/Auth.ts'
import InMemoryRepository from './InMemoryRepository.ts'

export default class InMemoryAuthRepository extends InMemoryRepository implements AuthRepository {
restore (): Promise<Session> {
return this.promisify({
username: 'memory',
abilities: []
})
}

signIn (username: string, password: string): Promise<Session> {
return this.promisify({
username: username + ':' + password,
abilities: []
})
}

signInWithOtp (username: string): Promise<Session> {
return this.promisify({
username: username,
abilities: []
})
}

signOut (): Promise<boolean> {
return Promise.resolve(true)
}

}
12 changes: 3 additions & 9 deletions src/app/Infrastructure/InMemory/InMemoryGameRepository.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import GameRepository from '../../Domain/Game/GameRepository.ts'
import Game from '../../Domain/Game/Game.ts'
import games from './games.ts'
import InMemoryRepository from './InMemoryRepository.ts'

export default class InMemoryGameRepository implements GameRepository {
export default class InMemoryGameRepository extends InMemoryRepository implements GameRepository {
private games: Game[]

constructor () {
super()
this.games = games()
}

async promisify <T>(data: T): Promise<T> {
const timeout = import.meta.env.VITE_IN_MEMORY_TIMEOUT || 300
return new Promise((resolve) => {
const handler = () => resolve(data)
window.setTimeout(handler, Number(timeout))
})
}

async paginate (page: number, limit: number): Promise<Game[]> {
return this.promisify(this.games.slice((page - 1) * limit, page * limit))
}
Expand Down
9 changes: 9 additions & 0 deletions src/app/Infrastructure/InMemory/InMemoryRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default class InMemoryRepository {
async promisify <T>(data: T): Promise<T> {
const timeout = import.meta.env.VITE_IN_MEMORY_TIMEOUT || 300
return new Promise((resolve) => {
const handler = () => resolve(data)
window.setTimeout(handler, Number(timeout))
})
}
}
Loading

0 comments on commit c8184e0

Please sign in to comment.