Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
feat(tabs): switched from 'ident' to 'id' as identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
herteleo committed Apr 19, 2019
1 parent 575650f commit 3fa8cb1
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/components/TabHeader.vue
Expand Up @@ -16,7 +16,7 @@
@click="$emit('toggleDevTools')"
/>
<title-bar-button
:to="{ name: 'tabs-settings', params: { ident: item.ident } }"
:to="{ name: 'tabs-settings', params: { id: item.id } }"
icon="dots-vertical"
/>
</title-bar>
Expand All @@ -42,7 +42,7 @@ export default {
return this.$store.getters['Settings/isLayoutInvertedForOs'];
},
pageState() {
return this.$store.getters['Pages/state'](this.item.ident);
return this.$store.getters['Pages/state'](this.item.id);
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/TabMain.vue
Expand Up @@ -35,7 +35,7 @@ export default {
},
computed: {
isActive() {
return parseInt(this.$route.params.ident, 0) === this.item.ident;
return parseInt(this.$route.params.id, 0) === this.item.id;
},
webview() {
return this.$refs.webview.$refs.webview;
Expand All @@ -44,7 +44,7 @@ export default {
watch: {
isActive(isActive) {
if (isActive) {
this.$store.commit('Tabs/activateIdent', this.item.ident);
this.$store.commit('Tabs/activateId', this.item.id);
this.webview.focus();
}
},
Expand Down
6 changes: 3 additions & 3 deletions src/components/TabWebview.vue
Expand Up @@ -48,7 +48,7 @@ export default {
this.$store.commit('Notifications/add', {
notification,
tabIdent: this.item.ident,
tabId: this.item.id,
});
if (!this.notificationsPreventOnBlur || this.windowHasFocus) {
Expand All @@ -58,7 +58,7 @@ export default {
this.$refs.webview.addEventListener('page-title-updated', ({ title }) => {
this.$store.commit('Pages/setState', {
tabId: this.item.ident,
tabId: this.item.id,
data: { title },
});
});
Expand All @@ -67,7 +67,7 @@ export default {
const [favicon] = favicons;
this.$store.commit('Pages/setState', {
tabId: this.item.ident,
tabId: this.item.id,
data: { favicon },
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/TabsList.vue
Expand Up @@ -5,7 +5,7 @@
>
<tab-main
v-for="tab in $store.getters['Tabs/list']"
:key="tab.ident"
:key="tab.id"
:item="tab"
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/TabsNav.vue
Expand Up @@ -9,7 +9,7 @@
>
<tabs-nav-item
v-for="tab in tabList"
:key="tab.ident"
:key="tab.id"
:item="tab"
/>
</vue-draggable>
Expand Down
4 changes: 2 additions & 2 deletions src/components/TabsNavItem.vue
@@ -1,6 +1,6 @@
<template>
<router-link
:to="{ name: 'tabs', params: { ident: item.ident } }"
:to="{ name: 'tabs', params: { id: item.id } }"
:class="$style.item"
:active-class="$style.active"
tag="button"
Expand Down Expand Up @@ -38,7 +38,7 @@ export default {
},
computed: {
pageState() {
return this.$store.getters['Pages/state'](this.item.ident);
return this.$store.getters['Pages/state'](this.item.id);
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/router/index.js
Expand Up @@ -16,12 +16,12 @@ export default new Router({
component: () => import(/* webpackChunkName: "tabs" */ '@/views/TabSettings.vue'),
},
{
path: '/tabs/:ident/settings',
path: '/tabs/:id/settings',
name: 'tabs-settings',
component: () => import(/* webpackChunkName: "tabs" */ '@/views/TabSettings.vue'),
},
{
path: '/tabs/:ident?',
path: '/tabs/:id?',
name: 'tabs',
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/Notifications.js
Expand Up @@ -48,11 +48,11 @@ export default {
},
},
mutations: {
add(state, { tabIdent, notification }) {
add(state, { tabId, notification }) {
db().get('notifications')
.push({
notification,
tabIdent,
tabId,
timestamp: Date.now(),
})
.write();
Expand Down
34 changes: 17 additions & 17 deletions src/store/modules/Tabs.js
Expand Up @@ -11,15 +11,15 @@ const db = new Connection({
export default {
namespaced: true,
state: {
activeIdent: 0,
activeId: 0,
dbUpdated: Date.now(),
},
getters: {
active({ activeIdent, dbUpdated }) {
return db(dbUpdated).get('tabs').find(item => item.ident === activeIdent).value() || {};
active({ activeId, dbUpdated }) {
return db(dbUpdated).get('tabs').find(item => item.id === activeId).value() || {};
},
byIdent({ dbUpdated }) {
return ident => db(dbUpdated).get('tabs').find(item => item.ident === ident).value() || {};
byId({ dbUpdated }) {
return id => db(dbUpdated).get('tabs').find(item => item.id === id).value() || {};
},
list({ dbUpdated }) {
return db(dbUpdated)
Expand All @@ -30,12 +30,12 @@ export default {
listSorted({ dbUpdated }, { list }) {
const sorting = db(dbUpdated).get('sorting').value();

return [...list].sort((a, b) => sorting.indexOf(a.ident) - sorting.indexOf(b.ident));
return [...list].sort((a, b) => sorting.indexOf(a.id) - sorting.indexOf(b.id));
},
},
mutations: {
activateIdent(state, ident) {
state.activeIdent = ident;
activateId(state, id) {
state.activeId = id;
state.dbUpdated = Date.now();
},
create(state, item) {
Expand All @@ -46,43 +46,43 @@ export default {

db()
.get('sorting')
.push(item.ident)
.push(item.id)
.write();

state.dbUpdated = Date.now();
},
delete(state, item) {
db()
.get('tabs')
.remove(i => i.ident === item.ident)
.remove(i => i.id === item.id)
.write();

db()
.get('sorting')
.remove(i => i === item.ident)
.remove(i => i === item.id)
.write();

state.activateIdent = 0;
state.activateId = 0;
state.dbUpdated = Date.now();
},
setSorting(state, items) {
db().set('sorting', items.map(item => item.ident)).write();
db().set('sorting', items.map(item => item.id)).write();
state.dbUpdated = Date.now();
},
update(state, { ident, data }) {
update(state, { id, data }) {
db()
.get('tabs')
.find(i => i.ident === ident).assign(data)
.find(i => i.id === id).assign(data)
.write();

state.dbUpdated = Date.now();
},
},
actions: {
create({ commit }, payload = {}) {
const ident = Date.now();
const id = Date.now();
const item = {
ident,
id,
...payload,
};
commit('create', item);
Expand Down
2 changes: 1 addition & 1 deletion src/views/Notifications.vue
Expand Up @@ -18,7 +18,7 @@
v-for="item in notifications"
:key="item.timestamp"
:class="$style.item"
@click="$router.push({ name: 'tabs', params: { ident: item.tabIdent }})"
@click="$router.push({ name: 'tabs', params: { id: item.tabId }})"
>
<div :class="$style.thumb">
<img
Expand Down
12 changes: 6 additions & 6 deletions src/views/TabSettings.vue
Expand Up @@ -94,8 +94,8 @@ export default {
created() {
if (this.isCreateMode) return;
const { ident } = this.$route.params;
this.tab = this.$store.getters['Tabs/byIdent'](ident);
const { id } = this.$route.params;
this.tab = this.$store.getters['Tabs/byId'](id);
},
methods: {
submitForm() {
Expand All @@ -111,17 +111,17 @@ export default {
this.$router.push({
name: 'tabs',
params: {
ident: tab.ident,
id: tab.id,
},
});
},
updateTab() {
const { ident, ...data } = this.tab;
this.$store.commit('Tabs/update', { ident, data });
const { id, ...data } = this.tab;
this.$store.commit('Tabs/update', { id, data });
this.$router.push({
name: 'tabs',
params: { ident: this.tab.ident },
params: { id: this.tab.id },
});
},
deleteTab() {
Expand Down

0 comments on commit 3fa8cb1

Please sign in to comment.