Skip to content

Commit

Permalink
feat: add default tab setting
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoung19 committed Nov 20, 2024
1 parent 892e020 commit dbc4940
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
20 changes: 13 additions & 7 deletions popup/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { getClipboardSnapshot, watchClipboardSnapshot } from "~storage/clipboard
import { getEntryIdToTags, watchEntryIdToTags } from "~storage/entryIdToTags";
import { getFavoriteEntryIds, watchFavoriteEntryIds } from "~storage/favoriteEntryIds";
import { getSettings, watchSettings } from "~storage/settings";
import { Tab } from "~types/tab";
import { getEntries, watchEntries } from "~utils/storage";
import { defaultBorderColor } from "~utils/sx";

Expand All @@ -50,7 +51,7 @@ import {
} from "./states/atoms";

export const App = () => {
const [tab, setTab] = useState("all");
const [tab, setTab] = useState<Tab>(Tab.Enum.All);

const [search, setSearch] = useAtom(searchAtom);

Expand All @@ -69,7 +70,12 @@ export const App = () => {
(async () => setFavoriteEntryIds(await getFavoriteEntryIds()))();
watchFavoriteEntryIds(setFavoriteEntryIds);

(async () => setSettings(await getSettings()))();
(async () => {
const settings = await getSettings();

setSettings(settings);
setTab(settings.defaultTab);
})();
watchSettings(setSettings);

(async () => setEntryIdToTags(await getEntryIdToTags()))();
Expand Down Expand Up @@ -161,9 +167,9 @@ export const App = () => {
/>
<SegmentedControl
value={tab}
onChange={setTab}
onChange={(newTab) => setTab(Tab.parse(newTab))}
size="xs"
color={tab === "all" ? "indigo.5" : "yellow.5"}
color={tab === Tab.Enum.All ? "indigo.5" : "yellow.5"}
data={[
{
label: (
Expand All @@ -172,7 +178,7 @@ export const App = () => {
<Text>All</Text>
</Group>
),
value: "all",
value: Tab.Enum.All,
},
{
label: (
Expand All @@ -181,12 +187,12 @@ export const App = () => {
<Text>Favorites</Text>
</Group>
),
value: "favorites",
value: Tab.Enum.Favorites,
},
]}
/>
</Group>
{tab === "all" ? <AllPage /> : <FavoritesPage />}
{tab === Tab.Enum.All ? <AllPage /> : <FavoritesPage />}
</Card>
);
};
21 changes: 21 additions & 0 deletions popup/components/modals/SettingsModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { z } from "zod";

import { settingsAtom } from "~popup/states/atoms";
import { setSettings } from "~storage/settings";
import { Tab } from "~types/tab";
import { removeActionBadgeText, setActionBadgeText } from "~utils/actionBadge";
import { getClipboardHistoryIOExport, importFile } from "~utils/importExport";
import { getEntries } from "~utils/storage";
Expand Down Expand Up @@ -143,6 +144,26 @@ export const SettingsModalContent = () => {
/>
</Group>
<Divider sx={(theme) => ({ borderColor: defaultBorderColor(theme) })} />
<Group align="flex-start" spacing="md" position="apart" noWrap>
<Stack spacing={0}>
<Title order={6}>Default Tab</Title>
<Text fz="xs">Select the tab shown when the extension is opened.</Text>
</Stack>
<Select
value={settings.defaultTab}
onChange={(newDefaultTab) =>
newDefaultTab &&
setSettings({ ...settings, defaultTab: Tab.parse(newDefaultTab) })
}
data={[
{ value: Tab.Enum.All, label: Tab.Enum.All },
{ value: Tab.Enum.Favorites, label: Tab.Enum.Favorites },
]}
size="xs"
withinPortal
/>
</Group>
<Divider sx={(theme) => ({ borderColor: defaultBorderColor(theme) })} />
<Group align="flex-start" spacing="md" position="apart" noWrap>
<Stack spacing={0}>
<Title order={6}>Theme</Title>
Expand Down
1 change: 0 additions & 1 deletion popup/states/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Entry } from "~types/entry";
import { EntryIdToTags } from "~types/entryIdToTags";
import { defaultSettings, Settings } from "~types/settings";

export const tabAtom = atom<string>("all");
export const searchAtom = atom<string>("");

export const entriesAtom = atom<Entry[]>([]);
Expand Down
4 changes: 4 additions & 0 deletions types/settings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { z } from "zod";

import { Tab } from "./tab";

// DO NOT REUSE DEPRECATED FIELDS.
export const defaultSettings = {
totalItemsBadge: true,
allowBlankItems: true,
defaultTab: Tab.Enum.All,
// theme: "light",
themeV2: "system",
localItemLimit: null,
Expand All @@ -13,6 +16,7 @@ export const Settings = z
.object({
totalItemsBadge: z.boolean().default(defaultSettings.totalItemsBadge),
allowBlankItems: z.boolean().default(defaultSettings.allowBlankItems),
defaultTab: Tab.default(defaultSettings.defaultTab),
// theme: z.string().default(defaultSettings.theme),
themeV2: z.string().default(defaultSettings.themeV2),
localItemLimit: z.number().nullable().default(defaultSettings.localItemLimit),
Expand Down
4 changes: 4 additions & 0 deletions types/tab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { z } from "zod";

export const Tab = z.enum(["All", "Favorites"]);
export type Tab = z.infer<typeof Tab>;

0 comments on commit dbc4940

Please sign in to comment.