-
Notifications
You must be signed in to change notification settings - Fork 5
fix: handle multiple diff lines #32
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
.yarn/install-state.gz
Binary file not shown.
893 changes: 893 additions & 0 deletions
.yarn/releases/yarn-4.0.2.cjs
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
.yarnrc.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
yarnPath: .yarn/releases/yarn-4.0.2.cjs | ||
nodeLinker: node-modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,5 +50,6 @@ | |
"keywords": [ | ||
"git", | ||
"git diff" | ||
] | ||
], | ||
"packageManager": "yarn@4.0.2" | ||
} |
77 changes: 77 additions & 0 deletions
src/__fixtures__/31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
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 | ||
new file mode 100644 | ||
index 0000000..e69de29 | ||
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 | ||
index 9913856..4d68325 100644 | ||
--- 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 | ||
@@ -1,4 +1,4 @@ | ||
-import { useCallback, useEffect, useState } from 'react' | ||
+import { createContext, useEffect, useState, use, useCallback } from 'react' | ||
import * as ReactDOM from 'react-dom/client' | ||
import { | ||
type BlogPost, | ||
@@ -7,15 +7,16 @@ import { | ||
} from '#shared/blog-posts' | ||
import { setGlobalSearchParams } from '#shared/utils' | ||
|
||
-// 🦺 create a SearchParamsTuple type here that's a readonly array of two elements: | ||
-// - the first element is a URLSearchParams instance | ||
-// - the second element is typeof setGlobalSearchParams | ||
-// 🐨 create a SearchParamsContext that is of this type | ||
-// 💰 let's start with this as the default value (we'll improve it next): | ||
-// [new URLSearchParams(window.location.search), setGlobalSearchParams] | ||
+type SearchParamsTuple = readonly [ | ||
+ URLSearchParams, | ||
+ typeof setGlobalSearchParams, | ||
+] | ||
+const SearchParamsContext = createContext<SearchParamsTuple>([ | ||
+ new URLSearchParams(window.location.search), | ||
+ setGlobalSearchParams, | ||
+]) | ||
|
||
-// 🐨 change this to SearchParamsProvider and accept children | ||
-function useSearchParams() { | ||
+function SearchParamsProvider({ children }: { children: React.ReactNode }) { | ||
const [searchParams, setSearchParamsState] = useState( | ||
() => new URLSearchParams(window.location.search), | ||
) | ||
@@ -46,23 +47,29 @@ function useSearchParams() { | ||
[], | ||
) | ||
|
||
- // 🐨 instead of returning this, render the SearchParamsContext and | ||
- // provide this tuple as the value | ||
- // 💰 make sure to render the children as well! | ||
- return [searchParams, setSearchParams] as const | ||
+ const searchParamsTuple = [searchParams, setSearchParams] as const | ||
+ | ||
+ return ( | ||
+ <SearchParamsContext value={searchParamsTuple}> | ||
+ {children} | ||
+ </SearchParamsContext> | ||
+ ) | ||
} | ||
|
||
-// 🐨 create a useSearchParams hook here that returns use(SearchParamsContext) | ||
+function useSearchParams() { | ||
+ return use(SearchParamsContext) | ||
+} | ||
|
||
const getQueryParam = (params: URLSearchParams) => params.get('query') ?? '' | ||
|
||
function App() { | ||
return ( | ||
- // 🐨 wrap this in the SearchParamsProvider | ||
- <div className="app"> | ||
- <Form /> | ||
- <MatchingPosts /> | ||
- </div> | ||
+ <SearchParamsProvider> | ||
+ <div className="app"> | ||
+ <Form /> | ||
+ <MatchingPosts /> | ||
+ </div> | ||
+ </SearchParamsProvider> | ||
) | ||
} |
10 changes: 10 additions & 0 deletions
src/__tests__/31.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { getFixture } from './test-utils'; | ||
import parseGitDiff from '../parse-git-diff'; | ||
|
||
describe.only('issue 31', () => { | ||
const fixture = getFixture('31'); | ||
|
||
it('parse `31`', () => { | ||
expect(parseGitDiff(fixture)).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.