/** * OxiCloud - Shared View Component * In-app shared files view. All operations go through the backend API. */ const sharedView = { // State items: [], filteredItems: [], currentItem: null, /** Auth header helper */ _headers(json = false) { const h = {}; const token = localStorage.getItem('oxicloud_token'); if (token) h['Authorization'] = `Bearer ${token}`; if (json) h['Content-Type'] = 'application/json'; return h; }, init() { console.log('Initializing shared view component (API-backed)'); this.loadItems(); }, show() { this.displayUI(); this.attachEventListeners(); this.loadItems().then(() => this.filterAndSortItems()); }, hide() { const c = document.getElementById('shared-container'); if (c) c.style.display = 'none'; }, // Load shared items from backend API async loadItems() { try { const res = await fetch('/api/shares?page=1&per_page=1000', { headers: this._headers() }); if (res.ok) { const data = await res.json(); this.items = data.items || []; } else { this.items = []; } } catch (err) { console.error('Error loading shared items:', err); this.items = []; } this.filteredItems = [...this.items]; }, // Create and display the shared view UI displayUI() { const contentArea = document.querySelector('.content-area'); let container = document.getElementById('shared-container'); if (!container) { container = document.createElement('div'); container.id = 'shared-container'; container.className = 'shared-view-container'; if (contentArea) contentArea.appendChild(container); } container.style.display = 'block'; container.innerHTML = `