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

feat(bottle): handle top notch area #60

Merged
merged 3 commits into from
Sep 24, 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
35 changes: 23 additions & 12 deletions apps/bottle/src/app/layout.css.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
import { colors, spacings } from '@bottlesteam/ui';
import { style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';

export const layoutStyle = style({
width: '100%',
minWidth: '360px',
padding: '0 16px',
'@media': {
'screen and (min-width: 500px)': {
width: '360px',
export const layoutStyle = recipe({
base: {
width: '100%',
minWidth: '360px',
padding: '0 16px',
'@media': {
'screen and (min-width: 500px)': {
width: '360px',
},
},
height: 'auto',
minHeight: '100vh',
backgroundColor: colors.neutral50,
margin: '0 auto',
position: 'relative',
},
variants: {
notch: {
true: {
paddingTop: 'env(safe-area-inset-top)',
},
false: {},
},
},
height: 'auto',
minHeight: '100vh',
backgroundColor: colors.neutral50,
margin: '0 auto',
position: 'relative',
});

export const errorImageContainer = style({
Expand Down
4 changes: 3 additions & 1 deletion apps/bottle/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { AppBridgeProvider } from '@/features/app-bridge/AppBridgeProvider';
import { UserAgentProvider } from '@/features/user-agent/UserAgentProvider';
import { QueryClientProvider } from '@/store/query/QueryClientProvider';
import { getCookie } from 'cookies-next';
import type { Metadata } from 'next';
import './globals.css';
import '@bottlesteam/ui/styles';
import type { Viewport } from 'next';
import { cookies } from 'next/headers';
import { wantedSansStd } from '../fonts';
import { layoutStyle } from './layout.css';

Expand All @@ -27,7 +29,7 @@ export default function RootLayout({
return (
<html lang="en">
<body className={wantedSansStd.className}>
<main className={layoutStyle}>
<main className={layoutStyle({ notch: getCookie('version', { cookies }) != null })}>
<QueryClientProvider>
<UserAgentProvider>
<AppBridgeProvider>{children}</AppBridgeProvider>
Expand Down
38 changes: 32 additions & 6 deletions apps/bottle/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,53 @@ import type { NextRequest } from 'next/server';

export async function middleware(request: NextRequest) {
const url = new URL(request.url);
if (String(url).includes('accessToken')) {
const accessToken = url.searchParams.get('accessToken') ?? '';
const refreshToken = url.searchParams.get('refreshToken') ?? '';
const cleanUrl = new URL(url);

const cleanUrl = new URL(url);
let accessToken;
let refreshToken;
let device;
let version;

if (String(url).includes('accessToken') && String(url).includes('refreshToken')) {
accessToken = url.searchParams.get('accessToken') ?? '';
refreshToken = url.searchParams.get('refreshToken') ?? '';
cleanUrl.searchParams.delete('accessToken');
cleanUrl.searchParams.delete('refreshToken');
const response = NextResponse.redirect(cleanUrl.toString());
}

if (String(url).includes('device') && String(url).includes('version')) {
device = url.searchParams.get('device')!;
version = url.searchParams.get('version')!;
cleanUrl.searchParams.delete('device');
cleanUrl.searchParams.delete('version');
}

if (url.toString() !== cleanUrl.toString()) {
const response = NextResponse.redirect(cleanUrl.toString());
if (accessToken != null && refreshToken != null) {
response.cookies.set('accessToken', accessToken, { httpOnly: false });
response.cookies.set('refreshToken', refreshToken, { httpOnly: false });
}
if (device != null && version != null) {
response.cookies.set('device', device, { httpOnly: false });
response.cookies.set('version', version, { httpOnly: false });
}

return response;
}

const response = NextResponse.next();

return response;
}

export const config = {
matcher: ['/bottles/:path*', '/my', '/create-profile/:path*', '/profile/create/:path*', '/profile/edit/:path*'],
matcher: [
'/bottles/:path*',
'/my',
'/create-profile/:path*',
'/profile/create/:path*',
'/profile/edit/:path*',
'/admin/:path*',
],
};
Loading