- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
<template>
<section class="container">
<Nav />
<Textarea />
</section>
</template>
<script>
import Nav from '~/components/Nav.vue'
import Textarea from '~/components/Textarea.vue'
import VueHighlightJS from 'vue-highlightjs'
import axios from 'axios'
export default {
components: {
Nav,
Textarea
},
head () {
return {
title: 'tabbit',
meta: [
{ hid: 'description', name: 'description', content: 'Pastebin with tabs' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
{ rel: 'stylesheet', href: 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/routeros.min.css'}
]
}
},
mounted ()
{
let self = this
window.onkeydown = function(e) {
if ((e.ctrlKey && e.code === "KeyR") )
{
// Prevent refreshing
e.preventDefault()
self.$store.commit('SET_MODE', 'edit')
self.$nextTick().then( () => {
window.document.querySelector('textarea').focus()
let contentHeight = document.querySelector('html').scrollHeight
document.querySelector('textarea').style.height = `${contentHeight}px`
document.querySelector('.modes').style.height = `${contentHeight}px`
})
}
}
},
/**
* We only need to fetch if the user is coming from a hard
* page load. if they were transferred here after creating a paste,
* the paste is already stored in the $store, no need to fetch.
* And we check if it's a hard reload by checking to see if
* there is a value for `state.content`.
*/
async fetch ({ store, params })
{
if (!store.state.content)
{
let id = params.id
let uri = `https://us-central1-tabbit-1313.cloudfunctions.net/get/?id=${params.id}`
try
{
let { data } = await axios.get(uri)
store.commit('UPDATE_ENTRIES', data.payload.paste)
store.commit('SET_ACTIVE_ENTRY', 0)
store.commit('SET_MODE', 'view')
store.commit('SET_CONTENT', data.payload.paste[0].content)
}
catch (e)
{
console.log(e)
console.log('-- ERR')
}
}
}
}
</script>
<style lang="stylus" >
.hljs
padding 0 0 0 0!important
</style>