Skip to content

Commit 80d7e09

Browse files
authored
fix: handle multiple diff lines (#32)
* fix: handle multiple diff lines * update yarn * fixup
1 parent d2a5a5e commit 80d7e09

File tree

11 files changed

+2080
-891
lines changed

11 files changed

+2080
-891
lines changed

.github/workflows/main.yml

+8-10
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ jobs:
55
name: CI
66
runs-on: ubuntu-latest
77
steps:
8-
- uses: actions/checkout@v2
9-
- name: set node.js 16.x
10-
uses: actions/setup-node@v3
8+
- uses: actions/checkout@v4
9+
- name: set node.js 20.x
10+
uses: actions/setup-node@v4
1111
with:
12-
node-version: 16.x
13-
- uses: borales/actions-yarn@v4
14-
with:
15-
cmd: install
16-
- uses: borales/actions-yarn@v4
17-
with:
18-
cmd: check:all
12+
node-version: 20.x
13+
- name: Install
14+
run: yarn install --immutable
15+
- name: Check
16+
run: yarn run check:all
1917
- name: Code coverage report
2018
uses: codecov/codecov-action@v2
2119
with:

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ coverage
44
dist
55
.parcel-cache
66
demo/parse-git-diff.js
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/sdks
12+
!.yarn/versions

.yarn/install-state.gz

-28.9 KB
Binary file not shown.

.yarn/releases/yarn-4.0.2.cjs

+893
Large diffs are not rendered by default.

.yarnrc.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yarnPath: .yarn/releases/yarn-4.0.2.cjs
2+
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": "yarn@4.0.2"
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)