Skip to content

Commit f12ca01

Browse files
committed
fix: update homepage URL and make tab URL optional in types
1 parent 0c67899 commit f12ca01

2 files changed

Lines changed: 26 additions & 17 deletions

File tree

src/features/browser/browserSlice.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { createSlice, nanoid, PayloadAction } from "@reduxjs/toolkit";
22
import { BrowserState, BrowserTab } from "./types";
33

44
const homePageUrl =
5-
process.env.EXPO_PUBLIC_HOME_PAGE_URL || "https://afnprojects.com";
5+
process.env.EXPO_PUBLIC_HOME_PAGE_URL || "https://www.google.com";
66

77
const initialState: BrowserState = {
88
tabs: [
99
{
1010
id: "1",
1111
url: homePageUrl,
12-
title: "Ali Fuat Numanoglu's Projects",
12+
title: "Homepage",
1313
isLoading: false,
1414
canGoBack: false,
1515
canGoForward: false,
@@ -25,21 +25,30 @@ const browserSlice = createSlice({
2525
name: "browser",
2626
initialState,
2727
reducers: {
28-
addTab: (state, action: PayloadAction<{ url?: string }>) => {
29-
const newTab: BrowserTab = {
30-
id: nanoid(),
31-
url: action.payload.url || homePageUrl,
32-
title: "New Tab",
33-
isLoading: false,
34-
canGoBack: false,
35-
canGoForward: false,
36-
activeScripts: [],
37-
};
38-
state.tabs.push(newTab);
39-
state.activeTabId = newTab.id;
40-
state.showTabs = false;
28+
addTab: {
29+
reducer: (state, action: PayloadAction<{ id: string; url?: string }>) => {
30+
const newTab: BrowserTab = {
31+
id: action.payload.id,
32+
url: action.payload.url || homePageUrl,
33+
title: "New Tab",
34+
isLoading: false,
35+
canGoBack: false,
36+
canGoForward: false,
37+
activeScripts: [],
38+
};
39+
state.tabs.push(newTab);
40+
state.activeTabId = newTab.id;
41+
state.showTabs = false;
42+
},
43+
prepare: (url?: string) => {
44+
return {
45+
payload: {
46+
id: nanoid(),
47+
url,
48+
},
49+
};
50+
},
4151
},
42-
4352
closeTab: (state, action: PayloadAction<string>) => {
4453
const tabId = action.payload;
4554
state.tabs = state.tabs.filter((tab) => tab.id !== tabId);

src/features/browser/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export interface BrowserTab {
22
id: string;
3-
url: string;
3+
url?: string;
44
title: string;
55
favicon?: string;
66
isLoading: boolean;

0 commit comments

Comments
 (0)