"use client"; import { Snippet } from "@nextui-org/snippet"; import { Code } from "@nextui-org/code"; import { Icon } from "@iconify/react"; import { Button, ScrollShadow, Select, SelectItem, } from "@nextui-org/react"; import { cn } from "@nextui-org/theme"; import React, { useCallback, useEffect, useRef, useState } from "react"; import { title } from "@/components/primitives"; import { ChapterItem, Chapters, readFile, splitChapter } from "./utils/chapter"; import { ChapterCard } from "@/components/ChapterCard"; export default function Home() { const [text,setText] = useState("") const [chapters,setChapters] = useState([]) const [activeChapter,setActiveChapter] = useState(null) const textareaRef = useRef(null) const onSplit = useCallback(async ()=>{ const dom = textareaRef.current if(!dom) return const index = dom.selectionStart if(index<0) return console.log("bookmark",index) const content = '====SPLIT CHAPTER====' setText(txt=>{ return txt.substring(0,index)+'\n'+content+"\n"+txt.substring(15) }) },[]) const onMergeNext = useCallback((chapter:ChapterItem)=>{ const current = chapters.findIndex(detail=>detail.key===chapter.key) if(current==-1) return const next = current+1 const nextChapter = chapters[next] if(!nextChapter) return chapter.text += ["",nextChapter.title,nextChapter.text].join("\n") const newChapters = chapters.slice() newChapters.splice(next,1) const newText = newChapters.reduce((txt,chapter)=>{ txt += chapter.rawTitle+'\n' txt += chapter.text+"\n" return txt },"") setText(newText) },[chapters]) const selectFile = useCallback(()=>{ const input = document.createElement("input") input.type = 'file' input.accept = '.txt' input.addEventListener("change",async function(event){ setActiveChapter(null) const [file] = input.files||[] if(!file) { setText("") return } console.time("read-txt") setText(await readFile(file)) console.timeEnd("read-txt") }) input.click() },[]) useEffect(()=>{ console.time("split-chapter") const chapters = splitChapter(text) setChapters(chapters) if(chapters.length>0) { setActiveChapter(1) } console.timeEnd("split-chapter") },[text]) return (
{/*
*/}

Chapter 1 - Chapter 1 title

{/* Adjusted to use flex display for layout */}