Skip to content

Commit

Permalink
feat(game-lobby): auto-focus on player name input (#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinezanardi authored Sep 12, 2024
1 parent 6e771c3 commit 7897da3
Show file tree
Hide file tree
Showing 15 changed files with 50,423 additions and 49,824 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.output
.data
.nuxt
.nuxt-test-cucumber
.nitro
.cache
dist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
id="player-name-input"
v-model="inputValue"
aria-labelledby="player-name-input-help"
:autofocus="!isOnTouchDevice"
:class="{ 'p-invalid': doesPlayerNameExistInGame }"
:disabled="isInputDisabled"
:maxlength="MAX_PLAYER_NAME_LENGTH"
Expand Down Expand Up @@ -55,12 +56,15 @@ import { computed } from "vue";
import { MAX_PLAYERS_IN_GAME } from "~/composables/api/game/constants/game.constants";
import { MAX_PLAYER_NAME_LENGTH } from "~/composables/api/game/constants/player/player.constants";
import { useDevice } from "~/composables/misc/useDevice";
import { useCreateGameDtoStore } from "~/stores/game/create-game-dto/useCreateGameDtoStore";
const { t } = useI18n();
const createGameDtoStore = useCreateGameDtoStore();
const { isOnTouchDevice } = useDevice();
const { createGameDto } = storeToRefs(createGameDtoStore);
const inputValue = defineModel<string>({ required: true });
Expand Down
17 changes: 17 additions & 0 deletions app/composables/misc/useDevice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { ComputedRef } from "vue";

type UseDevice = {
isOnTouchDevice: ComputedRef<boolean>;
};

function useDevice(): UseDevice {
const isOnTouchDevice = computed<boolean>(() => "ontouchstart" in window || navigator.maxTouchPoints > 0);

return {
isOnTouchDevice,
};
}

export {
useDevice,
};
1 change: 1 addition & 0 deletions config/eslint/flat-configs/eslint.global-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const ESLINT_GLOBAL_CONFIG = Object.freeze({
globals: {
window: READONLY,
process: READONLY,
navigator: READONLY,
Buffer: READONLY,
defineNuxtConfig: READONLY,
defineNuxtPlugin: READONLY,
Expand Down
1 change: 1 addition & 0 deletions modules/i18n/i18n.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineI18nConfig(() => {
return {
legacy: false,
locale: runtimeConfig.public.defaultLocale,
defaultLocale: runtimeConfig.public.defaultLocale,
messages: {
fr,
en,
Expand Down
6 changes: 2 additions & 4 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default defineNuxtConfig({
},
i18n: {
vueI18n: "./modules/i18n/i18n.config.ts",
defaultLocale: process.env.NUXT_PUBLIC_DEFAULT_LOCALE,
locales: [
{
code: "fr",
Expand All @@ -102,10 +103,7 @@ export default defineNuxtConfig({
strategy: "no_prefix",
},
image: {
domains: [
"antoinezanardi.fr",
"appspot.com",
],
domains: ["werewolves-assistant.com"],
},
linkChecker: {
enabled: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Feature: 🃏 Game Lobby Page
And the heading with name "Add player names with the input above" should be visible
And the button with name "Random composition" should be visible
And the button with name "Start game" should be visible
And the input with label "Player name" should be focused
And the page should match or creates the missing snapshot with name "Game Lobby Page without players"

Scenario: 🃏 Game Lobby page has valid head title and SEO tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ Then(/^the input with label "(?<label>.+?)" should be empty$/u, async function(t

Then(/^the input with label "(?<label>.+?)" should have placeholder "(?<placeholder>.+?)"$/u, async function(this: CustomWorld, label: string, placeholder: string): Promise<void> {
await expect(this.page.getByLabel(label)).toHaveAttribute("placeholder", placeholder);
});

Then(/^the input with label "(?<label>.+?)" should be focused$/u, async function(this: CustomWorld, label: string): Promise<void> {
await expect(this.page.getByLabel(label)).toBeFocused();
});
17 changes: 17 additions & 0 deletions tests/acceptance/features/support/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,28 @@ import type { CustomWorld } from "@tests/acceptance/shared/types/word.types";

const { beforeEach, afterEach, afterAll, setup } = createTest({
runner: "cucumber",
buildDir: ".nuxt-test-cucumber",
server: true,
browserOptions: {
type: "chromium",
launch: {
headless: true,
env: {
NUXT_PUBLIC_WEREWOLVES_ASSISTANT_API_BASE_URL: WEREWOLVES_ASSISTANT_SANDBOX_API_BASE_URL,
NUXT_PUBLIC_DEFAULT_LOCALE: I18N_TEST_LOCALE,
NUXT_SITE_URL: "http://127.0.0.1:4000",
NUXT_SITE_NAME: "Werewolves Assistant",
NUXT_SITE_ENV: "test",
NUXT_SITE_DESCRIPTION: "The perfect tool for game masters of the Werewolves of Miller's Hollow™",
},
},
},
rootDir: fileURLToPath(new URL("../../../..", import.meta.url)),
nuxtConfig: {
i18n: {
defaultLocale: I18N_TEST_LOCALE,
skipSettingLocaleOnNavigate: true,
locales: [{ code: "en", language: "en-US" }],
},
runtimeConfig: {
public: {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7897da3

Please sign in to comment.