Skip to content

Commit

Permalink
♻️ use nullish coalescing operator and optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
zetaraku committed Jul 16, 2023
1 parent de16c91 commit 3b270d9
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion components/SheetDataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ watch(sheets, () => {
</template>

<template #item.category="{ item: sheet }">
<span>{{ (sheet.category || '').replaceAll('|', '') }}</span>
<span>{{ (sheet.category ?? '').replaceAll('|', '') }}</span>
</template>
<template #item.title="{ item: sheet }">
<v-btn
Expand Down
10 changes: 5 additions & 5 deletions components/SheetDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ watch(isOpened, () => {
class="text-truncate"
style="margin-right: 80px;"
>
<span>{{ (sheet.category || 'N/A').replaceAll('|', '') }}</span>
<span>{{ (sheet.category ?? 'N/A').replaceAll('|', '') }}</span>
</h3>

<!-- Title -->
Expand All @@ -176,7 +176,7 @@ watch(isOpened, () => {
class="pb-2 text-truncate"
style="margin-right: 42px;"
>
<span>{{ sheet.artist || 'N/A' }}</span>
<span>{{ sheet.artist ?? 'N/A' }}</span>
</h4>

<!-- Difficulty & Level -->
Expand Down Expand Up @@ -209,14 +209,14 @@ watch(isOpened, () => {
<!-- Note Designer -->
<h4 class="pt-2 text-truncate">
<span v-text="$t('term.noteDesigner')" />:
<span>{{ sheet.noteDesigner || 'N/A' }}</span>
<span>{{ sheet.noteDesigner ?? 'N/A' }}</span>
</h4>

<!-- Release Date & Version -->
<h4 class="pt-2 text-truncate">
<span v-text="$t('term.releaseDate')" />:
<span>{{ sheet.releaseDate || '????-??-??' }}</span>
<span>({{ sheet.version || 'N/A' }})</span>
<span>{{ sheet.releaseDate ?? '????-??-??' }}</span>
<span>({{ sheet.version ?? 'N/A' }})</span>
</h4>
</div>

Expand Down
8 changes: 4 additions & 4 deletions components/SheetFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const filterOptions: Ref<FilterOptions> = inject('filterOptions')!;
:items="(!filters.useInternalLevel ? filterOptions.levels : filterOptions.internalLevels)"
prepend-icon="mdi-numeric-9-plus-box-multiple-outline"
:label="(!filters.useInternalLevel ? $t('term.minLevel') : $t('term.minInternalLevel'))"
:placeholder="(((!filters.useInternalLevel ? filterOptions.levels : filterOptions.internalLevels) || [])[0] || { text: '?' }).text"
:placeholder="((!filters.useInternalLevel ? filterOptions.levels : filterOptions.internalLevels)?.[0] ?? { text: '?' }).text"
persistent-placeholder
clearable
/>
Expand All @@ -85,7 +85,7 @@ const filterOptions: Ref<FilterOptions> = inject('filterOptions')!;
v-model="filters.maxLevelValue"
:items="(!filters.useInternalLevel ? filterOptions.levels : filterOptions.internalLevels)"
:label="(!filters.useInternalLevel ? $t('term.maxLevel') : $t('term.maxInternalLevel'))"
:placeholder="(((!filters.useInternalLevel ? filterOptions.levels : filterOptions.internalLevels) || []).slice(-1)[0] || { text: '?' }).text"
:placeholder="((!filters.useInternalLevel ? filterOptions.levels : filterOptions.internalLevels)?.slice(-1)[0] ?? { text: '?' }).text"
persistent-placeholder
clearable
/>
Expand Down Expand Up @@ -210,7 +210,7 @@ const filterOptions: Ref<FilterOptions> = inject('filterOptions')!;
:min="0"
prepend-icon="mdi-metronome"
:label="$t('term.minBPM')"
:placeholder="String(filterOptions.bpms[0] || 0)"
:placeholder="String(filterOptions.bpms[0] ?? 0)"
persistent-placeholder
clearable
/>
Expand All @@ -221,7 +221,7 @@ const filterOptions: Ref<FilterOptions> = inject('filterOptions')!;
type="number"
:min="0"
:label="$t('term.maxBPM')"
:placeholder="String(filterOptions.bpms.slice(-1)[0] || 999)"
:placeholder="String(filterOptions.bpms.slice(-1)[0] ?? 999)"
persistent-placeholder
clearable
/>
Expand Down
2 changes: 1 addition & 1 deletion components/SheetTile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const {

<!-- sheet title (if the default cover image is used) -->
<span
v-if="(sheet.imageName || '').endsWith('default-cover.png') && !hideCover"
v-if="(sheet.imageName ?? '').endsWith('default-cover.png') && !hideCover"
class="CoverTitle"
v-text="sheet.title"
/>
Expand Down
8 changes: 4 additions & 4 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ useHead(() => {
siteDescriptionJp,
} = context.$config;
const subSiteTitle = gameTitle.value ? `${gameTitle.value} | ${siteTitle}` : siteTitle;
const subSiteTitle = gameTitle.value != null ? `${gameTitle.value} | ${siteTitle}` : siteTitle;
const pageUrl = new URL(`${gameCode.value ?? ''}/`, siteUrl).toString();
const logoUrl = new URL('logo.png?v=1', siteUrl).toString();
const descriptionEn = String(siteDescriptionEn).replace('______', gameTitle.value || 'arcade games');
const descriptionJp = String(siteDescriptionJp).replace('______', gameTitle.value || '音ゲー');
const descriptionEn = String(siteDescriptionEn).replace('______', gameTitle.value ?? 'arcade games');
const descriptionJp = String(siteDescriptionJp).replace('______', gameTitle.value ?? '音ゲー');
return {
title: 'N/A',
Expand Down Expand Up @@ -238,7 +238,7 @@ export default defineComponent({
v-text="$config.siteTitle"
/>
<v-list-item-subtitle
v-text="gameTitle || 'made by @zetaraku'"
v-text="gameTitle ?? 'made by @zetaraku'"
/>
</v-list-item-content>
</v-toolbar-title>
Expand Down
2 changes: 1 addition & 1 deletion pages/_gameCode/song.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default defineComponent({
<span v-text="$t('term.releaseDate')" />
</th>
<td>
<span>{{ (song.releaseDate || '').replaceAll('-', '/') }}</span>
<span>{{ (song.releaseDate ?? '').replaceAll('-', '/') }}</span>
</td>
</tr>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion pages/_gameCode/songs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default defineComponent({
</template>

<template #item.category="{ item: song }">
<span>{{ (song.category || '').replaceAll('|', '') }}</span>
<span>{{ (song.category ?? '').replaceAll('|', '') }}</span>
</template>
<template #item.title="{ item: song }">
<router-link
Expand Down
2 changes: 1 addition & 1 deletion utils/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export function filterSheets(sheets: Sheet[], filters: Filters) {
}
if (filters.categories.length !== 0) {
result = result.filter((sheet) => filters.categories.some(
(category) => sheet.category === category || (sheet.category?.split('|').includes(category) ?? false),
(category) => sheet.category === category || (sheet.category != null && sheet.category.split('|').includes(category)),
));
}
if (filters.title != null) {
Expand Down

0 comments on commit 3b270d9

Please sign in to comment.