Skip to content

Commit

Permalink
Type browser actions and reducers
Browse files Browse the repository at this point in the history
  • Loading branch information
Cal-L committed Dec 17, 2024
1 parent 0c9b815 commit a8ee335
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 47 deletions.
79 changes: 56 additions & 23 deletions app/actions/browser/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import { BrowserActionTypes } from './types';
import {
BrowserActionTypes,
type BrowserRequestLoadAction,
type BrowserLoadEndAction,
type BrowserLoadStartAction,
type AddToViewedDappAction,
type AddToHistoryAction,
type ClearHistoryAction,
type AddToWhitelistAction,
type CloseAllTabsAction,
type CreateNewTabAction,
type CloseTabAction,
type SetActiveTabAction,
type UpdateTabAction,
type StoreFaviconAction,
} from './types';

export * from './types';

Expand All @@ -8,7 +23,7 @@ export * from './types';
* @param {string} hostname - Dapp hostname
* @returns
*/
export function addToViewedDapp(hostname: string) {
export function addToViewedDapp(hostname: string): AddToViewedDappAction {
return {
type: BrowserActionTypes.ADD_TO_VIEWED_DAPP,
hostname,
Expand All @@ -22,9 +37,15 @@ export function addToViewedDapp(hostname: string) {
* @param {string} website.url - The website's url
* @param {string} website.name - The website name
*/
export function addToHistory({ url, name }: { url: string; name: string }) {
export function addToHistory({
url,
name,
}: {
url: string;
name: string;
}): AddToHistoryAction {
return {
type: 'ADD_TO_BROWSER_HISTORY',
type: BrowserActionTypes.ADD_TO_BROWSER_HISTORY,
url,
name,
};
Expand All @@ -33,9 +54,9 @@ export function addToHistory({ url, name }: { url: string; name: string }) {
/**
* Clears the entire browser history
*/
export function clearHistory() {
export function clearHistory(): ClearHistoryAction {
return {
type: 'CLEAR_BROWSER_HISTORY',
type: BrowserActionTypes.CLEAR_BROWSER_HISTORY,
id: Date.now(),
};
}
Expand All @@ -45,19 +66,19 @@ export function clearHistory() {
*
* @param {string} url - The website's url
*/
export function addToWhitelist(url: string) {
export function addToWhitelist(url: string): AddToWhitelistAction {
return {
type: 'ADD_TO_BROWSER_WHITELIST',
type: BrowserActionTypes.ADD_TO_BROWSER_WHITELIST,
url,
};
}

/**
* Closes all the opened tabs
*/
export function closeAllTabs() {
export function closeAllTabs(): CloseAllTabsAction {
return {
type: 'CLOSE_ALL_TABS',
type: BrowserActionTypes.CLOSE_ALL_TABS,
};
}

Expand All @@ -67,9 +88,12 @@ export function closeAllTabs() {
* @param {string} url - The website's url
* @param {string} linkType - optional link type
*/
export function createNewTab(url: string, linkType: string) {
export function createNewTab(
url: string,
linkType: string,
): CreateNewTabAction {
return {
type: 'CREATE_NEW_TAB',
type: BrowserActionTypes.CREATE_NEW_TAB,
url,
linkType,
id: Date.now(),
Expand All @@ -81,9 +105,9 @@ export function createNewTab(url: string, linkType: string) {
*
* @param {number} id - The Tab ID
*/
export function closeTab(id: string) {
export function closeTab(id: string): CloseTabAction {
return {
type: 'CLOSE_TAB',
type: BrowserActionTypes.CLOSE_TAB,
id,
};
}
Expand All @@ -93,9 +117,9 @@ export function closeTab(id: string) {
*
* @param {number} id - The Tab ID
*/
export function setActiveTab(id: string) {
export function setActiveTab(id: string): SetActiveTabAction {
return {
type: 'SET_ACTIVE_TAB',
type: BrowserActionTypes.SET_ACTIVE_TAB,
id,
};
}
Expand All @@ -106,9 +130,12 @@ export function setActiveTab(id: string) {
* @param {number} id - The Tab ID
* @param {string} url - The website's url
*/
export function updateTab(id: string, data: { url: string; image?: string }) {
export function updateTab(
id: string,
data: { url: string; image?: string },
): UpdateTabAction {
return {
type: 'UPDATE_TAB',
type: BrowserActionTypes.UPDATE_TAB,
id,
data,
};
Expand All @@ -121,9 +148,15 @@ export function updateTab(id: string, data: { url: string; image?: string }) {
* @param {string} favicon.url - the favicon image url
* @returns {{favicon, type: string}}
*/
export function storeFavicon({ origin, url }: { origin: string; url: string }) {
export function storeFavicon({
origin,
url,
}: {
origin: string;
url: string;
}): StoreFaviconAction {
return {
type: 'STORE_FAVICON_URL',
type: BrowserActionTypes.STORE_FAVICON_URL,
origin,
url,
};
Expand All @@ -132,7 +165,7 @@ export function storeFavicon({ origin, url }: { origin: string; url: string }) {
/**
* Triggers when the browser requests to load
*/
export function setBrowserRequestLoad() {
export function setBrowserRequestLoad(): BrowserRequestLoadAction {
return {
type: BrowserActionTypes.SET_BROWSER_REQUEST_LOAD,
};
Expand All @@ -142,7 +175,7 @@ export function setBrowserRequestLoad() {
* Triggers when the browser starts load
* @param url - The website's url
*/
export function setBrowserLoadStart(url: string) {
export function setBrowserLoadStart(url: string): BrowserLoadStartAction {
return {
type: BrowserActionTypes.SET_BROWSER_LOAD_START,
payload: {
Expand All @@ -155,7 +188,7 @@ export function setBrowserLoadStart(url: string) {
* Triggers when the browser ends load
* @param url - The website's url
*/
export function setBrowserLoadEnd(url: string) {
export function setBrowserLoadEnd(url: string): BrowserLoadEndAction {
return {
type: BrowserActionTypes.SET_BROWSER_LOAD_END,
payload: {
Expand Down
99 changes: 99 additions & 0 deletions app/actions/browser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,103 @@ export enum BrowserActionTypes {
SET_BROWSER_REQUEST_LOAD = 'SET_BROWSER_REQUEST_LOAD',
SET_BROWSER_LOAD_START = 'SET_BROWSER_LOAD_START',
SET_BROWSER_LOAD_END = 'SET_BROWSER_LOAD_END',
ADD_TO_BROWSER_HISTORY = 'ADD_TO_BROWSER_HISTORY',
CLEAR_BROWSER_HISTORY = 'CLEAR_BROWSER_HISTORY',
ADD_TO_BROWSER_WHITELIST = 'ADD_TO_BROWSER_WHITELIST',
CLOSE_ALL_TABS = 'CLOSE_ALL_TABS',
CREATE_NEW_TAB = 'CREATE_NEW_TAB',
CLOSE_TAB = 'CLOSE_TAB',
SET_ACTIVE_TAB = 'SET_ACTIVE_TAB',
UPDATE_TAB = 'UPDATE_TAB',
STORE_FAVICON_URL = 'STORE_FAVICON_URL',
}

export type AddToViewedDappAction = {

Check failure on line 20 in app/actions/browser/types.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Use an `interface` instead of a `type`
type: BrowserActionTypes.ADD_TO_VIEWED_DAPP;
hostname: string;
};

export type BrowserRequestLoadAction = {

Check failure on line 25 in app/actions/browser/types.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Use an `interface` instead of a `type`
type: BrowserActionTypes.SET_BROWSER_REQUEST_LOAD;
};

export type BrowserLoadStartAction = {

Check failure on line 29 in app/actions/browser/types.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Use an `interface` instead of a `type`
type: BrowserActionTypes.SET_BROWSER_LOAD_START;
payload: {
url: string;
};
};

export type BrowserLoadEndAction = {

Check failure on line 36 in app/actions/browser/types.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Use an `interface` instead of a `type`
type: BrowserActionTypes.SET_BROWSER_LOAD_END;
payload: {
url: string;
};
};

export type AddToHistoryAction = {

Check failure on line 43 in app/actions/browser/types.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Use an `interface` instead of a `type`
type: BrowserActionTypes.ADD_TO_BROWSER_HISTORY;
url: string;
name: string;
};

export type ClearHistoryAction = {

Check failure on line 49 in app/actions/browser/types.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Use an `interface` instead of a `type`
type: BrowserActionTypes.CLEAR_BROWSER_HISTORY;
id: number;
};

export type AddToWhitelistAction = {

Check failure on line 54 in app/actions/browser/types.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Use an `interface` instead of a `type`
type: BrowserActionTypes.ADD_TO_BROWSER_WHITELIST;
url: string;
};

export type CloseAllTabsAction = {

Check failure on line 59 in app/actions/browser/types.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Use an `interface` instead of a `type`
type: BrowserActionTypes.CLOSE_ALL_TABS;
};

export type CreateNewTabAction = {

Check failure on line 63 in app/actions/browser/types.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Use an `interface` instead of a `type`
type: BrowserActionTypes.CREATE_NEW_TAB;
url: string;
id: number;
linkType: string;
};

export type CloseTabAction = {

Check failure on line 70 in app/actions/browser/types.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Use an `interface` instead of a `type`
type: BrowserActionTypes.CLOSE_TAB;
id: string;
};

export type SetActiveTabAction = {
type: BrowserActionTypes.SET_ACTIVE_TAB;
id: string;
};

export type UpdateTabAction = {
type: BrowserActionTypes.UPDATE_TAB;
id: string;
data: {
url: string;
image?: string;
};
};

export type StoreFaviconAction = {
type: BrowserActionTypes.STORE_FAVICON_URL;
origin: string;
url: string;
};

export type BrowserAction =
| AddToViewedDappAction
| BrowserRequestLoadAction
| BrowserLoadStartAction
| BrowserLoadEndAction
| AddToHistoryAction
| ClearHistoryAction
| AddToWhitelistAction
| CloseAllTabsAction
| CreateNewTabAction
| CloseTabAction
| SetActiveTabAction
| UpdateTabAction
| StoreFaviconAction;
Loading

0 comments on commit a8ee335

Please sign in to comment.