Skip to content

Commit aea37f8

Browse files
committed
Fix a few bugs
1 parent 708976e commit aea37f8

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/js/App.vue

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<legend class="menu-settings-group-name howto">Display location</legend>
7272
<div class="menu-settings-input checkbox-input" v-for="menuLocation in menuLocations">
7373
<input type="checkbox" :id="`locations-${menuLocation.slug}`" :name="menuLocation.slug"
74-
:value="menuLocation.id" :checked="menuLocation.id === activeMenuId"/>
74+
:value="menuLocation.id" :checked="menuLocation.id === activeMenuId && activeMenuId !== 0"/>
7575
<label :for="`locations-${menuLocation.slug}`">{{menuLocation.label}}</label>
7676
<span v-if="menuLocation.id && menuLocation.id !== activeMenuId"
7777
class="theme-location-set">(Currently set to: {{getNavMenuNameById(menuLocation.id)}})
@@ -81,7 +81,8 @@
8181
</div>
8282
</div>
8383
<div class="vue-menus__main-footer">
84-
<a href="#" class="delete" @click.prevent="onDeleteMenu">Delete Menu</a>
84+
<a v-if="activeMenuId" href="#" class="delete" @click.prevent="onDeleteMenu">Delete Menu</a>
85+
<span v-else></span>
8586
<button type="button" class="button button-primary" @click="onSaveMenu">{{saveMenuText}}</button>
8687
</div>
8788
</div>
@@ -245,7 +246,10 @@
245246
(response) => {
246247
this.menus.push( response );
247248
this.menus.sort( sortBy( 'name' ) );
249+
this.updateMenuLocations( response.term_id );
250+
this.saveMenuSettings( response.term_id );
248251
this.activeMenuId = response.term_id;
252+
this.setSuccessMessage( `Menu "${response.name}" created!` );
249253
},
250254
(response) => {
251255
console.log( response );
@@ -284,18 +288,21 @@
284288
const index = findIndex( this.menus, {term_id: response.term_id} );
285289
this.menus[index] = response;
286290
this.menus.sort( sortBy( 'name' ) );
291+
this.updateMenuLocations( response.term_id );
292+
this.saveMenuSettings( response.term_id );
287293
this.activeMenuId = response.term_id;
294+
this.setSuccessMessage( `Menu "${response.name}" saved!` );
288295
},
289296
(response) => {
290297
console.log( response );
291298
this.setErrorMessage( 'Sorry, we were unable to save your menu.' );
292299
}
293300
);
294301
},
295-
saveMenuSettings() {
302+
saveMenuSettings(menuId) {
296303
this.fetch( {
297304
method: 'POST',
298-
path: `/wp/v2/menus/${this.activeMenuId}/settings`,
305+
path: `/wp/v2/menus/${menuId}/settings`,
299306
data: this.menuSettings
300307
} )
301308
.then(
@@ -355,8 +362,6 @@
355362
},
356363
onSaveMenu() {
357364
this.activeMenuId ? this.saveMenu() : this.createMenu();
358-
this.updateMenuLocations();
359-
this.saveMenuSettings();
360365
},
361366
onRemoveMenuItem(id) {
362367
const menuItem = find( this.menuItems, {ID: id} );
@@ -443,15 +448,15 @@
443448
} );
444449
return item;
445450
},
446-
updateMenuLocations() {
451+
updateMenuLocations(menuId) {
447452
Array.from( this.$el.querySelectorAll( '.menu-settings .menu-theme-locations input[type="checkbox"]' ) ).forEach( (input) => {
448453
const slug = input.getAttribute( 'name' );
449454
const id = parseInt( input.getAttribute( 'value' ), 10 );
450455
const checked = input.checked;
451-
if (!checked && id === this.activeMenuId) {
456+
if (!checked && id === menuId) {
452457
this.setMenuLocation( slug, 0 );
453458
} else if (checked) {
454-
this.setMenuLocation( slug, this.activeMenuId );
459+
this.setMenuLocation( slug, menuId );
455460
}
456461
} );
457462
}

src/scss/vue-menus.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@
4747
width: 90%;
4848
max-width: 382px;
4949
}
50-
.menu-item-handle {
51-
width: 100%;
52-
}
5350
}
5451

5552
.delete {

0 commit comments

Comments
 (0)