-
+
+
diff --git a/src/Components/Map/hooks/useFilter.tsx b/src/Components/Map/hooks/useFilter.tsx
index cee13e13..f5b21e25 100644
--- a/src/Components/Map/hooks/useFilter.tsx
+++ b/src/Components/Map/hooks/useFilter.tsx
@@ -3,28 +3,32 @@ import * as React from "react";
import {Tag} from "../../../types";
type ActionType =
- | { type: "ADD"; tag: Tag }
- | { type: "REMOVE"; id: string }
- | { type: "RESET"};
+ | { type: "ADD_TAG"; tag: Tag }
+ | { type: "REMOVE_TAG"; id: string }
+ | { type: "RESET_TAGS"};
type UseFilterManagerResult = ReturnType;
const FilterContext = createContext({
filterTags: [],
+ searchPhrase: "",
addFilterTag: () => { },
removeFilterTag: () => { },
resetFilterTags: () => { },
+ setSearchPhrase: () => { },
});
function useFilterManager(initialTags: Tag[]): {
filterTags: Tag[];
+ searchPhrase: string;
addFilterTag: (tag: Tag) => void;
removeFilterTag: (id: string) => void;
resetFilterTags: () => void;
+ setSearchPhrase: (phrase: string) => void;
} {
- const [filterTags, dispatch] = useReducer((state: Tag[], action: ActionType) => {
+ const [filterTags, dispatchTags] = useReducer((state: Tag[], action: ActionType) => {
switch (action.type) {
- case "ADD":
+ case "ADD_TAG":
const exist = state.find((tag) =>
tag.id === action.tag.id ? true : false
);
@@ -33,40 +37,43 @@ function useFilterManager(initialTags: Tag[]): {
action.tag,
];
else return state;
- case "REMOVE":
+ case "REMOVE_TAG":
return state.filter(({ id }) => id !== action.id);
- case "RESET":
+ case "RESET_TAGS":
return initialTags;
default:
throw new Error();
}
}, initialTags);
-
+ const [searchPhrase, searchPhraseSet] = React.useState("");
const addFilterTag = (tag: Tag) => {
- dispatch({
- type: "ADD",
+ dispatchTags({
+ type: "ADD_TAG",
tag,
});
};
const removeFilterTag = useCallback((id: string) => {
- dispatch({
- type: "REMOVE",
+ dispatchTags({
+ type: "REMOVE_TAG",
id,
});
}, []);
const resetFilterTags = useCallback(() => {
- dispatch({
- type: "RESET",
+ dispatchTags({
+ type: "RESET_TAGS",
});
}, []);
+ const setSearchPhrase = useCallback((phrase:string) => {
+ searchPhraseSet(phrase)
+ }, []);
- return { filterTags, addFilterTag, removeFilterTag, resetFilterTags };
+ return { filterTags, addFilterTag, removeFilterTag, resetFilterTags, setSearchPhrase, searchPhrase };
}
export const FilterProvider: React.FunctionComponent<{
@@ -96,3 +103,13 @@ export const useResetFilterTags = (): UseFilterManagerResult["resetFilterTags"]
const { resetFilterTags } = useContext(FilterContext);
return resetFilterTags;
};
+
+export const useSearchPhrase = (): UseFilterManagerResult["searchPhrase"] => {
+ const { searchPhrase } = useContext(FilterContext);
+ return searchPhrase;
+};
+
+export const useSetSearchPhrase = (): UseFilterManagerResult["setSearchPhrase"] => {
+ const { setSearchPhrase } = useContext(FilterContext);
+ return setSearchPhrase;
+};
\ No newline at end of file
diff --git a/src/Components/Map/hooks/useItems.tsx b/src/Components/Map/hooks/useItems.tsx
index 5476fcec..d6ebfa9e 100644
--- a/src/Components/Map/hooks/useItems.tsx
+++ b/src/Components/Map/hooks/useItems.tsx
@@ -3,8 +3,9 @@ import * as React from "react";
import { Item, ItemsApi, LayerProps, Tag } from "../../../types";
import { toast } from "react-toastify";
import { useAddLayer } from "./useLayers";
-import { useTags } from "./useTags";
+import { useAddTag, useTags } from "./useTags";
import { hashTagRegex } from "../../../Utils/HashTagRegex";
+import { randomColor } from "../../../Utils/RandomColor";
type ActionType =
@@ -39,6 +40,7 @@ function useItemsManager(initialItems: Item[]): {
const addLayer = useAddLayer();
const tags = useTags();
+ const addTag = useAddTag();
const [items, dispatch] = useReducer((state: Item[], action: ActionType) => {
switch (action.type) {
@@ -67,7 +69,9 @@ function useItemsManager(initialItems: Item[]): {
const itemTagStrings = item.text.toLocaleLowerCase().match(hashTagRegex);
const itemTags: Tag[] = [];
itemTagStrings?.map(tag => {
- if (tags.find(t => t.id === tag.slice(1))) { itemTags.push(tags.find(t => t.id === tag.slice(1))!) }
+ if (tags.find(t => t.id === tag.slice(1))) {
+ itemTags.push(tags.find(t => t.id === tag.slice(1))!)
+ }
})
return { ...item, tags: itemTags }
})
@@ -97,7 +101,7 @@ function useItemsManager(initialItems: Item[]): {
const setItemsData = useCallback((layer: LayerProps) => {
layer.data?.map(item => {
- dispatch({ type: "ADD", item: { ...item, layer: layer } })
+ dispatch({ type: "ADD", item: { ...item, layer: layer } });
})
dispatch({ type: "ADD_TAGS" })
}, []);
diff --git a/src/index.css b/src/index.css
index 1f795086..762e2fa5 100644
--- a/src/index.css
+++ b/src/index.css
@@ -16,4 +16,15 @@
.tw-modal-box {
max-height: calc(100vh - 2em);
+}
+
+.Toastify__toast {
+ border-radius: 1rem;
+ --tw-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
+ --tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color);
+ box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
+ margin-left: 1rem;
+ margin-right: 1rem;
+ margin-bottom: 1rem;
+
}
\ No newline at end of file