Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: redesign header #2

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@tabler/icons-react": "^3.14.0",
"@tanstack/react-query": "^5.55.4",
"date-fns": "3.1.0",
"jotai": "^2.9.3",
"plasmo": "0.89.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 56 additions & 40 deletions popup/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { Box, Divider, Group, SegmentedControl, Switch, Text, TextInput } from "@mantine/core";
import { IconClipboardList, IconLock, IconSearch, IconStar } from "@tabler/icons-react";
import {
Box,
Divider,
Group,
Image,
SegmentedControl,
Stack,
Switch,
Text,
TextInput,
Title,
} from "@mantine/core";
import { IconClipboardList, IconSearch, IconStar } from "@tabler/icons-react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import icon from "data-base64:~assets/icon.png";
import { max } from "date-fns";
import { useSetAtom } from "jotai";
import { useEffect, useMemo, useState } from "react";

import { getClipboardContent, watchClipboardContent } from "~storage/clipboardContent";
Expand All @@ -14,6 +27,7 @@ import type { Entry } from "~types/entry";
import { getEntries, watchEntries } from "~utils/storage";

import { EntryList } from "./components/EntryList";
import { clipboardContentAtom } from "./states/atoms";

export const App = () => {
const [now] = useState(new Date());
Expand All @@ -25,8 +39,6 @@ export const App = () => {
const [entries, setEntries] = useState<Entry[]>([]);
const reversedEntries = useMemo(() => entries.toReversed(), [entries]);

const [clipboardContent, setClipboardContent] = useState<string>();

const [favoriteEntryIds, setFavoriteEntryIds] = useState<string[]>([]);
const favoriteEntryIdsSet = useMemo(() => new Set(favoriteEntryIds), [favoriteEntryIds]);

Expand All @@ -40,6 +52,8 @@ export const App = () => {
onSuccess: () => queryClient.invalidateQueries({ queryKey: ["clipboardMonitorIsEnabled"] }),
});

const setClipboardContent = useSetAtom(clipboardContentAtom);

useEffect(() => {
(async () => setEntries(await getEntries()))();
watchEntries(setEntries);
Expand All @@ -56,50 +70,58 @@ export const App = () => {
}

return (
<Box>
<Group align="center" position="apart" px="md" py="xs">
<Group align="center">
<Box p="sm">
<Stack spacing="sm" mb="sm">
<Group align="center" position="apart">
<Group spacing="xs">
<Image src={icon} maw={28} />
<Title order={5} color="gray.8">
Clipboard History Pro
</Title>
</Group>
<Switch
size="md"
color="indigo.4"
checked={clipboardMonitorIsEnabledQuery.data}
onChange={() => toggleClipboardMonitorIsEnabledMutation.mutate()}
/>
</Group>
<Group align="center" position="apart">
<TextInput
placeholder="Search"
icon={<IconSearch size="1rem" />}
size="xs"
value={search}
onChange={(e) => setSearch(e.currentTarget.value)}
/>
<SegmentedControl
value={tab}
onChange={setTab}
size="xs"
color={tab === "all" ? "indigo.4" : "yellow.5"}
data={[
{
label: (
<Group align="center" spacing={4} noWrap>
<IconClipboardList size="1rem" />
<Text>All</Text>
</Group>
),
value: "all",
},
{
label: (
<Group align="center" spacing={4} noWrap>
<IconStar size="1rem" />
<Text>Favorites</Text>
</Group>
),
value: "favorites",
},
]}
/>
</Group>
<SegmentedControl
value={tab}
onChange={setTab}
size="xs"
color={tab === "all" ? "indigo.4" : "yellow.5"}
data={[
{
label: (
<Group align="center" spacing={4} noWrap>
<IconClipboardList size="1rem" />
<Text>All</Text>
</Group>
),
value: "all",
},
{
label: (
<Group align="center" spacing={4} noWrap>
<IconStar size="1rem" />
<Text>Favorites</Text>
</Group>
),
value: "favorites",
},
]}
/>
</Group>
</Stack>
<Divider color="gray.2" />
<EntryList
now={max([new Date(reversedEntries[0]?.createdAt || 0), now])}
Expand All @@ -110,13 +132,7 @@ export const App = () => {
(entry) =>
search.length === 0 || entry.content.toLowerCase().includes(search.toLowerCase()),
)}
clipboardContent={clipboardContent}
favoriteEntryIdsSet={favoriteEntryIdsSet}
onEntryClick={async (entry) => {
await navigator.clipboard.writeText(entry.content);

setClipboardContent(entry.content);
}}
/>
</Box>
);
Expand Down
72 changes: 47 additions & 25 deletions popup/components/EntryList.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ActionIcon, Box, Checkbox, Divider, Group, Text } from "@mantine/core";
import { ActionIcon, Badge, Box, Checkbox, Divider, Group, Text } from "@mantine/core";
import { useSet } from "@mantine/hooks";
import { IconStar, IconTrash } from "@tabler/icons-react";
import { useAtom } from "jotai";
import { useEffect, useMemo } from "react";
import { FixedSizeList } from "react-window";

import { clipboardContentAtom } from "~popup/states/atoms";
import { addFavoriteEntryIds, deleteFavoriteEntryIds } from "~storage/favoriteEntryIds";
import type { Entry } from "~types/entry";
import { deleteEntries } from "~utils/storage";
Expand All @@ -14,28 +16,36 @@ import { EntryRow } from "./EntryRow";
interface Props {
now: Date;
entries: Entry[];
clipboardContent?: string;
favoriteEntryIdsSet: Set<string>;
onEntryClick: (entry: Entry) => void;
}

export const EntryList = ({
now,
entries,
clipboardContent,
favoriteEntryIdsSet,
onEntryClick,
}: Props) => {
export const EntryList = ({ now, entries, favoriteEntryIdsSet }: Props) => {
const selectedEntryIds = useSet<string>();
const entryIdsStringified = useMemo(() => JSON.stringify(entries.map(({ id }) => id)), [entries]);

const [clipboardContent, setClipboardContent] = useAtom(clipboardContentAtom);

useEffect(() => {
selectedEntryIds.clear();
}, [entryIdsStringified]);

return (
<>
<Group align="center" spacing="md" noWrap px="md" py={4}>
<Group
align="center"
spacing="md"
noWrap
px="md"
py={4}
sx={(theme) => ({
borderLeftColor: theme.colors.gray[2],
borderRightColor: theme.colors.gray[2],
borderLeftStyle: "solid",
borderRightStyle: "solid",
borderLeftWidth: "1px",
borderRightWidth: "1px",
})}
>
<Checkbox
size="xs"
color="indigo.3"
Expand Down Expand Up @@ -90,20 +100,32 @@ export const EntryList = ({
</Group>
</Group>
<Divider color="gray.2" />
<FixedSizeList height={500} itemCount={entries.length} itemSize={37} width={700}>
{({ index, style }) => (
<Box style={style}>
<EntryRow
now={now}
entry={entries[index]!}
clipboardContent={clipboardContent}
selectedEntryIds={selectedEntryIds}
favoriteEntryIdsSet={favoriteEntryIdsSet}
onEntryClick={onEntryClick}
/>
</Box>
)}
</FixedSizeList>
<Box
sx={(theme) => ({
borderLeftColor: theme.colors.gray[2],
borderBottomColor: theme.colors.gray[2],
borderLeftStyle: "solid",
borderBottomStyle: "solid",
borderLeftWidth: "1px",
borderBottomWidth: "1px",
borderRightColor: theme.colors.gray[2],
borderRightStyle: "solid",
borderRightWidth: "1px",
})}
>
<FixedSizeList height={450} itemCount={entries.length} itemSize={37} width={700}>
{({ index, style }) => (
<Box style={style}>
<EntryRow
now={now}
entry={entries[index]!}
selectedEntryIds={selectedEntryIds}
favoriteEntryIdsSet={favoriteEntryIdsSet}
/>
</Box>
)}
</FixedSizeList>
</Box>
</>
);
};
Loading