- 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 />
<Tabs />
<div class="contents">
<Lines />
<Code v-if="$store.state.mode == 'view'" />
<Textarea v-else />
</div>
</section>
</template>
<script>
import Nav from '~/components/Nav.vue'
import Tabs from '~/components/Tabs.vue'
import Textarea from '~/components/Textarea.vue'
import Code from '~/components/Code.vue'
import Lines from '~/components/Lines.vue'
import axios from 'axios'
//dUHRuycnC
export default {
components: {
Nav,
Code,
Textarea,
Lines,
Tabs
},
mounted ()
{
console.log('mounted id')
},
/**
* 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.getters.viewContent)
{
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')
}
catch (e)
{
console.log(e)
console.log('-- ERR')
}
}
},
// Ctrl + r switches to edit mode
mounted ()
{
window.onkeydown = (e) => {
if ((e.ctrlKey && e.code === "KeyR") )
{
// Prevent refreshing
e.preventDefault()
this.$store.commit('SET_MODE', 'edit')
this.$nextTick().then( () => {
let scrollHeight = document.querySelector('body').scrollHeight
let scrollHeightText = document.querySelector('textarea').scrollHeight
let offsetHeight = document.querySelector('body').offsetHeight
if (scrollHeight > offsetHeight)
{
document.querySelector('textarea').style.height = `${scrollHeightText}px`
}
})
}
}
}
}
</script>