Skip to content
This repository has been archived by the owner on Jul 31, 2022. It is now read-only.

Commit

Permalink
refractor: Move delete code to store
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark1626 committed Apr 14, 2019
1 parent 4364939 commit ab9d7a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/components/TileSet.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@
methods: {
handleRemove(idx) {
event.stopPropagation();
this.store.get().sites[idx] = {
title: '',
url: '',
color: api.colors[Math.floor(Math.random() * 10)],
character: '-'
};
this.store.saveSites();
this.store.deleteSite(idx);
// this.store.saveSites();
},
handleClick(idx, url) {
if(!url || url === '') {
Expand All @@ -45,9 +40,13 @@
display: flex;
flex-wrap: wrap;
flex-direction: row;
width: 50vw;
margin: 20px;
padding: 0;
font-size: 1.3rem;
}
@media only screen and (min-width: 1000px) {
.page-tile-set {
width: 60vw;
}
}
</style>
20 changes: 20 additions & 0 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ class HomePageStore extends Store {
this.set({sites: sites});
}

deleteSite(idx) {
const sites = this.get().sites;
// Retain the old color
const deleteSiteColor = sites[idx].color;
const newSitesList = [
...sites.slice(0, idx),
{
title: '',
url: '',
color: deleteSiteColor,
character: '-'
},
...sites.slice(idx+1)
];
this.set({
sites: newSitesList
});
this.saveSites(newSitesList);
}

updateSite(idx, property, value) {
const sites = this.get().sites;
sites[idx][property] = value;
Expand Down

0 comments on commit ab9d7a6

Please sign in to comment.