chore: add missing files and improve Dockerfile
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@ WORKDIR /app
|
||||
COPY *.html *.json *.ts ./
|
||||
COPY ./src ./src
|
||||
COPY ./public ./public
|
||||
RUN npm ci --ignore-scripts --no-update-notifier --omit=dev && \
|
||||
RUN npm i --ignore-scripts --no-update-notifier --omit=dev && \
|
||||
npm run build && \
|
||||
rm -rf node_modules
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { createContext } from 'react';
|
||||
|
||||
export interface FilterContextData {
|
||||
filterText: string;
|
||||
selectedOption: string;
|
||||
setFilterText: (text: string) => void;
|
||||
setSelectedOption: (option: string) => void;
|
||||
}
|
||||
|
||||
const FilterContext = createContext<FilterContextData>({} as FilterContextData);
|
||||
|
||||
export default FilterContext;
|
||||
@@ -0,0 +1,49 @@
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import FilterContext, { FilterContextData } from './FilterContext';
|
||||
|
||||
const FILTER_TEXT_KEY = 'FILTER_TEXT';
|
||||
const FILTER_OPTION_KEY = 'FILTER_OPTION';
|
||||
|
||||
interface Props {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const FilterProvider: React.FC<Props> = ({ children }: Props) => {
|
||||
const [filterText, setFilterTextState] = useState<string>(
|
||||
() => localStorage.getItem(FILTER_TEXT_KEY) ?? ''
|
||||
);
|
||||
const [selectedOption, setSelectedOptionState] = useState<string>(
|
||||
() => localStorage.getItem(FILTER_OPTION_KEY) ?? 'everything'
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem(FILTER_TEXT_KEY, filterText);
|
||||
}, [filterText]);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem(FILTER_OPTION_KEY, selectedOption);
|
||||
}, [selectedOption]);
|
||||
|
||||
const setFilterText = (text: string): void => {
|
||||
setFilterTextState(text);
|
||||
};
|
||||
|
||||
const setSelectedOption = (option: string): void => {
|
||||
setSelectedOptionState(option);
|
||||
};
|
||||
|
||||
const contextValue: FilterContextData = useMemo(() => ({
|
||||
filterText,
|
||||
selectedOption,
|
||||
setFilterText,
|
||||
setSelectedOption
|
||||
}), [filterText, selectedOption]);
|
||||
|
||||
return (
|
||||
<FilterContext.Provider value={contextValue}>
|
||||
{children}
|
||||
</FilterContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default FilterProvider;
|
||||
Reference in New Issue
Block a user