Skip to content

Commit 56bdc01

Browse files
committed
fix: handle multiple diff lines
1 parent d2a5a5e commit 56bdc01

File tree

8 files changed

+1172
-881
lines changed

8 files changed

+1172
-881
lines changed

.yarn/install-state.gz

-28.9 KB
Binary file not shown.

.yarnrc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@
5050
"keywords": [
5151
"git",
5252
"git diff"
53-
]
53+
],
54+
"packageManager": "[email protected]"
5455
}

src/__fixtures__/31

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
diff --git a/var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/epicshop/diff/advanced-react-apis/04.01.solution/7h2jowvfi2q/index.test.tsx b/var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/epicshop/diff/advanced-react-apis/04.01.solution/7h2jowvfi2q/index.test.tsx
2+
new file mode 100644
3+
index 0000000..e69de29
4+
diff --git a/var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/epicshop/diff/advanced-react-apis/04.01.problem/7h2jowvfi2q/index.tsx b/var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/epicshop/diff/advanced-react-apis/04.01.solution/7h2jowvfi2q/index.tsx
5+
index 9913856..4d68325 100644
6+
--- a/var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/epicshop/diff/advanced-react-apis/04.01.problem/7h2jowvfi2q/index.tsx
7+
+++ b/var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/epicshop/diff/advanced-react-apis/04.01.solution/7h2jowvfi2q/index.tsx
8+
@@ -1,4 +1,4 @@
9+
-import { useCallback, useEffect, useState } from 'react'
10+
+import { createContext, useEffect, useState, use, useCallback } from 'react'
11+
import * as ReactDOM from 'react-dom/client'
12+
import {
13+
type BlogPost,
14+
@@ -7,15 +7,16 @@ import {
15+
} from '#shared/blog-posts'
16+
import { setGlobalSearchParams } from '#shared/utils'
17+
18+
-// 🦺 create a SearchParamsTuple type here that's a readonly array of two elements:
19+
-// - the first element is a URLSearchParams instance
20+
-// - the second element is typeof setGlobalSearchParams
21+
-// 🐨 create a SearchParamsContext that is of this type
22+
-// 💰 let's start with this as the default value (we'll improve it next):
23+
-// [new URLSearchParams(window.location.search), setGlobalSearchParams]
24+
+type SearchParamsTuple = readonly [
25+
+ URLSearchParams,
26+
+ typeof setGlobalSearchParams,
27+
+]
28+
+const SearchParamsContext = createContext<SearchParamsTuple>([
29+
+ new URLSearchParams(window.location.search),
30+
+ setGlobalSearchParams,
31+
+])
32+
33+
-// 🐨 change this to SearchParamsProvider and accept children
34+
-function useSearchParams() {
35+
+function SearchParamsProvider({ children }: { children: React.ReactNode }) {
36+
const [searchParams, setSearchParamsState] = useState(
37+
() => new URLSearchParams(window.location.search),
38+
)
39+
@@ -46,23 +47,29 @@ function useSearchParams() {
40+
[],
41+
)
42+
43+
- // 🐨 instead of returning this, render the SearchParamsContext and
44+
- // provide this tuple as the value
45+
- // 💰 make sure to render the children as well!
46+
- return [searchParams, setSearchParams] as const
47+
+ const searchParamsTuple = [searchParams, setSearchParams] as const
48+
+
49+
+ return (
50+
+ <SearchParamsContext value={searchParamsTuple}>
51+
+ {children}
52+
+ </SearchParamsContext>
53+
+ )
54+
}
55+
56+
-// 🐨 create a useSearchParams hook here that returns use(SearchParamsContext)
57+
+function useSearchParams() {
58+
+ return use(SearchParamsContext)
59+
+}
60+
61+
const getQueryParam = (params: URLSearchParams) => params.get('query') ?? ''
62+
63+
function App() {
64+
return (
65+
- // 🐨 wrap this in the SearchParamsProvider
66+
- <div className="app">
67+
- <Form />
68+
- <MatchingPosts />
69+
- </div>
70+
+ <SearchParamsProvider>
71+
+ <div className="app">
72+
+ <Form />
73+
+ <MatchingPosts />
74+
+ </div>
75+
+ </SearchParamsProvider>
76+
)
77+
}

src/__tests__/31.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { getFixture } from './test-utils';
2+
import parseGitDiff from '../parse-git-diff';
3+
4+
describe.only('issue 31', () => {
5+
const fixture = getFixture('31');
6+
7+
it('parse `31`', () => {
8+
expect(parseGitDiff(fixture)).toMatchSnapshot();
9+
});
10+
});

0 commit comments

Comments
 (0)