Skip to content

Commit

Permalink
Merge pull request #702 from aeternity/feature/refactoring
Browse files Browse the repository at this point in the history
Some refactoring
  • Loading branch information
mradkov authored Jul 13, 2020
2 parents ac146dd + 24609c3 commit f3e0852
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 80 deletions.
51 changes: 16 additions & 35 deletions src/components/ListOfTipsAndComments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,49 +58,32 @@
<div
v-if="showNoResultsMsg"
class="no-results"
:class="[error ? 'error' : '']"
:class="{ error }"
>
{{ $t('components.ListOfTipsAndComments.NoActivity') }}
</div>
<TipComment
v-for="(comment, index) in comments"
:key="index"
:comment="comment"
:sender-link="openExplorer(comment.author)"
/>
</div>
<div
v-if="activeTab === 'tips' && activity === 'channel'"
class="tips__container"
>
<div v-if="address === account">
<div
v-if="!pinnedItems.length"
class="no-results"
:class="[error ? 'error' : '']"
>
{{ $t('components.ListOfTipsAndComments.NoPinnedItems') }}
</div>
<TipRecord
v-for="pinnedItem in pinnedItems"
:key="pinnedItem.id"
:tip="pinnedItem"
/>
</div>
<div v-else>
<div
v-if="!userPinnedItems.length"
class="no-results"
:class="[error ? 'error' : '']"
>
{{ $t('components.ListOfTipsAndComments.NoPinnedItems') }}
</div>
<TipRecord
v-for="userPinnedItem in userPinnedItems"
:key="userPinnedItem.id"
:tip="userPinnedItem"
/>
<div
v-if="!pinnedItems.length"
class="no-results"
:class="{ error }"
>
{{ $t('components.ListOfTipsAndComments.NoPinnedItems') }}
</div>
<TipRecord
v-for="pinnedItem in pinnedItems"
:key="pinnedItem.id"
:tip="pinnedItem"
/>
</div>
</div>
</div>
Expand All @@ -110,7 +93,6 @@
import { mapState } from 'vuex';
import Backend from '../utils/backend';
import { EventBus } from '../utils/eventBus';
import { EXPLORER_URL } from '../config/constants';
import Loading from './Loading.vue';
import TipsPagination from './TipsPagination.vue';
import TipComment from './tipRecords/TipComment.vue';
Expand All @@ -131,7 +113,6 @@ export default {
},
props: { address: { type: String, required: true } },
data: () => ({
explorerUrl: `${EXPLORER_URL}account/transactions/`,
showLoading: false,
error: false,
comments: [],
Expand All @@ -140,7 +121,10 @@ export default {
userPinnedItems: [],
}),
computed: {
...mapState(['loading', 'pinnedItems', 'account']),
...mapState(['loading', 'account']),
pinnedItems() {
return this.address === this.account ? this.$store.state.pinnedItems : this.userPinnedItems;
},
showNoResultsMsg() {
return this.activeTab === 'comments'
&& this.comments.length === 0 && !this.showLoading && !this.loading.tips;
Expand Down Expand Up @@ -168,9 +152,6 @@ export default {
setActiveTab(tab) {
this.activeTab = tab;
},
openExplorer(address) {
return this.explorerUrl + address;
},
reloadData() {
this.showLoading = true;
Backend.getUserComments(this.address)
Expand Down
2 changes: 1 addition & 1 deletion src/components/TipInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ import Loading from './Loading.vue';
import AeButton from './AeButton.vue';
import AeAmountFiat from './AeAmountFiat.vue';
import Modal from './Modal.vue';
import { i18n } from '../utils/i18nHelper';
import i18n from '../utils/i18nHelper';
export default {
name: 'TipInput',
Expand Down
5 changes: 0 additions & 5 deletions src/components/TipsPagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
:key="tip.id"
:tip="tip"
:fiat-value="tip.fiatValue"
:sender-link="openExplorer(tip.sender)"
/>
<Loading
v-if="loadingMoreTips"
Expand All @@ -30,7 +29,6 @@
import { times } from 'lodash-es';
import Loading from './Loading.vue';
import Backend from '../utils/backend';
import { MIDDLEWARE_URL } from '../config/constants';
import TipRecord from './tipRecords/TipRecord.vue';
import { EventBus } from '../utils/eventBus';
Expand Down Expand Up @@ -117,9 +115,6 @@ export default {
)).flat();
this.loadingTips = false;
},
openExplorer(address) {
return `${MIDDLEWARE_URL}account/transactions/${address}`;
},
},
};
</script>
5 changes: 0 additions & 5 deletions src/components/tipRecords/TipComment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
import { mapState } from 'vuex';
import FormatDate from './FormatDate.vue';
import Avatar from '../Avatar.vue';
import Backend from '../../utils/backend';
import TipInput from '../TipInput.vue';
export default {
Expand Down Expand Up @@ -116,10 +115,6 @@ export default {
},
},
methods: {
getAvatar(address) {
const userImage = Backend.getProfileImageUrl(address);
return userImage || this.defaultAvatar;
},
goToCommentPage(tipId, id) {
this.$router.push({
name: 'comment',
Expand Down
2 changes: 0 additions & 2 deletions src/components/tipRecords/TipRecord.vue
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ export default {
},
props: {
tip: { type: Object, required: true },
foundWallet: { type: Boolean },
senderLink: { type: String, default: '' },
},
data() {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { sync } from 'vuex-router-sync';
import App from './App.vue';
import store from './store';
import router from './router';
import { i18n } from './utils/i18nHelper';
import i18n from './utils/i18nHelper';

Vue.use(VueRouter);

Expand Down
2 changes: 1 addition & 1 deletion src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const routes = [
},
},
{
path: '/admin/tracing/:id',
path: '/admin/tracing/:tipId',
name: 'tracing',
props: true,
component: Tracing,
Expand Down
22 changes: 1 addition & 21 deletions src/utils/i18nHelper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint no-param-reassign: ["error", { "ignorePropertyModificationsFor": ["state"] }] */
/* eslint-disable global-require */

import Vue from 'vue';
import VueI18n from 'vue-i18n';
import en from '../locales/en.json';
Expand All @@ -9,26 +6,9 @@ Vue.use(VueI18n);

const fallbackLocale = 'en';

export const i18n = new VueI18n({
export default new VueI18n({
locale: fallbackLocale,
fallbackLocale,
formatFallbackMessages: true,
messages: { en },
});

export const langs = {
en: {
getMessages: () => require('../locales/en.json'),
},
zh: {
getMessages: () => require(/* webpackChunkName: "locale-zh" */ '../locales/zh.json'),
},
};

export const fetchAndSetLocale = async (languageCode) => {
if (!i18n.availableLocales.includes(languageCode)) {
const messages = (await langs[languageCode].getMessages());
i18n.setLocaleMessage(languageCode, messages);
}
i18n.locale = languageCode;
};
2 changes: 1 addition & 1 deletion src/utils/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { get } from 'lodash-es';
import BigNumber from 'bignumber.js';
import { EventBus } from './eventBus';
import { i18n } from './i18nHelper';
import i18n from './i18nHelper';

const atomsToAe = (atoms) => (new BigNumber(atoms)).dividedBy(new BigNumber(1000000000000000000));
const aeToAtoms = (ae) => (new BigNumber(ae)).times(new BigNumber(1000000000000000000));
Expand Down
7 changes: 4 additions & 3 deletions src/views/SingleComment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
</template>

<script>
// eslint-disable-next-line import/no-cycle
import Backend from '../utils/backend';
import TipComment from '../components/tipRecords/TipComment.vue';
import Page from '../components/layout/Page.vue';
Expand All @@ -58,13 +57,15 @@ export default {
TipComment,
SendComment,
},
props: {
id: { type: [String, Number], required: true },
tipId: { type: [String, Number], required: true },
},
data() {
return {
id: this.$route.params.id,
showLoading: true,
error: false,
comment: null,
tipId: this.$route.params.tipId,
};
},
created() {
Expand Down
5 changes: 3 additions & 2 deletions src/views/TipComments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

<script>
import { mapState } from 'vuex';
// eslint-disable-next-line import/no-cycle
import Backend from '../utils/backend';
import TipRecord from '../components/tipRecords/TipRecord.vue';
import TipCommentList from '../components/tipRecords/TipCommentList.vue';
Expand All @@ -58,9 +57,11 @@ export default {
Page,
SendComment,
},
props: {
id: { type: [String, Number], required: true },
},
data() {
return {
id: this.$route.params.id,
showLoading: true,
comments: [],
error: false,
Expand Down
3 changes: 1 addition & 2 deletions src/views/UserProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ export default {
data() {
return {
maxLength: 250,
explorerUrl: `${EXPLORER_URL}account/transactions/`,
error: false,
userStats: null,
editMode: false,
Expand Down Expand Up @@ -360,7 +359,7 @@ export default {
}
},
openExplorer(address) {
return this.explorerUrl + address;
return `${EXPLORER_URL}account/transactions/${address}`;
},
resetEditedValues() {
this.editMode = false;
Expand Down
4 changes: 3 additions & 1 deletion src/views/admin/Tracing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ import FormatDate from '../../components/tipRecords/FormatDate.vue';
export default {
name: 'Tracing',
components: { FormatDate, AeAmount },
props: {
tipId: { type: [String, Number], required: true },
},
data() {
return {
tipId: this.$route.params.id,
backendTrace: null,
blockchainTrace: null,
expandedTrace: null,
Expand Down

1 comment on commit f3e0852

@mradkov
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.