Skip to content

Commit

Permalink
Also merging
Browse files Browse the repository at this point in the history
  • Loading branch information
vmonakhov committed Oct 30, 2023
1 parent bdabebb commit 00a5499
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 25 deletions.
78 changes: 54 additions & 24 deletions src/components/LexicalEntryCorp/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Button, Checkbox } from "semantic-ui-react";
import { find, isEqual } from "lodash";
import PropTypes from "prop-types";
import { onlyUpdateForKeys } from "recompose";
import { RegExpMarker } from "react-mark.js";

import Entities from "./index";

Expand All @@ -26,13 +27,18 @@ const TextEntityContent = ({
resetCheckedColumn,
checkedAll,
resetCheckedAll,
number,
update, /* new!!!!!! */
/*draggable*/ /* new!!!!!! */
id /* new!!!!!! */
}) => {

const is_order_column = (number && column.english_translation === "Order");

const [edit, setEdit] = useState(false);
const [content, setContent] = useState(entity.content);
const [read_only, setReadOnly] = useState(is_order_column);
const [is_number, setIsNumber] = useState(is_order_column);

/* new!!!!!! */
const [dropped, setDropped] = useState(null);
Expand Down Expand Up @@ -74,6 +80,7 @@ const TextEntityContent = ({
});

/* /new!!!!! */
const text = is_number ? number : entity.content;

if (checkEntries) {
if (checkedAll) {
Expand Down Expand Up @@ -117,40 +124,58 @@ const TextEntityContent = ({
}
}

const pg_ln = /\[\d+[ab]:\d+\]/;
const pg = /\[\d+[ab]?\]/;
const ln = /\(\d+\)/;
const snt = /\/{2}/;
const missed = /[/]missed text[/]/;
// TODO: change 'number' to something meaningful
const metatext = number
? new RegExp(
pg_ln.source + "|" +
pg.source + "|" +
ln.source + "|" +
snt.source + "|" +
missed.source
)
: new RegExp();

switch (mode) {
case "edit":
return !dropped ? (
<div /* new!!!! */ className={isDragging && "lingvo-input-buttons-group lingvo-input-buttons-group_drag" || "lingvo-input-buttons-group"} ref={preview} id={id}>
{!(is_being_updated || edit) && (
<span className="lingvo-input-buttons-group__name">{content}</span>
<span className="lingvo-input-buttons-group__name"><RegExpMarker mark={metatext}>{text}</RegExpMarker></span>
)}
{(is_being_updated || edit) && (
/* new!!!!!! */
<TextareaAutosize
defaultValue={content}
defaultValue={text}
onChange={(event) => setContent(event.target.value)}
onKeyDown={onKeyDown}
className="lingvo-input-action lingvo-input-action_textarea"
/>
/* /new!!!!!! */
)}
<Button.Group basic icon className="lingvo-buttons-group">
{/* new!!!!! */}
<div ref={dragRef} className="lingvo-buttons-group__drag">
<Button icon={<i className="lingvo-icon lingvo-icon_dnd" />} />
</div>
{/* new!!!!! */}
<Button icon={is_being_updated ? <i className="lingvo-icon lingvo-icon_spinner" /> : edit ? <i className="lingvo-icon lingvo-icon_save2" /> : <i className="lingvo-icon lingvo-icon_edit2" />}
onClick={onEdit}
disabled={is_being_updated || !content}
className={is_being_updated ? "lingvo-button-spinner" : ""}
/>
{is_being_removed ? (
<Button icon={<i className="lingvo-icon lingvo-icon_spinner" />} disabled className="lingvo-button-spinner" />
) : (
<Button icon={<i className="lingvo-icon lingvo-icon_delete2" />} onClick={() => remove(entity)} />
)}
</Button.Group>
{ read_only || (
<Button.Group basic icon className="lingvo-buttons-group">
{/* new!!!!! */}
<div ref={dragRef} className="lingvo-buttons-group__drag">
<Button icon={<i className="lingvo-icon lingvo-icon_dnd" />} />
</div>
{/* new!!!!! */}
<Button icon={is_being_updated ? <i className="lingvo-icon lingvo-icon_spinner" /> : edit ? <i className="lingvo-icon lingvo-icon_save2" /> : <i className="lingvo-icon lingvo-icon_edit2" />}
onClick={onEdit}
disabled={is_being_updated || !text}
className={is_being_updated ? "lingvo-button-spinner" : ""}
/>
{is_being_removed ? (
<Button icon={<i className="lingvo-icon lingvo-icon_spinner" />} disabled className="lingvo-button-spinner" />
) : (
<Button icon={<i className="lingvo-icon lingvo-icon_delete2" />} onClick={() => remove(entity)} />
)}
</Button.Group>
)}
</div>
) : null;
case "publish":
Expand All @@ -165,11 +190,11 @@ const TextEntityContent = ({
href={`/dictionary/${entity.parent_id[0]}/${entity.parent_id[1]}/perspective/${entity.id[0]}/${entity.id[1]}/edit`}
className="lingvo-languages-link"
>
{entity.content}
{text}
</a>
</span>
) : (
<span className="lingvo-entry-content">{entity.content}</span>
<span className="lingvo-entry-content"><RegExpMarker mark={metatext}>{text}</RegExpMarker></span>
)}
<Checkbox
className="lingvo-checkbox lingvo-entry-text__checkbox"
Expand All @@ -195,14 +220,14 @@ const TextEntityContent = ({

case "view":
return (
<span className="lingvo-entry-content">{entity.content}</span>
<span className="lingvo-entry-content"><RegExpMarker mark={metatext}>{text}</RegExpMarker></span>
);
case "contributions":
return entity.accepted ? (
<span className="lingvo-entry-content">{entity.content}</span>
<span className="lingvo-entry-content"><RegExpMarker mark={metatext}>{text}</RegExpMarker></span>
) : (
<Button.Group basic icon className="lingvo-buttons-group">
<Button content={entity.content} className="lingvo-buttons-group__text" />
<Button content={text} className="lingvo-buttons-group__text" />
<Button
icon={<i className="lingvo-icon lingvo-icon_check2" />}
onClick={() => accept(entity, true)}
Expand All @@ -224,6 +249,7 @@ const Text = onlyUpdateForKeys([
"checkedRow",
"checkedColumn",
"checkedAll",
"number",
"draggable", // new!!!!!!
"id", // new!!!!!!
])(props => {
Expand Down Expand Up @@ -253,6 +279,7 @@ const Text = onlyUpdateForKeys([
breakdown, /* new!!!!!!! */
is_being_removed,
is_being_updated,
number,
draggable, /* new!!!!!! */
id, /* new!!!!!! */
} = props;
Expand Down Expand Up @@ -281,6 +308,7 @@ const Text = onlyUpdateForKeys([
breakdown={breakdown} /* new!!!!!!! */
is_being_removed={is_being_removed}
is_being_updated={is_being_updated}
number={number}
id={id} /* new!!!!!! */
draggable /* new!!!!!! */
/>
Expand All @@ -304,6 +332,7 @@ const Text = onlyUpdateForKeys([
breakdown={breakdown} /* new!!!!!!! */
is_being_removed={is_being_removed}
is_being_updated={is_being_updated}
number={number}
id={id} /* new!!!!!! */
/>
)}
Expand Down Expand Up @@ -349,6 +378,7 @@ Text.propTypes = {
resetCheckedRow: PropTypes.func,
resetCheckedColumn: PropTypes.func,
resetCheckedAll: PropTypes.func,
number: PropTypes.string,
draggable: PropTypes.bool, /* new!!!!! */
id: PropTypes.array.isRequired, /* new!!!!! */
};
Expand Down
8 changes: 7 additions & 1 deletion src/components/LexicalEntryCorp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ const Entities = ({
removeEntity,
updateEntity,
client,
number
}) => {

const filters = [
Expand Down Expand Up @@ -491,6 +492,7 @@ const Entities = ({
resetCheckedColumn,
checkedAll,
resetCheckedAll,
number
};

const Component = getComponent(column.data_type);
Expand All @@ -499,6 +501,8 @@ const Entities = ({
return <Component {...props} />;
}

const is_order_column = column.english_translation === "Order";

return (
<ul>
{entities.map(entity => (
Expand Down Expand Up @@ -530,11 +534,12 @@ const Entities = ({
disabled={disabled}
is_being_removed={remove_set.hasOwnProperty(id2str(entity.id))}
is_being_updated={update_set.hasOwnProperty(id2str(entity.id))}
number={number}
draggable={true} /* new!!!!! */
id={entity.id} /* new!!!!! */
/>
))}
{mode === "edit" && (
{mode === "edit" && !is_order_column && (
<li className="last">
{!edit && (
<div ref={dropRef} /* new!!!! */>
Expand Down Expand Up @@ -586,6 +591,7 @@ Entities.propTypes = {
resetCheckedColumn: PropTypes.func,
resetCheckedAll: PropTypes.func,
reRender: PropTypes.func,
number: PropTypes.string
};

Entities.defaultProps = {
Expand Down

0 comments on commit 00a5499

Please sign in to comment.