import React, { useState } from 'react'
import { useSnapshot } from 'valtio'
import { useTheme } from 'next-themes'
import { useRouter } from 'next/router'
import NextLink from 'next/link'
import ReactTimeAgo from 'react-time-ago'
import filesize from 'filesize'
import Box from './Box'
import Container from './Container'
import state from '../state'
import wat from '../utils/wat-highlight'
import EditorNavigation from './EditorNavigation'
import { Button, Text, Link, Flex, Tabs, Tab } from '.'
import Monaco from './Monaco'
const FILESIZE_BREAKPOINTS: [number, number] = [2 * 1024, 5 * 1024]
const DeployEditor = () => {
const snap = useSnapshot(state)
const router = useRouter()
const { theme } = useTheme()
const [showContent, setShowContent] = useState(false)
const compiledFiles = snap.files.filter(file => file.compiledContent)
const activeFile = compiledFiles[snap.activeWat]
const renderNav = () => (
(state.activeWat = idx)}>
{compiledFiles.map((file, index) => {
return
})}
)
const compiledSize = activeFile?.compiledContent?.byteLength || 0
const color =
compiledSize > FILESIZE_BREAKPOINTS[1]
? '$error'
: compiledSize > FILESIZE_BREAKPOINTS[0]
? '$warning'
: '$success'
const isContentChanged = activeFile && activeFile.compiledValueSnapshot !== activeFile.content
// const hasDeployErrors = activeFile && activeFile.containsErrors;
const CompiledStatView = activeFile && (
Compiled {activeFile.name.split('.')[0] + '.wasm'}
{activeFile?.lastCompiled && }
{activeFile.compiledContent?.byteLength && (
({filesize(activeFile.compiledContent.byteLength)})
)}
{activeFile.compiledContent?.byteLength && activeFile.compiledContent?.byteLength >= 64000 && (
File size is larger than 64kB, cannot set hook!
)}
{isContentChanged && (
File contents were changed after last compile, compile again to incorporate your latest
changes in the build.
)}
)
const NoContentView = !snap.loading && router.isReady && (
{`You haven't compiled any files yet, compile files on `}
develop view
)
const isContent = snap.files?.filter(file => file.compiledWatContent).length > 0 && router.isReady
return (
{!isContent ? (
NoContentView
) : !showContent ? (
CompiledStatView
) : (
{
monaco.languages.register({ id: 'wat' })
monaco.languages.setLanguageConfiguration('wat', wat.config)
monaco.languages.setMonarchTokensProvider('wat', wat.tokens)
}}
onMount={editor => {
editor.updateOptions({
glyphMargin: true,
readOnly: true
})
}}
theme={theme === 'dark' ? 'dark' : 'light'}
overlay={
setShowContent(false)}>Exit editor mode
}
/>
)}
)
}
export default DeployEditor