Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add word status #347

Merged
merged 11 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
"start": "npm run dev",
"storybook": "storybook dev -p 6006",
"test:pw": "playwright test",
"test:unit": "jest --logHeapUsage --coverage --config jest-config.json"
"test:unit": "jest --logHeapUsage --coverage --config jest-config.json",
"test:dictionary": "cross-env NODE_ENV=production UPDATE_SNAPSHOT=false ts-node -r tsconfig-paths/register ./src/services/dictionary-test",
"test:dictionary-update-shanshot": "cross-env NODE_ENV=production UPDATE_SNAPSHOT=false ts-node -r tsconfig-paths/register ./src/services/dictionary-test"
},
"pre-commit": [
"lint",
"stylelint"
"lint:fix",
"stylelint:fix"
],
"dependencies": {
"@ag-grid-community/client-side-row-model": "25.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ body {
--table-highlighted-cell: #81D4FA;
--table-border-color: var(--gray-9);
--overlay-color: #000;
--tips-font-color: #122f80;
--main-background-color: #FAFAFA;
--tips-background-color: #1976D2;
--status-badge-color: #fff;
--dark: #212121;
--light: #fff;
Expand All @@ -53,8 +53,8 @@ body {
--table-highlighted-cell: #1976D2;
--table-border-color: var(--gray-9);
--overlay-color: #000;
--tips-font-color: #122f80;
--main-background-color: #262626;
--tips-background-color: #81D4FA;
--status-badge-color: #fff;
--dark: #fff;
--light: #212121;
Expand Down
12 changes: 7 additions & 5 deletions src/components/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ export const Main =
const theme = isDarkTheme ? 'dark' : 'light';

useEffect(() => {
async function fetchAll() {
document.getElementById('app').className='color-theme--' + theme;

(async () => {
await fetchDictionary(dispatch, dictionaryLanguages);
await fetchCommunityLinks(dispatch, communityLinks);
}

fetchAll();
document.getElementById('app').className='color-theme--' + theme;
if (IS_COM) {
await fetchCommunityLinks(dispatch, communityLinks);
}
})()
}, [dispatch, dictionaryLanguages, theme]);

return (
Expand Down
13 changes: 10 additions & 3 deletions src/components/Modals/TranslationsModal/TranslationsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useModalDialog } from 'hooks/useModalDialog';
import { useResults } from 'hooks/useResults';
import { getCyrillic } from 'utils/getCyrillic';
import { getLatin } from 'utils/getLatin';
import { getWordStatus } from "utils/getWordStatus";
import { findIntelligibilityIssues } from "utils/intelligibilityIssues";

import { Table } from 'components/Table';
Expand Down Expand Up @@ -65,15 +66,15 @@ export const TranslationsModal =
return [
[
`{${t('isvEtymologicLatinLang')}}[B]@ts;b;sw=130px;nowrap`,
`${getLatin(translate, '2')}@ts`,
`${getLatin(item.isv, '2')}@ts`,
],
[
`{${t('isvLatinLang')}}[B]@ts;b`,
`${getLatin(translate, '3')}@ts`,
`${getLatin(item.isv, '3')}@ts`,
],
[
`{${t('isvCyrillicLang')}}[B]@ts;b`,
`${getCyrillic(translate, '3')}@ts`,
`${getCyrillic(item.isv, '3')}@ts`,
],
[
`@w=2;S`,
Expand All @@ -98,6 +99,7 @@ export const TranslationsModal =
}, []);

const hasMarks = new Set(Object.values(marks).filter(Boolean)).size > 0;
const wordStatus = getWordStatus(item)
const extraLegend = hasMarks && (<>
<br/>
⚠️ – {t('translationsLegendIntelligibilityWarning')}.<br/>
Expand All @@ -119,6 +121,11 @@ export const TranslationsModal =
</button>
</div>
<div className="modal-dialog__body">
{wordStatus && (
<div>
{wordStatus.icon}&nbsp;{t(wordStatus.text)}
</div>
)}
<Table data={tableData}/>
</div>
<footer className="modal-dialog__footer">
Expand Down
36 changes: 9 additions & 27 deletions src/components/Pages/CommunityPage/CommunityPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import { useEffect, useState } from 'react';
import { useEffect } from 'react';
import { useDispatch } from 'react-redux';

import { t } from 'translations';
Expand Down Expand Up @@ -71,32 +71,17 @@ export const CommunityPage = () => {
const dispatch = useDispatch();
const communityLinks = useCommunityLinks();
const online = isOnline();
const [isFbAvailable, setFbAvailable] = useState(false);

useEffect(() => {
try {
fetch('https://www.facebook.com', {
mode: 'no-cors',
cache: 'no-cache',
}).then((res) => {
if (res) {
setFbAvailable(true);
}
});
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {}
}, [setFbAvailable]);

useEffect(() => {
if (online && FB && isFbAvailable) {
if (online && FB) {
FB.init({
xfbml: true,
version: 'v12.0'
});

dispatch(setBadges([]));
}
}, [communityLinks, isFbAvailable, FB]);
}, [communityLinks, FB]);

if (!online) {
return <OfflinePlaceholder className="community-offline"/>
Expand All @@ -106,15 +91,12 @@ export const CommunityPage = () => {
<div className="community">
<h1 className="community__title">{t('communityPageTitle')}</h1>
<p className="community__sub-title">{t('communityPageSubTitle')}</p>
{
communityLinks
.filter(({ link }) => {
const linkType = getLinkType(link);

return linkType === 'facebook' ? isFbAvailable : true;
})
.map((linkData, i) => (<CommunityLink key={i} {...linkData} />))
}
{communityLinks.map((linkData, i) => (
<CommunityLink
key={i}
{...linkData}
/>
))}
</div>
);
};
Expand Down
2 changes: 2 additions & 0 deletions src/components/ResultsCard/ResultCard.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const enIsvItemMock = {
"caseInfo": "",
"details": "m.anim.",
"ipa": "kɔt",
"id": "1093",
"checked": true,
"raw": ["1093", "kot", "", "m.anim.", "cat, tom-cat", "кот", "кот", "кіт", "kot, kocur", "kocour, kot", "kocúr, kot", "!Mačka", "mačak, mačor", "мачак, мачор", "мачор", "котарак", "!"],
"from": "en",
Expand All @@ -40,6 +41,7 @@ const isvEnItemMock = {
"caseInfo": "",
"details": "m.anim.",
"ipa": "kɔt",
"id": "1093",
"checked": true,
"raw": ["1093", "kot", "", "m.anim.", "cat, tom-cat", "кот", "кот", "кіт", "kot, kocur", "kocour, kot", "kocúr, kot", "!Mačka", "mačak, mačor", "мачак, мачор", "мачор", "котарак", "!"],
"from": "isv",
Expand Down
45 changes: 25 additions & 20 deletions src/components/ResultsCard/ResultsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import { Dictionary, ITranslateResult } from 'services/dictionary';
import { useAlphabets } from 'hooks/useAlphabets';
import { useCaseQuestions } from 'hooks/useCaseQuestions';
import { useLang } from 'hooks/useLang';
import { estimateIntelligibility, hasIntelligibilityIssues } from "utils/intelligibilityIssues";
import { getWordStatus } from "utils/getWordStatus";
import { toQueryString } from 'utils/toQueryString';
import { getPartOfSpeech } from 'utils/wordDetails';
import { wordHasForms } from 'utils/wordHasForms';

import { Clipboard } from 'components/Clipboard';

import { removeBrackets } from "../../utils/removeBrackets";

import './ResultsCard.scss';

import ErrorIcon from './images/error-icon.svg';
Expand Down Expand Up @@ -81,27 +79,41 @@ function renderOriginal(item, alphabets, caseQuestions) {
return (
<span className="word" key={i}>
<Clipboard str={str} />
{caseInfo && <> <span className="caseInfo">({caseInfo})</span></>}
{caseInfo && <span className="caseInfo">({caseInfo})</span>}
</span>
);
})}
{!caseQuestions && item.caseInfo &&
<> <span className="caseInfo">(+{t(`case${item.caseInfo.slice(1)}`)})</span></>
<span className="caseInfo">(+{t(`case${item.caseInfo.slice(1)}`)})</span>
}
{item.ipa && <> <span className="ipa">[{item.ipa}]</span></>}
{item.ipa && <span className="ipa">[{item.ipa}]</span>}
</>
);
}

const WordStatus = ({ item, onClick }: { item: ITranslateResult, onClick: () => void }) => {
const wordStatus = getWordStatus(item)

if (wordStatus) {
return (
<button
key="wordStatus"
onClick={onClick}
className="results-card__status"
title={t(wordStatus.text)}
>
{wordStatus.icon}
</button>
);
}
}

export const ResultsCard =
({ item, short, index }: IResultsCardProps) => {
const alphabets = useAlphabets();
const caseQuestions = useCaseQuestions();
const wordId = Dictionary.getField(item.raw, 'id')?.toString();
const pos = getPartOfSpeech(item.details);
const dispatch = useDispatch();
const intelligibility = Dictionary.getField(item.raw, 'intelligibility');
const intelligibilityVector = estimateIntelligibility(intelligibility);
const lang = useLang();

const showTranslations = () => {
Expand All @@ -115,7 +127,7 @@ export const ResultsCard =
dispatch(showModalDialog({
type: MODAL_DIALOG_TYPES.MODAL_DIALOG_WORD_ERROR,
data: {
wordId,
wordId: item.id,
isvWord: item.original,
translatedWord: item.translate,
},
Expand All @@ -126,7 +138,7 @@ export const ResultsCard =
dispatch(showModalDialog({
type: MODAL_DIALOG_TYPES.MODAL_DIALOG_WORD_FORMS,
data: {
word: removeBrackets(Dictionary.getField(item.raw, 'isv'), '[', ']'),
word: item.isv,
add: Dictionary.getField(item.raw, 'addition'),
details: Dictionary.getField(item.raw, 'partOfSpeech'),
},
Expand All @@ -136,7 +148,7 @@ export const ResultsCard =
const shareWord = () => {
const { origin, pathname } = window.location;
const query = toQueryString({
text: `id${wordId}`,
text: `id${item.id}`,
lang: `${lang.from}-${lang.to}`,
});

Expand Down Expand Up @@ -167,14 +179,7 @@ export const ResultsCard =
<Clipboard str={item.translate} />
) : renderOriginal(item, alphabets, caseQuestions)}
{'\u00A0'}
{ hasIntelligibilityIssues(intelligibilityVector)
? <button
key="intelligibilityIssues"
onClick={showTranslations}
className={classNames({ 'results-card__status': true })}
title={t('intelligibilityIssues')}>⚠️</button>
: undefined
}
<WordStatus item={item} onClick={showTranslations}/>
{item.to === 'isv' && short && (
<>
&nbsp;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Tips/Tips.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
padding: 0.35rem;
border-radius: 0.25rem;
background-color: var(--tips-background-color);
color: var(--tips-font-color);
color: var(--light);
white-space: nowrap;
}

Expand Down
3 changes: 1 addition & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ declare global {

setInitialPage();

if ('serviceWorker' in navigator) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
navigator.serviceWorker.register(`sw.js`, { scope: '.' });
}


const root = createRoot(document.getElementById('app'));

root.render(
Expand Down
1 change: 1 addition & 0 deletions src/services/dictionary-test/basic.json

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions src/services/dictionary-test/deepDiffMapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
export const deepDiffMapper = function () {
return {
VALUE_CREATED: 'created',
VALUE_UPDATED: 'updated',
VALUE_DELETED: 'deleted',
VALUE_UNCHANGED: 'unchanged',
map: function (obj1, obj2) {
if (this.isFunction(obj1) || this.isFunction(obj2)) {
throw 'Invalid argument. Function given, object expected.';
}
if (this.isValue(obj1) || this.isValue(obj2)) {
return {
type: this.compareValues(obj1, obj2),
data: obj1 === undefined ? obj2 : obj1
};
}

const diff = {};
for (const key in obj1) {
if (this.isFunction(obj1[key])) {
continue;
}

let value2 = undefined;
if (obj2[key] !== undefined) {
value2 = obj2[key];
}

diff[key] = this.map(obj1[key], value2);
}
for (const key in obj2) {
if (this.isFunction(obj2[key]) || diff[key] !== undefined) {
continue;
}

diff[key] = this.map(undefined, obj2[key]);
}

return diff;

},
compareValues: function (value1, value2) {
if (value1 === value2) {
return this.VALUE_UNCHANGED;
}
if (this.isDate(value1) && this.isDate(value2) && value1.getTime() === value2.getTime()) {
return this.VALUE_UNCHANGED;
}
if (value1 === undefined) {
return this.VALUE_CREATED;
}
if (value2 === undefined) {
return this.VALUE_DELETED;
}

return this.VALUE_UPDATED;
},
isFunction: function (x) {
return Object.prototype.toString.call(x) === '[object Function]';
},
isArray: function (x) {
return Object.prototype.toString.call(x) === '[object Array]';
},
isDate: function (x) {
return Object.prototype.toString.call(x) === '[object Date]';
},
isObject: function (x) {
return Object.prototype.toString.call(x) === '[object Object]';
},
isValue: function (x) {
return !this.isObject(x) && !this.isArray(x);
}
}
}();
Loading
Loading