Skip to content

Commit 7b062b5

Browse files
committed
added refresh button to habit list, fixed touch reordering
1 parent d8b00af commit 7b062b5

File tree

8 files changed

+42
-10
lines changed

8 files changed

+42
-10
lines changed

src/components/collection/context.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from "react"
33

44
interface S {
55
collection: Collection
6+
isFetching: boolean
67

78
tags: string[]
89
tagSet: Set<string>

src/components/collection/provider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { CollectionContext } from "./context"
99

1010
export const CollectionProvider: React.FC<React.PropsWithChildren> = ({ children }) => {
1111
const collection = useCollection()
12-
const repoContent = useRepoContentContext()
12+
const { repoContent } = useRepoContentContext()
1313

1414
const habits = [...iterHabitNames(repoContent)]
1515

@@ -23,6 +23,7 @@ export const CollectionProvider: React.FC<React.PropsWithChildren> = ({ children
2323
<CollectionContext.Provider
2424
value={{
2525
collection: collection.data,
26+
isFetching: collection.isFetching,
2627
tags,
2728
tagSet: new Set(tags),
2829
habits: new Set(habits),

src/components/habit/card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const HabitCard: React.FC = () => {
6565
<div
6666
{...extraProps}
6767
className={cn(
68-
"habit-card rounded truncate w-full max-w-211 flex flex-col gap-1",
68+
"habit-card rounded truncate w-full max-w-211 flex flex-col gap-1 touch-none",
6969
{
7070
"min-h-40": !displayOptions.hideChart,
7171
},

src/components/habit/list.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useCollectionContext } from "@/components/collection/context"
22
import { HabitCard } from "@/components/habit/card"
33
import { HabitFetcher } from "@/components/habit/fetcher"
44
import { useOrderingContext } from "@/components/ordering/context"
5+
import { RefreshButton } from "@/components/refresh-button"
56
import { TagContext } from "@/components/tag/context"
67
import { TagList } from "@/components/tag/list"
78
import { Button } from "@/components/ui/button"
@@ -55,7 +56,8 @@ export const HabitList: React.FC = () => {
5556
</Link>
5657
</>
5758
) : (
58-
<div className="flex justify-center">
59+
<div className="flex items-center justify-center gap-2">
60+
<RefreshButton />
5961
<Button
6062
variant="ghost"
6163
className="w-fit"

src/components/refresh-button.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { useRefresh } from "@/lib/queries"
2+
import { cn } from "@/lib/utils"
3+
import { RefreshCw } from "lucide-react"
4+
import type React from "react"
5+
6+
import { useCollectionContext } from "./collection/context"
7+
import { useRepoContentContext } from "./repo/content-context"
8+
import { Button } from "./ui/button"
9+
10+
export const RefreshButton: React.FC<React.ComponentProps<typeof Button>> = (props) => {
11+
const { isFetching: repoIsFetching } = useRepoContentContext()
12+
const { isFetching: collectionIsFetching } = useCollectionContext()
13+
const refresh = useRefresh()
14+
const loading = repoIsFetching || collectionIsFetching
15+
16+
return (
17+
<Button variant="ghost" disabled={loading} onClick={() => void refresh()} {...props}>
18+
<RefreshCw className={cn({ "animate-spin": loading })} />
19+
Refresh
20+
</Button>
21+
)
22+
}

src/components/repo/content-context.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import type { RepoContent } from "@/lib/git"
22
import React from "react"
33

4-
export const RepoContentContext = React.createContext<RepoContent | undefined>(undefined)
4+
interface S {
5+
repoContent: RepoContent
6+
isFetching: boolean
7+
}
8+
9+
export const RepoContentContext = React.createContext<S | undefined>(undefined)
510

611
export const useRepoContentContext = () => {
712
const ctx = React.useContext(RepoContentContext)
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
import { ErrorView } from "@/components/util/error-view"
22
import { LoadingPage } from "@/components/util/loading-page"
3-
import { useRefresh, useRepoContent } from "@/lib/queries"
3+
import { useRepoContent } from "@/lib/queries"
44
import React from "react"
55

66
import { RepoContentContext } from "./content-context"
77

88
export const RepoContentProvider: React.FC<React.PropsWithChildren> = ({ children }) => {
99
const content = useRepoContent()
10-
const refresh = useRefresh()
1110

1211
if (content.isLoading) {
1312
return <LoadingPage label="Loading repository..." />
1413
}
1514

1615
if (content.data) {
1716
return (
18-
<RepoContentContext.Provider value={content.data}>
17+
<RepoContentContext.Provider
18+
value={{ repoContent: content.data, isFetching: content.isFetching }}
19+
>
1920
{children}
2021
</RepoContentContext.Provider>
2122
)
2223
}
2324

24-
return <ErrorView error={content.error} retry={refresh} />
25+
return <ErrorView error={content.error} retry={content.refetch} />
2526
}

src/lib/queries.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ export const useRepoContent = () => {
168168
export const useCollection = () => {
169169
const account = useStoredAccountContext()
170170
const repo = useRepoContext()
171-
const content = useRepoContentContext()
171+
const { repoContent } = useRepoContentContext()
172172
const octokit = useOctokit()
173173

174174
const [stored, setStored] = useStoredCollection()
175175

176176
return useQuery({
177177
queryKey: ["repo", repo.id, "collection"],
178178
queryFn: async ({ signal }) => {
179-
if (content.tree.length === 0) {
179+
if (repoContent.tree.length === 0) {
180180
return create(CollectionSchema, {})
181181
}
182182

0 commit comments

Comments
 (0)