Skip to content

Commit 51e280d

Browse files
committed
auto-uploading
1 parent ba7ae18 commit 51e280d

File tree

1 file changed

+49
-30
lines changed

1 file changed

+49
-30
lines changed

src/pages/Perspective/component.js

+49-30
Original file line numberDiff line numberDiff line change
@@ -1113,30 +1113,24 @@ const Filter = handlers(({ value, onChange, onSubmit, isCaseSens, onToggleCaseSe
11131113
);
11141114
});
11151115

1116-
const tsakorpusIdStrSet = {
1117-
"3796,6": null,
1118-
"4222,7": null,
1119-
"3235,7": null,
1120-
"4083,7": null,
1121-
"3421,8": null,
1122-
"3648,8": null,
1123-
"3814,9": null,
1124-
"3872,9": null,
1125-
"5180,9": null,
1126-
"3428,9": null,
1127-
"4448,9": null,
1128-
"4830,11": null,
1129-
"5039,22": null,
1130-
"4830,27": null,
1131-
"4473,32": null,
1132-
"4443,37": null,
1133-
"5124,45": null,
1134-
"4447,99": null,
1135-
"4447,130": null,
1136-
"3539,769": null,
1137-
"3391,9437": null,
1138-
"4084,86722": null
1139-
};
1116+
const getUploadDate = gql`
1117+
query getUploadDate($id: LingvodocID!) {
1118+
perspective(id: $id) {
1119+
id
1120+
additional_metadata {
1121+
uploaded_at
1122+
}
1123+
}
1124+
}
1125+
`;
1126+
1127+
const uploadPerspective = gql`
1128+
mutation uploadPerspective($id: LingvodocID!, $debugFlag: Boolean) {
1129+
tsakorpus(perspective_id: $id, debug_flag: $debugFlag) {
1130+
triumph
1131+
}
1132+
}
1133+
`;
11401134

11411135
const ModeSelector = compose(
11421136
connect(state => state.user),
@@ -1157,6 +1151,24 @@ const ModeSelector = compose(
11571151
}) => {
11581152
const getTranslation = useContext(TranslationContext);
11591153

1154+
const {data: dateData, error: dateError, loading: dateLoading, refetch} = (
1155+
useQuery(getUploadDate, { variables: { id }, fetchPolicy: "network-only" }));
1156+
1157+
const [runUploadPerspective, {data, error, loading}] = (
1158+
useMutation(uploadPerspective, { variables: { id }, onCompleted: refetch }));
1159+
1160+
if (dateLoading || dateError) {
1161+
return null;
1162+
}
1163+
1164+
const {
1165+
perspective: { additional_metadata: { uploaded_at }}
1166+
} = dateData;
1167+
1168+
if (!uploaded_at && !loading && !error && !data) {
1169+
runUploadPerspective();
1170+
}
1171+
11601172
const modes = {};
11611173
if (user.id !== undefined) {
11621174
Object.assign(modes, {
@@ -1190,8 +1202,6 @@ const ModeSelector = compose(
11901202
}
11911203
});
11921204

1193-
const tsakorpusFlag = tsakorpusIdStrSet.hasOwnProperty(id2str(id));
1194-
11951205
return (
11961206
<Menu tabular className="lingvo-perspective-menu">
11971207
{map(modes, (info, stub) => (
@@ -1200,10 +1210,19 @@ const ModeSelector = compose(
12001210
{info.component === PerspectiveView ? <Counter id={id} mode={info.entitiesMode} /> : null}
12011211
</Menu.Item>
12021212
))}
1203-
{tsakorpusFlag && (
1204-
<Menu.Item key="corpus_search" href={`http://83.149.198.78/${id[0]}_${id[1]}/search`}>
1205-
{getTranslation("Corpus search")}
1206-
</Menu.Item>
1213+
{ (uploaded_at || loading) && (
1214+
<Menu.Item
1215+
key="corpus_search"
1216+
onClick={() => uploaded_at && window.open(`http://83.149.198.78/${id[0]}_${id[1]}/search`, "_blank")}
1217+
content={
1218+
loading ? (
1219+
<span>
1220+
{getTranslation("Uploading")}... <Icon name="spinner" loading />
1221+
</span>
1222+
) : (
1223+
getTranslation("Corpus search")
1224+
)}
1225+
/>
12071226
)}
12081227
<Tools
12091228
id={id}

0 commit comments

Comments
 (0)