Skip to content

Commit

Permalink
Linting refactor (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
lanedirt committed Feb 7, 2025
1 parent 5594c1a commit 24d9999
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 18 deletions.
49 changes: 33 additions & 16 deletions browser-extensions/chrome/src/app/pages/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useCallback } from 'react';
import { DISABLED_SITES_KEY } from '../../contentScript/Popup';

interface PopupSettings {
/**
* Popup settings type.
*/
type PopupSettings = {
disabledUrls: string[];
currentUrl: string;
isEnabled: boolean;
}

/**
* Settings page component.
*/
const Settings: React.FC = () => {
const [settings, setSettings] = useState<PopupSettings>({
disabledUrls: [],
currentUrl: '',
isEnabled: true
});

useEffect(() => {
loadSettings();
}, []);

const getCurrentTab = async () => {
/**
* Get current tab in browser.
*/
const getCurrentTab = async () : Promise<chrome.tabs.Tab> => {
const queryOptions = { active: true, currentWindow: true };
const [tab] = await chrome.tabs.query(queryOptions);
return tab;
};

const loadSettings = async () => {
/**
* Load settings.
*/
const loadSettings = useCallback(async () : Promise<void> => {
const tab = await getCurrentTab();
const currentUrl = new URL(tab.url || '').hostname;

Expand All @@ -37,9 +45,16 @@ const Settings: React.FC = () => {
isEnabled: !disabledUrls.includes(currentUrl)
});
});
};
}, []); // No dependencies needed since it only uses external APIs

const toggleCurrentSite = async () => {
useEffect(() => {
loadSettings();
}, [loadSettings]);

/**
* Toggle current site.
*/
const toggleCurrentSite = async () : Promise<void> => {
const { currentUrl, disabledUrls, isEnabled } = settings;
let newDisabledUrls = [...disabledUrls];

Expand All @@ -59,8 +74,10 @@ const Settings: React.FC = () => {
}));
};

const resetSettings = async () => {
// Fix: Use DISABLED_SITES_KEY as the key name here too
/**
* Reset settings.
*/
const resetSettings = async () : Promise<void> => {
const storageData = { [DISABLED_SITES_KEY]: [] };
await chrome.storage.local.set(storageData);

Expand All @@ -79,11 +96,11 @@ const Settings: React.FC = () => {

<div className="space-y-4">
<div>
<div className="text-gray-500 dark:text-gray-400 space-y-2 mb-4">
<p className="text-sm">
<div className="text-gray-500 dark:text-gray-400 space-y-2 mb-4">
<p className="text-sm">
You can enable or disable the autofill popup per site.
</p>
</div>
</p>
</div>
<div className="flex items-center justify-between p-4 bg-gray-50 dark:bg-gray-800 rounded-lg">
<div>
<p className="text-sm font-medium text-gray-900 dark:text-white">{settings.currentUrl}</p>
Expand Down
6 changes: 4 additions & 2 deletions browser-extensions/chrome/src/contentScript/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,10 @@ function triggerInputEvents(element: HTMLInputElement) : void {
// Create an overlay div that will show the highlight effect
const overlay = document.createElement('div');

// Initial positioning
const updatePosition = () => {
/**
* Update position of the overlay.
*/
const updatePosition = () : void => {
const rect = element.getBoundingClientRect();
overlay.style.cssText = `
position: fixed;
Expand Down
3 changes: 3 additions & 0 deletions browser-extensions/chrome/src/shared/types/Credential.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Credential SQLite database type.
*/
export type Credential = {
Id: string;
Username: string;
Expand Down
3 changes: 3 additions & 0 deletions browser-extensions/chrome/src/shared/types/EncryptionKey.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Encryption key SQLite database type.
*/
export type EncryptionKey = {
Id: string;
PublicKey: string;
Expand Down
12 changes: 12 additions & 0 deletions browser-extensions/chrome/src/shared/types/webapi/Attachment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
/**
* Email attachment type.
*/
export type Attachment = {
/** The ID of the attachment */
id: number;

/** The ID of the email the attachment belongs to */
emailId: number;

/** The filename of the attachment */
filename: string;

/** The MIME type of the attachment */
mimeType: string;

/** The size of the attachment in bytes */
filesize: number;
}
6 changes: 6 additions & 0 deletions browser-extensions/chrome/src/shared/types/webapi/Login.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/**
* Login request type.
*/
export type LoginRequest = {
username: string;
}

/**
* Login response type.
*/
export type LoginResponse = {
salt: string;
serverEphemeral: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { MailboxEmail } from "./MailboxEmail";

/**
* Mailbox bulk request type.
*/
export type MailboxBulkRequest = {
addresses: string[];
page: number;
pageSize: number;
}

/**
* Mailbox bulk response type.
*/
export type MailboxBulkResponse = {
addresses: string[];
currentPage: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/**
* Validate login request type.
*/
export type ValidateLoginRequest = {
username: string;
rememberMe: boolean;
clientPublicEphemeral: string;
clientSessionProof: string;
}

/**
* Validate login request type for 2FA.
*/
export type ValidateLoginRequest2Fa = {
username: string;
code2Fa: number;
Expand All @@ -13,6 +19,9 @@ export type ValidateLoginRequest2Fa = {
clientSessionProof: string;
}

/**
* Validate login response type.
*/
export type ValidateLoginResponse = {
requiresTwoFactor: boolean;
token?: {
Expand Down
3 changes: 3 additions & 0 deletions browser-extensions/chrome/src/shared/types/webapi/Vault.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Vault type.
*/
export type Vault = {
blob: string;
createdAt: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Vault } from "./Vault";

/**
* Vault response type.
*/
export type VaultResponse = {
status: number;
vault: Vault;
Expand Down

0 comments on commit 24d9999

Please sign in to comment.