Skip to content

Instantly share code, notes, and snippets.

View hmelenok's full-sized avatar
🙊
Coding

Mykyta Khmel hmelenok

🙊
Coding
View GitHub Profile
import React from 'react';
import {Provider} from 'react-redux';
import App, {Container} from 'next/app';
import withRedux from 'next-redux-wrapper';
import {PersistGate} from 'redux-persist/integration/react';
import {Api} from '@shelf/sdk';
import Error from './_error';
import {initStore} from '../lib/store';
import {initRollbar} from '../lib/rollbar';
import {initIntercom} from '../lib/intercom';
/* Amplify Params - DO NOT EDIT
You can access the following resource attributes as environment variables from your Lambda function
var environment = process.env.ENV
var region = process.env.REGION
var storageEmailsBucketName = process.env.STORAGE_EMAILS_BUCKETNAME
Amplify Params - DO NOT EDIT */
var storageEmailsBucketName = process.env.STORAGE_EMAILS_BUCKETNAME;
var AWS = require('aws-sdk');
var s3 = new AWS.S3();
@hmelenok
hmelenok / structure.txt
Last active April 27, 2021 16:17
File structure for i18n package
i18n
├── README.md
├── babel.config.js
├── create-translations.js
├── crowdin.yml
├── package.json
├── renovate.json
├── src
│ ├── bundles
│ │ ├── app-1
@hmelenok
hmelenok / upload.ts
Created August 25, 2021 07:39
Upload Uppy file
const taskId = ''; //TODO: get task if from prev mutaition
const raw = JSON.stringify({
filename: 'Screenshot 2021-08-20 at 12.06.13.png',
type: 'image/png',
});
const {key: uploadKey, uploadId} = await fetch('https://api.gsstaging.net/cpw/uppy/s3/multipart', {
method: 'POST',
headers: {
'x-cpw-task-id': taskId,
/**
* Now
*/
import Api from './api';
import {ContentApi} from './index';
Api.API_HOST = 'x';
Api.AUTH_TOKEN = 'y';
@hmelenok
hmelenok / crowdin.yml
Created January 11, 2022 10:41
Sync file structure with Crowdin
files:
- source: /src/resources/en/**/*.json
translation: /src/resources/%two_letters_code%/**/%original_file_name%
@hmelenok
hmelenok / i18n.ts
Created January 11, 2022 10:43
React example of app library initialization
import i18NextLib from 'i18next';
import {initReactI18next} from 'react-i18next'; //To have a react context
import {resources} from 'dictionary-package/lib/bundles/app-1'; //reduce bundles if there is many
import {defaultInterpolation} from 'dictionary-package/lib/lib/helpers'; // day-to-day functions to format text
const i18next = i18NextLib.createInstance();
i18next.use(initReactI18next).init({
lng: 'en',
resources,
@hmelenok
hmelenok / Component.tsx
Created January 11, 2022 10:44
i18n in React usage
import {useTranslation} from 'react-i18next';
const Index: FC = () => {
const {t} = useTranslation();
return (
<MainLayout pageTitle={t(`app-1.common.pageTitle`)}>
{t(`app-1.common.pageTitle`)}
</MainLayout>
);
}
@hmelenok
hmelenok / de-glossary.json
Created January 11, 2022 10:55
Example of translation file
{
//Simple key->translation
"search": "Suchen",
"noResults": "Keine Suchergebnisse gefunden",
"publish": "Veröffentlichen",
"cancel": "Abbrechen",
"save": "Speichern",
//nested key->key->translation
"fileTypes": {
"document": "Dokument",
@hmelenok
hmelenok / useVisibilityChange.tsx
Created May 10, 2022 07:45
visibilitychange with react useSyncExternalStore
export function useVisibilityChange(serverFallback: boolean) {
const getServerSnapshot = () => serverFallback;
const [getSnapshot, subscribe] = useMemo(() => {
return [
() => document.visibilityState === 'visible',
(notify: () => void) => {
window.addEventListener('visibilitychange', notify);
return () => {
window.removeEventListener('visibilitychange', notify);