import React, { useState, useEffect } from 'react'; import { Plus, FileText, Presentation } from 'lucide-react'; import api from '@/lib/api'; interface FileItem { name: string; path: string; is_dir: boolean; size: number; mime_type: string; is_pinned: boolean; is_trashed: boolean; mod_time: string; } interface OfficeHomeProps { type: 'docs' | 'slides'; onFileSelect: (file: FileItem) => void; onCreateBlank: (file: FileItem) => void; } export default function OfficeHome({ type, onFileSelect, onCreateBlank }: OfficeHomeProps) { const [recentFiles, setRecentFiles] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { // Fetch all files from root directory (as a simple way to find recent files of this type) // Or we could use a search endpoint. For now we will fetch the root directory and filter. api.listFiles('.') .then(files => { const ext = type === 'docs' ? '.docx' : '.pptx'; const filtered = files .filter(f => !f.is_dir && f.name.endsWith(ext) && !f.is_trashed) .sort((a, b) => new Date(b.mod_time).getTime() - new Date(a.mod_time).getTime()) .slice(0, 10); setRecentFiles(filtered); setLoading(false); }) .catch(err => { console.error(err); setLoading(false); }); }, [type]); const handleCreateBlank = async () => { try { const res = await api.client.post('/onlyoffice/create', { type: type === 'docs' ? 'word' : 'slide' }); const { path, name } = res.data; const newFile: FileItem = { name, path, is_dir: false, size: 0, mime_type: type === 'docs' ? 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' : 'application/vnd.openxmlformats-officedocument.presentationml.presentation', is_pinned: false, is_trashed: false, mod_time: new Date().toISOString() }; onCreateBlank(newFile); } catch (err) { console.error("Failed to create document", err); } }; const title = type === 'docs' ? 'Documents' : 'Presentations'; const Icon = type === 'docs' ? FileText : Presentation; const colorClass = type === 'docs' ? 'text-blue-500' : 'text-amber-500'; return (
{/* Top Banner (Template Gallery placeholder) */}

Start a new document

{/* Blank Document */}
Blank
{/* Recent Documents */}

Recent {title.toLowerCase()}

{loading ? (
Loading...
) : recentFiles.length === 0 ? (
No recent {title.toLowerCase()} found.
) : (
{recentFiles.map(file => (
{file.name}
))}
)}
); }