Skip to content

Instantly share code, notes, and snippets.

View maapteh's full-sized avatar
🏠
Working from home

Mаартен - Maarten maapteh

🏠
Working from home
  • The Hague, Moscow
View GitHub Profile
Pet: {
/**
* Format: int64
* @example 10
*/
id?: number;
/** @example doggie */
name: string;
category?: components["schemas"]["Category"];
photoUrls: string[];
@maapteh
maapteh / pet-store.d.ts
Last active May 9, 2022 07:44
pet-store.d.ts
/* eslint-disable */
/* auto generated by yarn workspace @maapteh/types tooling:generate-types */
declare namespace PetStoreRaw {
/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/
export interface paths {
'/pet': {
@maapteh
maapteh / index.d.ts
Last active May 7, 2022 10:36
central types
// Imports of types for `index.d.ts`
/// <reference path="./pet-store.d.ts" />
/// <reference path="./wild-cats.d.ts" />
@maapteh
maapteh / package.json
Last active May 7, 2022 10:36
petStore package types
{
"name": "@maapteh/types-api-animals",
"version": "1.0.0",
"typings": "index.d.ts"
}
export enum Viewport {
xs = 'xs',
sm = 'sm',
md = 'md',
lg = 'lg',
xl = 'xl',
'2xl' = '2xl',
}
import React from 'react';
import { Viewport } from '@lib/types';
import {
screen,
render,
renderHook,
waitFor,
} from '../../__tests__/test-utils';
import { MockedViewportProvider } from '../../__mocks__/mock-viewport-provider';
import React, { ReactNode } from 'react';
import { Viewport } from '@lib/types';
import { ViewportContext } from '../hooks/use-viewport/use-viewport';
type TMockedViewportProps = {
children: ReactNode;
viewport?: Viewport;
};
const MockedViewportProvider = ({
@maapteh
maapteh / viewport.jsx
Last active January 28, 2022 18:44
Viewport based on MatchMedia
import React, {
FC,
ReactNode,
useState,
useEffect,
createContext,
useContext,
useCallback,
} from 'react';
import { Viewport } from '@lib/types';
@maapteh
maapteh / _app.jsx
Created January 26, 2022 20:52
App
function App({ Component, pageProps }: AppProps) {
const { i18n } = useTranslation();
const { locale, viewport } = pageProps;
if (locale !== i18n.language) {
i18n.changeLanguage(locale);
}
return (
<I18nProvider>
@maapteh
maapteh / next-middleware.js
Created January 26, 2022 20:46
NextJS middleware using getViewportFromUserAgent
export function middleware(req: NextRequest) {
const { pathname } = req.nextUrl;
// public static stuff
if (pathname.startsWith('/images') || pathname.startsWith('/fonts')) {
return undefined;
}
// api/static/client routes NextJS stuff
if (pathname.includes('.') || pathname.startsWith('/api')) {