Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
b9b795bf
Unverified
Commit
b9b795bf
authored
Aug 20, 2023
by
boojack
Committed by
GitHub
Aug 20, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: add react use (#2157)
* chore: add react use * chore: update
parent
19e7731a
Changes
16
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
149 additions
and
283 deletions
+149
-283
package.json
web/package.json
+4
-4
pnpm-lock.yaml
web/pnpm-lock.yaml
+136
-124
MemoList.tsx
web/src/components/MemoList.tsx
+3
-10
ResourceSearchBar.tsx
web/src/components/ResourceSearchBar.tsx
+1
-1
SearchBar.tsx
web/src/components/SearchBar.tsx
+1
-1
TagList.tsx
web/src/components/TagList.tsx
+1
-1
Dropdown.tsx
web/src/components/kit/Dropdown.tsx
+1
-1
Selector.tsx
web/src/components/kit/Selector.tsx
+1
-1
index.ts
web/src/hooks/index.ts
+0
-3
useDebounce.ts
web/src/hooks/useDebounce.ts
+0
-12
useTimeoutFn.ts
web/src/hooks/useTimeoutFn.ts
+0
-40
useToggle.ts
web/src/hooks/useToggle.ts
+0
-21
DailyReview.tsx
web/src/pages/DailyReview.tsx
+1
-1
filter.ts
web/src/store/module/filter.ts
+0
-8
filter.ts
web/src/store/reducer/filter.ts
+0
-1
filter.d.ts
web/src/types/filter.d.ts
+0
-54
No files found.
web/package.json
View file @
b9b795bf
...
...
@@ -10,7 +10,7 @@
"dependencies"
:
{
"@emotion/react"
:
"^11.11.1"
,
"@emotion/styled"
:
"^11.11.0"
,
"@mui/joy"
:
"5.0.0-beta.
0
"
,
"@mui/joy"
:
"5.0.0-beta.
2
"
,
"@reduxjs/toolkit"
:
"^1.8.1"
,
"axios"
:
"^0.27.2"
,
"classnames"
:
"^2.3.2"
,
...
...
@@ -46,7 +46,7 @@
"@types/uuid"
:
"^9.0.2"
,
"@typescript-eslint/eslint-plugin"
:
"^5.6.0"
,
"@typescript-eslint/parser"
:
"^5.6.0"
,
"@vitejs/plugin-react-swc"
:
"^3.3.
0
"
,
"@vitejs/plugin-react-swc"
:
"^3.3.
2
"
,
"autoprefixer"
:
"^10.4.2"
,
"eslint"
:
"^8.46.0"
,
"eslint-config-prettier"
:
"^8.6.0"
,
...
...
@@ -56,7 +56,7 @@
"postcss"
:
"^8.4.21"
,
"prettier"
:
"2.6.2"
,
"terser"
:
"^5.16.1"
,
"typescript"
:
"^5.
0.4
"
,
"vite"
:
"^4.
2.1
"
"typescript"
:
"^5.
1.6
"
,
"vite"
:
"^4.
4.9
"
}
}
web/pnpm-lock.yaml
View file @
b9b795bf
This diff is collapsed.
Click to expand it.
web/src/components/MemoList.tsx
View file @
b9b795bf
...
...
@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from "react";
import
{
toast
}
from
"react-hot-toast"
;
import
{
DEFAULT_MEMO_LIMIT
}
from
"@/helpers/consts"
;
import
{
getTimeStampByDate
}
from
"@/helpers/datetime"
;
import
{
LINK_REG
,
PLAIN_LINK_REG
,
TAG_REG
}
from
"@/labs/marked/parser"
;
import
{
TAG_REG
}
from
"@/labs/marked/parser"
;
import
{
useFilterStore
,
useMemoStore
,
useUserStore
}
from
"@/store/module"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
import
Empty
from
"./Empty"
;
...
...
@@ -24,8 +24,8 @@ const MemoList: React.FC<Props> = (props: Props) => {
const
[
isComplete
,
setIsComplete
]
=
useState
<
boolean
>
(
false
);
const
currentUsername
=
userStore
.
getCurrentUsername
();
const
{
tag
:
tagQuery
,
duration
,
t
ype
:
memoType
,
t
ext
:
textQuery
,
visibility
}
=
filter
;
const
showMemoFilter
=
Boolean
(
tagQuery
||
(
duration
&&
duration
.
from
<
duration
.
to
)
||
memoType
||
textQuery
||
visibility
);
const
{
tag
:
tagQuery
,
duration
,
text
:
textQuery
,
visibility
}
=
filter
;
const
showMemoFilter
=
Boolean
(
tagQuery
||
(
duration
&&
duration
.
from
<
duration
.
to
)
||
textQuery
||
visibility
);
const
shownMemos
=
(
showMemoFilter
...
...
@@ -55,13 +55,6 @@ const MemoList: React.FC<Props> = (props: Props) => {
)
{
shouldShow
=
false
;
}
if (memoType)
{
if
(
memoType
===
"NOT_TAGGED"
&&
memo
.
content
.
match
(
TAG_REG
)
!==
null
)
{
shouldShow
=
false
;
}
else
if
(
memoType
===
"LINKED"
&&
(
memo
.
content
.
match
(
LINK_REG
)
===
null
||
memo
.
content
.
match
(
PLAIN_LINK_REG
)
===
null
))
{
shouldShow
=
false
;
}
}
if (textQuery
&&
!memo.content.toLowerCase().includes(textQuery.toLowerCase()))
{
shouldShow
=
false
;
}
...
...
web/src/components/ResourceSearchBar.tsx
View file @
b9b795bf
import
{
useRef
,
useState
}
from
"react"
;
import
useDebounce
from
"
@/hooks
/useDebounce"
;
import
useDebounce
from
"
react-use/lib
/useDebounce"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
import
Icon
from
"./Icon"
;
...
...
web/src/components/SearchBar.tsx
View file @
b9b795bf
import
{
useEffect
,
useRef
,
useState
}
from
"react"
;
import
useDebounce
from
"
@/hooks
/useDebounce"
;
import
useDebounce
from
"
react-use/lib
/useDebounce"
;
import
{
useFilterStore
}
from
"@/store/module"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
import
Icon
from
"./Icon"
;
...
...
web/src/components/TagList.tsx
View file @
b9b795bf
import
{
useEffect
,
useState
}
from
"react"
;
import
useToggle
from
"
@/hooks
/useToggle"
;
import
useToggle
from
"
react-use/lib
/useToggle"
;
import
{
useFilterStore
,
useTagStore
}
from
"@/store/module"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
import
showCreateTagDialog
from
"./CreateTagDialog"
;
...
...
web/src/components/kit/Dropdown.tsx
View file @
b9b795bf
import
{
ReactNode
,
useEffect
,
useRef
}
from
"react"
;
import
useToggle
from
"
@/hooks
/useToggle"
;
import
useToggle
from
"
react-use/lib
/useToggle"
;
import
Icon
from
"../Icon"
;
interface
Props
{
...
...
web/src/components/kit/Selector.tsx
View file @
b9b795bf
import
{
Tooltip
}
from
"@mui/joy"
;
import
{
memo
,
useEffect
,
useRef
}
from
"react"
;
import
useToggle
from
"
@/hooks
/useToggle"
;
import
useToggle
from
"
react-use/lib
/useToggle"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
import
Icon
from
"../Icon"
;
import
"@/less/common/selector.less"
;
...
...
web/src/hooks/index.ts
View file @
b9b795bf
export
*
from
"./useDebounce"
;
export
*
from
"./useLoading"
;
export
*
from
"./useTimeoutFn"
;
export
*
from
"./useToggle"
;
web/src/hooks/useDebounce.ts
deleted
100644 → 0
View file @
19e7731a
import
{
DependencyList
,
useEffect
}
from
"react"
;
import
useTimeoutFn
from
"./useTimeoutFn"
;
export
type
UseDebounceReturn
=
[()
=>
boolean
|
null
,
()
=>
void
];
export
default
function
useDebounce
(
fn
:
()
=>
any
,
ms
=
0
,
deps
:
DependencyList
=
[]):
UseDebounceReturn
{
const
[
isReady
,
cancel
,
reset
]
=
useTimeoutFn
(
fn
,
ms
);
useEffect
(
reset
,
deps
);
return
[
isReady
,
cancel
];
}
web/src/hooks/useTimeoutFn.ts
deleted
100644 → 0
View file @
19e7731a
import
{
useCallback
,
useEffect
,
useRef
}
from
"react"
;
export
type
UseTimeoutFnReturn
=
[()
=>
boolean
|
null
,
()
=>
void
,
()
=>
void
];
export
default
function
useTimeoutFn
(
fn
:
()
=>
any
,
ms
=
0
):
UseTimeoutFnReturn
{
const
ready
=
useRef
<
boolean
|
null
>
(
false
);
const
timeout
=
useRef
<
ReturnType
<
typeof
setTimeout
>>
();
const
callback
=
useRef
(
fn
);
const
isReady
=
useCallback
(()
=>
ready
.
current
,
[]);
const
set
=
useCallback
(()
=>
{
ready
.
current
=
false
;
timeout
.
current
&&
clearTimeout
(
timeout
.
current
);
timeout
.
current
=
setTimeout
(()
=>
{
ready
.
current
=
true
;
callback
.
current
();
},
ms
);
},
[
ms
]);
const
clear
=
useCallback
(()
=>
{
ready
.
current
=
null
;
timeout
.
current
&&
clearTimeout
(
timeout
.
current
);
},
[]);
// update ref when function changes
useEffect
(()
=>
{
callback
.
current
=
fn
;
},
[
fn
]);
// set on mount, clear on unmount
useEffect
(()
=>
{
set
();
return
clear
;
},
[
ms
]);
return
[
isReady
,
clear
,
set
];
}
web/src/hooks/useToggle.ts
deleted
100644 → 0
View file @
19e7731a
import
{
useCallback
,
useState
}
from
"react"
;
// Parameter is the boolean, with default "false" value
const
useToggle
=
(
initialState
=
false
):
[
boolean
,
(
nextState
?:
boolean
)
=>
void
]
=>
{
// Initialize the state
const
[
state
,
setState
]
=
useState
(
initialState
);
// Define and memorize toggler function in case we pass down the component,
// This function change the boolean value to it's opposite value
const
toggle
=
useCallback
((
nextState
?:
boolean
)
=>
{
if
(
nextState
!==
undefined
)
{
setState
(
nextState
);
}
else
{
setState
((
state
)
=>
!
state
);
}
},
[]);
return
[
state
,
toggle
];
};
export
default
useToggle
;
web/src/pages/DailyReview.tsx
View file @
b9b795bf
...
...
@@ -2,6 +2,7 @@ import classNames from "classnames";
import
{
last
}
from
"lodash-es"
;
import
{
useEffect
,
useRef
,
useState
}
from
"react"
;
import
toast
from
"react-hot-toast"
;
import
useToggle
from
"react-use/lib/useToggle"
;
import
DailyMemo
from
"@/components/DailyMemo"
;
import
Empty
from
"@/components/Empty"
;
import
Icon
from
"@/components/Icon"
;
...
...
@@ -10,7 +11,6 @@ import showPreviewImageDialog from "@/components/PreviewImageDialog";
import
DatePicker
from
"@/components/kit/DatePicker"
;
import
{
DAILY_TIMESTAMP
,
DEFAULT_MEMO_LIMIT
}
from
"@/helpers/consts"
;
import
{
convertToMillis
,
getDateStampByDate
,
getNormalizedDateString
,
getTimeStampByDate
,
isFutureDate
}
from
"@/helpers/datetime"
;
import
useToggle
from
"@/hooks/useToggle"
;
import
i18n
from
"@/i18n"
;
import
toImage
from
"@/labs/html2image"
;
import
{
useMemoStore
,
useUserStore
}
from
"@/store/module"
;
...
...
web/src/store/module/filter.ts
View file @
b9b795bf
...
...
@@ -16,20 +16,12 @@ export const useFilterStore = () => {
store
.
dispatch
(
setFilter
({
tag
:
undefined
,
type
:
undefined
,
duration
:
undefined
,
text
:
undefined
,
visibility
:
undefined
,
})
);
},
setMemoTypeFilter
:
(
type
?:
MemoSpecType
)
=>
{
store
.
dispatch
(
setFilter
({
type
:
type
,
})
);
},
setTextFilter
:
(
text
?:
string
)
=>
{
store
.
dispatch
(
setFilter
({
...
...
web/src/store/reducer/filter.ts
View file @
b9b795bf
...
...
@@ -8,7 +8,6 @@ interface Duration {
interface
State
{
tag
?:
string
;
duration
?:
Duration
;
type
?:
MemoSpecType
;
text
?:
string
;
visibility
?:
Visibility
;
}
...
...
web/src/types/filter.d.ts
deleted
100644 → 0
View file @
19e7731a
type
MemoFilterRelation
=
"AND"
|
"OR"
;
interface
BaseFilter
{
type
:
FilterType
;
value
:
{
operator
:
string
;
value
:
string
;
};
relation
:
MemoFilterRelation
;
}
interface
TagFilter
extends
BaseFilter
{
type
:
"TAG"
;
value
:
{
operator
:
"CONTAIN"
|
"NOT_CONTAIN"
;
value
:
string
;
};
}
interface
TypeFilter
extends
BaseFilter
{
type
:
"TYPE"
;
value
:
{
operator
:
"IS"
|
"IS_NOT"
;
value
:
MemoSpecType
;
};
}
interface
TextFilter
extends
BaseFilter
{
type
:
"TEXT"
;
value
:
{
operator
:
"CONTAIN"
|
"NOT_CONTAIN"
;
value
:
string
;
};
}
interface
DisplayTimeFilter
extends
BaseFilter
{
type
:
"DISPLAY_TIME"
;
value
:
{
operator
:
"BEFORE"
|
"AFTER"
;
value
:
string
;
};
}
interface
VisibilityFilter
extends
BaseFilter
{
type
:
"VISIBILITY"
;
value
:
{
operator
:
"IS"
|
"IS_NOT"
;
value
:
string
;
};
}
type
FilterType
=
"TEXT"
|
"TYPE"
|
"TAG"
|
"DISPLAY_TIME"
|
"VISIBILITY"
;
type
Filter
=
BaseFilter
|
TagFilter
|
TypeFilter
|
TextFilter
|
DisplayTimeFilter
|
VisibilityFilter
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment