Skip to content

Commit

Permalink
fix: handle multiple diff lines (#32)
Browse files Browse the repository at this point in the history
* fix: handle multiple diff lines

* update yarn

* fixup
  • Loading branch information
yeonjuan authored Sep 18, 2024
1 parent d2a5a5e commit 80d7e09
Show file tree
Hide file tree
Showing 11 changed files with 2,080 additions and 891 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ jobs:
name: CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: set node.js 16.x
uses: actions/setup-node@v3
- uses: actions/checkout@v4
- name: set node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 16.x
- uses: borales/actions-yarn@v4
with:
cmd: install
- uses: borales/actions-yarn@v4
with:
cmd: check:all
node-version: 20.x
- name: Install
run: yarn install --immutable
- name: Check
run: yarn run check:all
- name: Code coverage report
uses: codecov/codecov-action@v2
with:
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ coverage
dist
.parcel-cache
demo/parse-git-diff.js
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
Binary file modified .yarn/install-state.gz
Binary file not shown.
893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.0.2.cjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .yarnrc.yml
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
"keywords": [
"git",
"git diff"
]
],
"packageManager": "[email protected]"
}
77 changes: 77 additions & 0 deletions src/__fixtures__/31
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
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();
});
});
Loading

0 comments on commit 80d7e09

Please sign in to comment.