import React from "react"
import hljs from "highlight.js"
import LinkButton from "./util/linkButton"
MAX_HIGHLIGHT_LENGTH = 10 * 1024 # 10 KiB
class CodeViewer extends React.Component
constructor: (props) ->
super props
@state =
code: "Loading..."
highlight: true
componentDidMount: ->
resp = await fetch "/paste/#{@props.id}?original"
resp = await resp.text()
if resp.length < MAX_HIGHLIGHT_LENGTH
resp = hljs.highlightAuto(resp).value
else
@setState
highlight: false
@setState
code: resp
render: ->
if @state.switchToHome
return
{@state.code}}