Skip to content

Commit a186c33

Browse files
committed
Add lock button.
1 parent 210c72c commit a186c33

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

components/lineup/Lineup.vue

+18-3
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,36 @@ import { useSortable } from '@vueuse/integrations/useSortable'
33
44
import { nanoid } from 'nanoid';
55
6-
import type { Lineup, AppSettings } from '~~/types';
6+
import type { Spot, Lineup, AppSettings } from '~~/types';
77
88
const lineup = useLocalStorage<Lineup>('lineup', {
99
id: nanoid(),
1010
teamName: '',
1111
spots: []
12+
}, {
13+
mergeDefaults: true
1214
});
1315
const appSettings = useLocalStorage<AppSettings>('app-settings', {
16+
isLineupLocked: false,
1417
jerseyColor: 'f47373',
1518
jerseyTextColor: '000000'
19+
}, {
20+
mergeDefaults: true
1621
});
1722
1823
const sortableContainer = ref<HTMLElement | null>(null);
1924
useSortable(sortableContainer, lineup.value.spots, {
2025
group: 'spots',
2126
handle: '.drag-handle',
22-
animation: 150
27+
animation: 150,
28+
onMove: () => !appSettings.value.isLineupLocked
2329
});
30+
31+
function addSpot(spot: Spot) {
32+
if (!appSettings.value.isLineupLocked) {
33+
lineup.value.spots.push(spot);
34+
}
35+
}
2436
</script>
2537

2638
<template>
@@ -34,6 +46,8 @@ useSortable(sortableContainer, lineup.value.spots, {
3446
placeholder="Team Name"
3547
/>
3648

49+
<SettingsLockButton :is-locked="appSettings.isLineupLocked" @lock="appSettings.isLineupLocked = true" @unlock="appSettings.isLineupLocked = false" />
50+
3751
<SettingsButton :app-settings="appSettings" />
3852
</header>
3953

@@ -43,6 +57,7 @@ useSortable(sortableContainer, lineup.value.spots, {
4357
v-for="spot in lineup.spots"
4458
:key="spot.player.id"
4559
:spot="spot"
60+
:is-lineup-locked="appSettings.isLineupLocked"
4661
:jersey-color="appSettings.jerseyColor"
4762
:jersey-text-color="appSettings.jerseyTextColor"
4863
@delete="lineup.spots = lineup.spots.filter(s => s.player.id !== $event)"
@@ -52,7 +67,7 @@ useSortable(sortableContainer, lineup.value.spots, {
5267
</div>
5368

5469
<footer>
55-
<LineupNewSpot @add="lineup.spots.push($event)" />
70+
<LineupNewSpot @add="addSpot($event)" :class="`${ appSettings.isLineupLocked ? 'collapse' : 'visible' }`" />
5671
</footer>
5772
</div>
5873
</template>

components/lineup/LineupSpot.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PositionOptions } from '~~/types';
44
55
const props = defineProps<{
66
spot: Spot,
7+
isLineupLocked: boolean,
78
jerseyColor: string,
89
jerseyTextColor: string
910
}>();
@@ -30,7 +31,7 @@ const isPositionDialogVisible = ref(false);
3031
@blur="focused = false"
3132
tabindex="0"
3233
>
33-
<LineupDragHandle class="inline-block shrink-0 text-[1.3em] px-2" />
34+
<LineupDragHandle :class="`${ props.isLineupLocked ? 'collapse' : 'visible' } inline-block shrink-0 text-[1.3em] px-2`" />
3435

3536
<PlayerJersey :player="props.spot.player" :jersey-color="props.jerseyColor" :jersey-text-color="props.jerseyTextColor" class="shrink-0" />
3637

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<script setup lang="ts">
2+
const props = defineProps<{
3+
isLocked: boolean
4+
}>();
5+
6+
const emit = defineEmits<{
7+
(e: "lock"): void;
8+
(e: "unlock"): void;
9+
}>();
10+
11+
const isLocked = ref(props.isLocked);
12+
13+
function handleClick(): void {
14+
isLocked.value = !isLocked.value;
15+
16+
if (isLocked.value) {
17+
emit('lock');
18+
} else {
19+
emit('unlock');
20+
}
21+
}
22+
</script>
23+
24+
<template>
25+
<Button
26+
@click="handleClick"
27+
:icon="`pi pi-${ isLocked ? 'lock' : 'lock-open' }`"
28+
:severity="`${ isLocked ? 'secondary' : 'warning' }`"
29+
text
30+
rounded
31+
:aria-label="`${ isLocked ? 'Unlock lineup' : 'Lock lineup' }`"
32+
:title="`${ isLocked ? 'Unlock lineup' : 'Lock lineup' }`"
33+
/>
34+
</template>

types/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface Lineup {
3434
};
3535

3636
export interface AppSettings {
37+
isLineupLocked: boolean,
3738
jerseyColor: string,
3839
jerseyTextColor: string,
3940
};

0 commit comments

Comments
 (0)