This commit is contained in:
2026-06-24 15:59:04 +02:00
commit 510945b733
32 changed files with 7009 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.env
.next
.git
+1
View File
@@ -0,0 +1 @@
NEXT_PUBLIC_BACKEND_URI=
+37
View File
@@ -0,0 +1,37 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env*.local
.env
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
+9
View File
@@ -0,0 +1,9 @@
FROM node:24.4.1-alpine3.22
WORKDIR /app
COPY . .
RUN npm ci
RUN npx next telemetry disable
RUN npm run build
RUN adduser -D appuser && chown -R appuser /app
USER appuser
CMD npm run start
+14
View File
@@ -0,0 +1,14 @@
'use client'
import { apollo } from '@/lib'
import { ApolloProvider } from '@apollo/client/react'
import { ChakraProvider } from '@chakra-ui/react'
export const Providers = ({ children }: { children: React.ReactNode }) => {
return (
<ApolloProvider client={apollo}>
<ChakraProvider>
{children}
</ChakraProvider>
</ApolloProvider>
)
}
+1
View File
@@ -0,0 +1 @@
# Frontend for MemeSearch 🔎
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

+19
View File
@@ -0,0 +1,19 @@
import { Providers } from '@/Providers'
import type { Metadata } from 'next'
export const metadata: Metadata = {
title: 'Meme Search Client'
}
export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
return (
<html lang='en'>
<body>
<Providers>
{children}
</Providers>
</body>
</html>
)
}
+78
View File
@@ -0,0 +1,78 @@
'use client'
import { InputField, Wrapper } from '@/components'
import { SearchDocument } from '@/generated/graphql/graphql'
import { useQuery } from '@apollo/client/react'
import { Image } from '@chakra-ui/react'
import { Box, Button, Flex, Text } from '@chakra-ui/react'
import { Form, Formik } from 'formik'
// import { readFileSync } from 'fs'
import { useState } from 'react'
const Home: React.FC = () => {
const [imageFile, setImageFile] = useState<File | null>(null)
const { refetch, loading } = useQuery(SearchDocument, { skip: true })
const [results, setResults] = useState<{ __typename?: string, image: string, text: string }[]>([])
return (
<main>
<Wrapper variant='regular'>
<Formik
initialValues={{ image: '' }}
onSubmit={async ({ }, { setValues }) => {
if (imageFile) {
setResults([])
const reader = new FileReader()
reader.readAsArrayBuffer(imageFile)
reader.onloadend = async () => {
const b64 = Buffer.from(reader.result as string, 'base64').toString('base64')
const result = await refetch({ image: b64, limit: 10 })
setResults(result.data!.search)
setImageFile(null)
setValues({ image: '' })
}
}
}}
>
{({ isSubmitting }) => (
<Form>
<InputField
label='Upload image to search for the most similar memes'
name='image'
type='file'
accept='image/*'
p={2}
h='3rem'
onChange={(e) => {
setResults([])
if (e.currentTarget.files) {
setImageFile(e.currentTarget.files[0])
}
}}
/>
{
imageFile &&
<Flex flexDir='column' alignItems='center' mt={4}>
<Text>Selected image: {imageFile.name}</Text>
</Flex>
}
<Flex mt={4} w='100%' justifyContent='center'>
<Button type='submit' isLoading={isSubmitting || loading} hidden={!imageFile ? true : false}>Search</Button>
</Flex>
</Form>
)}
</Formik>
<Flex alignItems='center' justifyContent='center' p={2} flexWrap='wrap' rowGap={4}>
{
results?.map(r => (
<Flex flexDir='column' alignItems='center'>
<Image src={`data:image/${r.text.split('.')[r.text.split('.').length - 1]};base64,${r.image}`} alt={r.text || ''} />
<Text mt={4}>{r.text}</Text>
</Flex>
))
}
</Flex>
</Wrapper>
</main>
)
}
export default Home
+17
View File
@@ -0,0 +1,17 @@
'use client'
import { CloseIcon } from '@chakra-ui/icons'
import { Flex, Text } from '@chakra-ui/react'
interface Props {
message: string
}
export const FormErrorMessage: React.FC<Props> = (props) => {
const { message } = props
return (
<Flex alignItems='center' color='red' mt={4} fontSize='0.875rem' >
<CloseIcon color='red' mr={2.5} fontSize='0.725rem'/>
<Text color='red'>{message}</Text>
</Flex>
)
}
+17
View File
@@ -0,0 +1,17 @@
'use client'
import { CheckIcon } from '@chakra-ui/icons'
import { Flex, Text } from '@chakra-ui/react'
interface Props {
message: string
}
export const FormSuccessMessage: React.FC<Props> = (props) => {
const { message } = props
return (
<Flex alignItems='center' color='green-500' mt={4} fontSize='0.875rem'>
<CheckIcon color='green.700' fontSize='0.875rem' mr={2} />
<Text color='green'>{message}</Text>
</Flex>
)
}
+18
View File
@@ -0,0 +1,18 @@
'use client'
import { FormControl, FormErrorMessage, FormLabel, Input, InputProps } from '@chakra-ui/react'
import { useField } from 'formik'
type Props = React.InputHTMLAttributes<HTMLInputElement> & InputProps & { name: string, label: string, isTextArea?: boolean }
export const InputField: React.FC<Props> = ({size: _, isTextArea=false, ...props}) => {
const [field, { error }] = useField(props)
const { label, placeholder } = props
return (
<FormControl isInvalid={!!error}>
<FormLabel htmlFor={field.name}>{label}</FormLabel>
<Input {...field} {...props} id={field.name} placeholder={placeholder} />
{error ? <FormErrorMessage>{error}</FormErrorMessage> : null}
</FormControl>
)
}
+10
View File
@@ -0,0 +1,10 @@
'use client'
import { Button, PropsOf } from '@chakra-ui/react'
import { useRouter } from 'next/navigation'
export const RefetchButton: React.FC<PropsOf<typeof Button>> = (props) => {
const router = useRouter()
return (
<Button onClick={() => { router.refresh() }} {...props}>Refetch</Button>
)
}
+36
View File
@@ -0,0 +1,36 @@
'use client'
import { FormControl, FormErrorMessage, FormLabel, Textarea } from '@chakra-ui/react'
import autosize from 'autosize'
import { useField } from 'formik'
import { useRef, useEffect } from 'react'
type Props = React.TextareaHTMLAttributes<HTMLTextAreaElement> & { name: string, label: string }
export const TextareaField: React.FC<Props> = (props) => {
const [field, { error }] = useField(props)
const { label, placeholder } = props
// https://github.com/chakra-ui/chakra-ui/issues/670
const ref: any = useRef(null)
useEffect(() => {
const current = ref.current
autosize(current)
return () => {
autosize.destroy(current)
}
}, [])
return (
<FormControl isInvalid={!!error}>
<FormLabel htmlFor={field.name}>{label}</FormLabel>
<Textarea
{...field}
{...props}
ref={ref}
id={field.name}
placeholder={placeholder}
/>
{error ? <FormErrorMessage>{error}</FormErrorMessage> : null}
</FormControl>
)
}
+14
View File
@@ -0,0 +1,14 @@
import { Box } from '@chakra-ui/react'
interface Props {
children: React.ReactNode
variant?: 'small' | 'regular'
}
export const Wrapper: React.FC<Props> = ({ children, variant = 'regular' }) => {
return (
<Box w='100%' maxW={variant == 'small' ? 400 : 800} mt={8} mx='auto'>
{children}
</Box>
)
}
+6
View File
@@ -0,0 +1,6 @@
export * from './Wrapper'
export * from './InputField'
export * from './TextareaField'
export * from './RefetchButton'
export * from './FormSuccessMessage'
export * from './FormErrorMessage'
Vendored
+9
View File
@@ -0,0 +1,9 @@
declare global {
namespace NodeJS {
interface ProcessEnv {
NEXT_PUBLIC_BACKEND_URI: string;
}
}
}
export {}
+42
View File
@@ -0,0 +1,42 @@
/* eslint-disable */
import * as types from './graphql';
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
/**
* Map of all GraphQL operations in the project.
*
* This map has several performance disadvantages:
* 1. It is not tree-shakeable, so it will include all operations in the project.
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
* 3. It does not support dead code elimination, so it will add unused operations.
*
* Therefore it is highly recommended to use the babel or swc plugin for production.
*/
const documents = {
"query Search($limit: Int, $image: String) {\n search(limit: $limit, image: $image) {\n image\n text\n }\n}": types.SearchDocument,
};
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*
*
* @example
* ```ts
* const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`);
* ```
*
* The query argument is unknown!
* Please regenerate the types.
*/
export function graphql(source: string): unknown;
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "query Search($limit: Int, $image: String) {\n search(limit: $limit, image: $image) {\n image\n text\n }\n}"): (typeof documents)["query Search($limit: Int, $image: String) {\n search(limit: $limit, image: $image) {\n image\n text\n }\n}"];
export function graphql(source: string) {
return (documents as any)[source] ?? {};
}
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode< infer TType, any> ? TType : never;
+45
View File
@@ -0,0 +1,45 @@
/* eslint-disable */
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
export type Maybe<T> = T | null;
export type InputMaybe<T> = Maybe<T>;
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
export type MakeEmpty<T extends { [key: string]: unknown }, K extends keyof T> = { [_ in K]?: never };
export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: { input: string; output: string; }
String: { input: string; output: string; }
Boolean: { input: boolean; output: boolean; }
Int: { input: number; output: number; }
Float: { input: number; output: number; }
};
export type Meme = {
__typename?: 'Meme';
image: Scalars['String']['output'];
text: Scalars['String']['output'];
};
export type Query = {
__typename?: 'Query';
search: Array<Meme>;
};
export type QuerySearchArgs = {
image?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
};
export type SearchQueryVariables = Exact<{
limit?: InputMaybe<Scalars['Int']['input']>;
image?: InputMaybe<Scalars['String']['input']>;
}>;
export type SearchQuery = { __typename?: 'Query', search: Array<{ __typename?: 'Meme', image: string, text: string }> };
export const SearchDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Search"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"limit"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"image"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"search"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"limit"},"value":{"kind":"Variable","name":{"kind":"Name","value":"limit"}}},{"kind":"Argument","name":{"kind":"Name","value":"image"},"value":{"kind":"Variable","name":{"kind":"Name","value":"image"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"image"}},{"kind":"Field","name":{"kind":"Name","value":"text"}}]}}]}}]} as unknown as DocumentNode<SearchQuery, SearchQueryVariables>;
+1
View File
@@ -0,0 +1 @@
export * from "./gql";
+17
View File
@@ -0,0 +1,17 @@
import type { CodegenConfig } from '@graphql-codegen/cli'
const config: CodegenConfig = {
overwrite: true,
schema: 'http://localhost:4000/graphql',
documents: 'graphql/**/*.graphql',
generates: {
'generated/graphql/': {
preset: 'client',
presetConfig: {
fragmentMasking: false
}
}
}
}
export default config
+6
View File
@@ -0,0 +1,6 @@
query Search($limit: Int, $image: String) {
search(limit: $limit, image: $image) {
image
text
}
}
+10
View File
@@ -0,0 +1,10 @@
import { HttpLink } from '@apollo/client'
import { ApolloClient, InMemoryCache } from '@apollo/client'
// This is the client-side client
export const apollo = new ApolloClient({
link: new HttpLink({
uri: process.env.NODE_ENV == 'production' ? 'https://memesearch-backend.elliot-at-zuri.ch/graphql' : process.env.NEXT_PUBLIC_BACKEND_URI,
}),
cache: new InMemoryCache(),
})
+2
View File
@@ -0,0 +1,2 @@
export * from './client'
export * from './server'
+14
View File
@@ -0,0 +1,14 @@
'use server'
import { HttpLink } from '@apollo/client'
import { ApolloClient, InMemoryCache, registerApolloClient } from '@apollo/client-integration-nextjs'
// This is the server-side client
export const createApolloClient = async (cookie?: string) => registerApolloClient(() => {
return new ApolloClient({
link: new HttpLink({
uri: process.env.NODE_ENV == 'production' ? 'https://memesearch-backend.elliot-at-zuri.ch/graphql' : process.env.NEXT_PUBLIC_BACKEND_URI,
credentials: 'include',
}),
cache: new InMemoryCache()
})
})
+1
View File
@@ -0,0 +1 @@
export * from './apollo'
+4
View File
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
export default nextConfig;
+6489
View File
File diff suppressed because it is too large Load Diff
+42
View File
@@ -0,0 +1,42 @@
{
"name": "memesearch-frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"env:generate": "gen-env-types .env -o env.d.ts -e .",
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"graphql:generate": "graphql-codegen --config graphql-codegen.ts"
},
"dependencies": {
"@apollo/client": "^4.0.4",
"@apollo/client-integration-nextjs": "^0.13.1",
"@chakra-ui/icons": "^2.1.1",
"@chakra-ui/next-js": "^2.2.0",
"@chakra-ui/react": "^2.10.9",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@types/autosize": "^4.0.3",
"autosize": "^6.0.1",
"formik": "^2.4.6",
"framer-motion": "^11.3.4",
"graphql": "^16.9.0",
"next": "^15.5.3",
"react": "^19.1.1",
"react-dom": "^19.1.1"
},
"devDependencies": {
"@graphql-codegen/cli": "5.0.2",
"@graphql-codegen/client-preset": "^4.3.2",
"@types/js-yaml": "^4.0.9",
"@types/node": "^24.3.1",
"@types/prop-types": "^15.7.12",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.9",
"@types/ws": "^8.5.11",
"gen-env-types": "^1.3.4",
"typescript": "^5"
}
}
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3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 KiB

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 283 64"><path fill="black" d="M141 16c-11 0-19 7-19 18s9 18 20 18c7 0 13-3 16-7l-7-5c-2 3-6 4-9 4-5 0-9-3-10-7h28v-3c0-11-8-18-19-18zm-9 15c1-4 4-7 9-7s8 3 9 7h-18zm117-15c-11 0-19 7-19 18s9 18 20 18c6 0 12-3 16-7l-8-5c-2 3-5 4-8 4-5 0-9-3-11-7h28l1-3c0-11-8-18-19-18zm-10 15c2-4 5-7 10-7s8 3 9 7h-19zm-39 3c0 6 4 10 10 10 4 0 7-2 9-5l8 5c-3 5-9 8-17 8-11 0-19-7-19-18s8-18 19-18c8 0 14 3 17 8l-8 5c-2-3-5-5-9-5-6 0-10 4-10 10zm83-29v46h-9V5h9zM37 0l37 64H0L37 0zm92 5-27 48L74 5h10l18 30 17-30h10zm59 12v10l-3-1c-6 0-10 4-10 10v15h-9V17h9v9c0-5 6-9 13-9z"/></svg>

After

Width:  |  Height:  |  Size: 629 B

+40
View File
@@ -0,0 +1,40 @@
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": [
"./*"
]
},
"target": "ES2017"
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}