feat(links): route to selected link

This commit is contained in:
SabreCat
2023-03-17 16:37:16 -05:00
parent 3a4620976e
commit 8cd706fd95
5 changed files with 24 additions and 23 deletions

View File

@@ -366,12 +366,6 @@
class="btn btn-secondary" class="btn btn-secondary"
@click="makeAdmin()" @click="makeAdmin()"
>Make Admin</a> >Make Admin</a>
<a
class="btn btn-danger"
@click="externalLinkModal()"
>
External Link Modal
</a>
</div> </div>
</div> </div>
</div> </div>
@@ -903,10 +897,6 @@ export default {
donate () { donate () {
this.$root.$emit('bv::show::modal', 'buy-gems', { alreadyTracked: true }); this.$root.$emit('bv::show::modal', 'buy-gems', { alreadyTracked: true });
}, },
externalLinkModal () {
this.$root.$emit('bv::show::modal', 'external-link-modal');
console.log('Hi!');
},
}, },
}; };
</script> </script>

View File

@@ -39,7 +39,7 @@
<button <button
v-once v-once
class="btn btn-primary" class="btn btn-primary"
@click="close()" @click="proceed()"
> >
{{ $t('continue') }} {{ $t('continue') }}
</button> </button>
@@ -51,9 +51,14 @@
@import '~@/assets/scss/colors.scss'; @import '~@/assets/scss/colors.scss';
#external-link-modal { #external-link-modal {
&.modal {
display: flex !important;
}
.modal-md { .modal-md {
max-width: 448px; max-width: 448px;
min-width: 330px; min-width: 330px;
margin: auto;
.modal-close { .modal-close {
position: absolute; position: absolute;
@@ -142,12 +147,25 @@ export default {
close: closeIcon, close: closeIcon,
exclamation: exclamationIcon, exclamation: exclamationIcon,
}), }),
url: '',
}; };
}, },
mounted () {
this.$root.$on('habitica:external-link', url => {
this.url = url;
this.$root.$emit('bv::show::modal', 'external-link-modal');
});
},
beforeDestroy () {
this.$root.$off('habitica:external-link');
},
methods: { methods: {
close () { close () {
this.$root.$emit('bv::hide::modal', 'external-link-modal'); this.$root.$emit('bv::hide::modal', 'external-link-modal');
console.log('Bye!'); },
proceed () {
window.open(this.url, '_blank').focus();
this.close();
}, },
}, },
}; };

View File

@@ -14,10 +14,10 @@ export default function markdown (el, { value, oldValue }) {
for (let i = 0; i < allLinks.length; i += 1) { for (let i = 0; i < allLinks.length; i += 1) {
const link = allLinks[i]; const link = allLinks[i];
// todo middleclick or ctrl+click to open it in a new tab
// todo? should a normal click leave the current page or also open it in a new tab?
// ... hopefully this wont create memory leaks
link.addEventListener('click', e => { link.addEventListener('click', e => {
if (e.ctrlKey) {
return;
}
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();

View File

@@ -43,5 +43,5 @@ const vueInstance = new Vue({
export default vueInstance; export default vueInstance;
window.externalLink = url => { window.externalLink = url => {
vueInstance.$root.$emit('bv::show::modal', 'external-link-modal', url); vueInstance.$root.$emit('habitica:external-link', url);
}; };

View File

@@ -377,8 +377,6 @@ const router = new VueRouter({
], ],
}, },
{ name: 'externalLink', path: '/external' },
// Only used to handle some redirects // Only used to handle some redirects
// See router.beforeEach // See router.beforeEach
{ path: '/redirect/:redirect', name: 'redirect' }, { path: '/redirect/:redirect', name: 'redirect' },
@@ -395,11 +393,6 @@ router.beforeEach(async (to, from, next) => {
if (to.name === 'redirect') return handleRedirect(to, from, next); if (to.name === 'redirect') return handleRedirect(to, from, next);
if (to.name === 'externalLink') {
setTimeout(() => router.app.$emit('bv::show::modal', 'external-link-modal'), 500);
return null;
}
if (!isUserLoggedIn && routeRequiresLogin) { if (!isUserLoggedIn && routeRequiresLogin) {
// Redirect to the login page unless the user is trying to reach the // Redirect to the login page unless the user is trying to reach the
// root of the website, in which case show the home page. // root of the website, in which case show the home page.