Skip to content

Commit

Permalink
feat: update code
Browse files Browse the repository at this point in the history
  • Loading branch information
杨国璇 authored and 杨国璇 committed Sep 18, 2024
1 parent f6e788c commit 8555710
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
8 changes: 4 additions & 4 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@seafile/sdoc-editor": "1.0.81",
"@seafile/seafile-calendar": "0.0.27",
"@seafile/seafile-editor": "^1.0.116",
"@seafile/sf-metadata-ui-component": "^0.0.36",
"@seafile/sf-metadata-ui-component": "^0.0.37",
"@uiw/codemirror-extensions-langs": "^4.19.4",
"@uiw/react-codemirror": "^4.19.4",
"axios": "^1.7.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useCallback, useMemo, useRef, useState } from 'react';
import { SfCalendar } from '@seafile/sf-metadata-ui-component';
import { ClickOutside, SfCalendar } from '@seafile/sf-metadata-ui-component';
import PropTypes from 'prop-types';
import { getDateDisplayString } from '../../../utils/cell';
import { DEFAULT_DATE_FORMAT } from '../../../constants';
import { getDateDisplayString, isCellValueChanged } from '../../../utils/cell';
import { CellType, DEFAULT_DATE_FORMAT } from '../../../constants';
import { gettext } from '../../../../utils/constants';
import { getEventClassName } from '../../../utils/common';

import './index.css';

Expand All @@ -27,8 +28,15 @@ const DateEditor = ({ value, field, onChange: onChangeAPI, lang }) => {

const closeEditor = useCallback(() => {
setShowEditor(false);
if (!isCellValueChanged(value, newValue.current, CellType.DATE)) return;
onChangeAPI(newValue.current);
}, [onChangeAPI, newValue]);
}, [value, newValue, onChangeAPI]);

const onClickOutside = useCallback((event) => {
let className = getEventClassName(event);
if (className.indexOf('rc-calendar') > -1 || !className && event.target.tagName === 'LI') return;
closeEditor();
}, [closeEditor]);

return (
<>
Expand All @@ -40,7 +48,9 @@ const DateEditor = ({ value, field, onChange: onChangeAPI, lang }) => {
{getDateDisplayString(value, format)}
</div>
{showEditor && (
<SfCalendar lang={lang} format={format} value={value} onChange={onChange} onClose={closeEditor} onClear={onClear} />
<ClickOutside onClickOutside={onClickOutside}>
<SfCalendar lang={lang} format={format} value={value} onChange={onChange} onClose={closeEditor} onClear={onClear} />
</ClickOutside>
)}
</>
);
Expand Down

0 comments on commit 8555710

Please sign in to comment.