mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Improve types
This commit is contained in:
@@ -11,9 +11,12 @@ import type { UserProfile } from "../core/types";
|
|||||||
import { showError, showSuccess } from "../utils/notification";
|
import { showError, showSuccess } from "../utils/notification";
|
||||||
import { formatTime } from "../utils/utils";
|
import { formatTime } from "../utils/utils";
|
||||||
import defaultAvatar from "../resources/images/default-avatar.png";
|
import defaultAvatar from "../resources/images/default-avatar.png";
|
||||||
|
import type { Tabs } from "mdui/components/tabs";
|
||||||
|
import type { Dialog } from "mdui/components/dialog";
|
||||||
|
import type { TextField } from "mdui/components/text-field";
|
||||||
|
|
||||||
|
|
||||||
let dialog = document.getElementById("user-profile-dialog")!;
|
let dialog = document.getElementById("user-profile-dialog") as Dialog;
|
||||||
let currentProfile: UserProfile | null = null;
|
let currentProfile: UserProfile | null = null;
|
||||||
let isOwnProfile: boolean = false;
|
let isOwnProfile: boolean = false;
|
||||||
|
|
||||||
@@ -34,13 +37,6 @@ function bindEvents(): void {
|
|||||||
editBioBtn?.addEventListener('click', () => startEditBio());
|
editBioBtn?.addEventListener('click', () => startEditBio());
|
||||||
saveBioBtn?.addEventListener('click', () => saveBio());
|
saveBioBtn?.addEventListener('click', () => saveBio());
|
||||||
cancelBioBtn?.addEventListener('click', () => cancelEditBio());
|
cancelBioBtn?.addEventListener('click', () => cancelEditBio());
|
||||||
|
|
||||||
// Keyboard shortcuts
|
|
||||||
document.addEventListener('keydown', (e) => {
|
|
||||||
if (e.key === 'Escape' && dialog?.getAttribute('open') !== null) {
|
|
||||||
hide();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,7 +59,7 @@ export async function show(username: string): Promise<void> {
|
|||||||
currentProfile = profile;
|
currentProfile = profile;
|
||||||
isOwnProfile = profile.username === currentUser?.username;
|
isOwnProfile = profile.username === currentUser?.username;
|
||||||
populateDialog(profile);
|
populateDialog(profile);
|
||||||
(dialog as any).open = true;
|
dialog.open = true;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showError('Failed to load user profile');
|
showError('Failed to load user profile');
|
||||||
@@ -108,7 +104,7 @@ function populateDialog(profile: UserProfile): void {
|
|||||||
|
|
||||||
// Bio
|
// Bio
|
||||||
const bioDisplay = dialog.querySelector('.bio-display') as HTMLElement;
|
const bioDisplay = dialog.querySelector('.bio-display') as HTMLElement;
|
||||||
const bioEdit = dialog.querySelector('#bio-edit-field') as any;
|
const bioEdit = dialog.querySelector('#bio-edit-field') as TextField;
|
||||||
|
|
||||||
if (profile.bio) {
|
if (profile.bio) {
|
||||||
bioDisplay.textContent = profile.bio;
|
bioDisplay.textContent = profile.bio;
|
||||||
@@ -136,7 +132,7 @@ function startEditBio(): void {
|
|||||||
if (!dialog) return;
|
if (!dialog) return;
|
||||||
|
|
||||||
const bioDisplay = dialog.querySelector('.bio-display') as HTMLElement;
|
const bioDisplay = dialog.querySelector('.bio-display') as HTMLElement;
|
||||||
const bioEdit = dialog.querySelector('#bio-edit-field') as any;
|
const bioEdit = dialog.querySelector('#bio-edit-field') as TextField;
|
||||||
const bioActions = dialog.querySelector('.bio-actions') as HTMLElement;
|
const bioActions = dialog.querySelector('.bio-actions') as HTMLElement;
|
||||||
const editBioBtn = dialog.querySelector('#edit-bio-btn') as HTMLElement;
|
const editBioBtn = dialog.querySelector('#edit-bio-btn') as HTMLElement;
|
||||||
|
|
||||||
@@ -158,7 +154,7 @@ function startEditBio(): void {
|
|||||||
export async function saveBio(): Promise<void> {
|
export async function saveBio(): Promise<void> {
|
||||||
if (!dialog || !currentProfile) return;
|
if (!dialog || !currentProfile) return;
|
||||||
|
|
||||||
const bioEdit = dialog.querySelector('#bio-edit-field') as any;
|
const bioEdit = dialog.querySelector('#bio-edit-field') as TextField;
|
||||||
const newBio = bioEdit?.value?.trim() || '';
|
const newBio = bioEdit?.value?.trim() || '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -195,7 +191,7 @@ function cancelEditBio(): void {
|
|||||||
if (!dialog) return;
|
if (!dialog) return;
|
||||||
|
|
||||||
const bioDisplay = dialog.querySelector('.bio-display') as HTMLElement;
|
const bioDisplay = dialog.querySelector('.bio-display') as HTMLElement;
|
||||||
const bioEdit = dialog.querySelector('#bio-edit-field') as any;
|
const bioEdit = dialog.querySelector('#bio-edit-field') as TextField;
|
||||||
const bioActions = dialog.querySelector('.bio-actions') as HTMLElement;
|
const bioActions = dialog.querySelector('.bio-actions') as HTMLElement;
|
||||||
const editBioBtn = dialog.querySelector('#edit-bio-btn') as HTMLElement;
|
const editBioBtn = dialog.querySelector('#edit-bio-btn') as HTMLElement;
|
||||||
|
|
||||||
@@ -214,9 +210,7 @@ function cancelEditBio(): void {
|
|||||||
* Hides the dialog
|
* Hides the dialog
|
||||||
*/
|
*/
|
||||||
export function hide(): void {
|
export function hide(): void {
|
||||||
if (dialog) {
|
dialog.open = false;
|
||||||
(dialog as any).open = false;
|
|
||||||
}
|
|
||||||
currentProfile = null;
|
currentProfile = null;
|
||||||
isOwnProfile = false;
|
isOwnProfile = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,8 +111,8 @@ function setupFormHandler(): void {
|
|||||||
|
|
||||||
// Get DOM elements
|
// Get DOM elements
|
||||||
profileForm = document.getElementById('profile-form')!;
|
profileForm = document.getElementById('profile-form')!;
|
||||||
nicknameField = document.getElementById('username-field') as any;
|
nicknameField = document.getElementById('username-field') as TextField;
|
||||||
descriptionField = document.getElementById('description-field') as any;
|
descriptionField = document.getElementById('description-field') as TextField;
|
||||||
|
|
||||||
profileForm.addEventListener('submit', handleFormSubmission);
|
profileForm.addEventListener('submit', handleFormSubmission);
|
||||||
|
|
||||||
|
|||||||
+18
-21
@@ -1,25 +1,22 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"useDefineForClassFields": true,
|
"useDefineForClassFields": true,
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
|
|
||||||
/* Bundler mode */
|
/* Bundler mode */
|
||||||
"moduleResolution": "bundler",
|
"moduleResolution": "bundler",
|
||||||
"allowImportingTsExtensions": true,
|
"allowImportingTsExtensions": true,
|
||||||
"verbatimModuleSyntax": true,
|
"verbatimModuleSyntax": true,
|
||||||
"moduleDetection": "force",
|
"moduleDetection": "force",
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
|
|
||||||
/* Linting */
|
/* Linting */
|
||||||
"strict": true,
|
"erasableSyntaxOnly": true,
|
||||||
"noUnusedLocals": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
"noUnusedParameters": true,
|
"noUncheckedSideEffectImports": true
|
||||||
"erasableSyntaxOnly": true,
|
},
|
||||||
"noFallthroughCasesInSwitch": true,
|
"include": ["src"]
|
||||||
"noUncheckedSideEffectImports": true
|
|
||||||
},
|
|
||||||
"include": ["src"]
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user