/** * @fileoverview Settings Page Component for Rantii * @author retoor * @description Application settings and preferences page * @keywords settings, page, preferences, options, config */ import { BaseComponent } from '../components/base-component.js'; class SettingsPage extends BaseComponent { init() { this.installHandler = () => this.render(); this.render(); this.bindEvents(); } render() { const isLoggedIn = this.isLoggedIn(); const user = this.getCurrentUser(); const canInstall = this.getApp()?.canInstall(); this.addClass('page', 'settings-page'); this.setHtml(`

Settings

${canInstall ? `

Install App

Install Rantii for quick access

` : ''} ${isLoggedIn ? `

Account

Logged in as ${user?.username || ''}
` : `

Account

Sign in to access all features

`}

Appearance

About

Rantii - A DevRant Client

Version 1.0.0

Made with care by retoor

Data

`); } bindEvents() { this.on(this, 'click', this.handleClick); window.addEventListener('rantii:install-available', this.installHandler); window.addEventListener('rantii:app-installed', this.installHandler); } onDisconnected() { window.removeEventListener('rantii:install-available', this.installHandler); window.removeEventListener('rantii:app-installed', this.installHandler); } handleClick(e) { const backBtn = e.target.closest('.back-btn'); const loginBtn = e.target.closest('.login-btn'); const logoutBtn = e.target.closest('.logout-btn'); const clearCacheBtn = e.target.closest('.clear-cache-btn'); const installBtn = e.target.closest('.install-btn'); if (backBtn) { window.history.back(); return; } if (loginBtn) { this.getRouter()?.goToLogin(); return; } if (logoutBtn) { this.logout(); return; } if (clearCacheBtn) { this.clearCache(); return; } if (installBtn) { this.installApp(); } } async installApp() { const installed = await this.getApp()?.installApp(); if (installed) { this.getApp()?.toast?.success('App installed'); this.render(); } } logout() { this.getAuth()?.logout(); this.render(); this.getApp()?.toast?.success('Signed out successfully'); } clearCache() { const storage = this.getStorage(); if (storage) { storage.clear(); storage.setTheme(this.getTheme()?.getTheme() || 'dark'); } this.getApp()?.toast?.success('Cache cleared'); } } customElements.define('settings-page', SettingsPage); export { SettingsPage };