Skip to content

Commit 8651e6b

Browse files
Johannes HötterLennartSchmidtKern
andauthored
Cognition apps rework (#9)
* added console log hook for state * pre websocket-auth error * minor change --------- Co-authored-by: Lennart Schmidt <lennart.schmidt@kern.ai>
1 parent 62d3da4 commit 8651e6b

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

components/Dropdown.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { Fragment, useEffect, useRef, useState } from 'react'
22
import { Menu, Transition } from '@headlessui/react'
3-
import { ChevronDownIcon } from '@heroicons/react/20/solid'
43
import { DropdownProps } from '../types/dropdown';
54
import { combineClassNames } from '../../javascript-functions/general';
65
import { SELECT_ALL, checkDropdownProps, prepareDropdownOptionsToArray, setOptionsWithSearchBar } from '../helpers/dropdown-helper';
76
import { Tooltip } from '@nextui-org/react';
8-
import { IconTrashXFilled } from '@tabler/icons-react';
7+
import { IconChevronDown, IconTrashXFilled } from '@tabler/icons-react';
98
import useOnClickOutside from '../hooks/useHooks/useOnClickOutside';
109

1110
export default function Dropdown(props: DropdownProps) {
@@ -107,7 +106,7 @@ export default function Dropdown(props: DropdownProps) {
107106

108107
className="h-9 w-full text-sm border-gray-300 rounded-md placeholder-italic border text-gray-900 pr-8 pl-4 truncate placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-300 focus:ring-offset-2 focus:ring-offset-gray-100"
109108
placeholder="Type to search..." />
110-
<ChevronDownIcon
109+
<IconChevronDown
111110
className="h-5 w-5 absolute right-0 mr-3 -mt-7"
112111
aria-hidden="true"
113112
/>
@@ -116,7 +115,7 @@ export default function Dropdown(props: DropdownProps) {
116115
focus:ring-gray-300 focus:ring-offset-2 focus:ring-offset-gray-100 disabled:opacity-50 disabled:cursor-not-allowed ${props.buttonClasses ?? ''}`}
117116
disabled={isDisabled && !props.hasCheckboxes}>
118117
{props.buttonName}
119-
<ChevronDownIcon
118+
<IconChevronDown
120119
className="-mr-1 ml-2 h-5 w-5"
121120
aria-hidden="true"
122121
/>

components/InfoButton.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { combineClassNames } from "@/submodules/javascript-functions/general";
22
import { useDefaults } from "@/submodules/react-components/hooks/useDefaults";
33
import { IconInfoCircle } from "@tabler/icons-react";
44
import { Dispatch, Fragment, SetStateAction, useEffect, useRef, useState } from "react";
5-
import { InformationCircleIcon } from "@heroicons/react/20/solid";
65
import useOnClickOutside from "@/submodules/react-components/hooks/useHooks/useOnClickOutside";
76
import { Transition } from "@headlessui/react";
87
import { INFO_BUTTON_DEFAULT_VALUES, InfoButtonConfig, InfoButtonProps } from "../types/infoButton";
@@ -45,7 +44,7 @@ export function InfoButton(_props: InfoButtonProps) {
4544

4645
if (!config) return null;
4746

48-
return <>
47+
return (
4948
<div className={combineClassNames("relative w-fit p-1", config.cursorClass)} onClick={props.access == 'click' ? config.showInfo : undefined} onMouseEnter={props.access == 'hover' ? config.showInfo : undefined} onMouseLeave={props.access == 'hover' ? config.hideInfo : undefined}>
5049
<IconInfoCircle size={config.size} className={props.infoButtonColorClass} />
5150
{props.display == "absoluteDiv" ? <RenderDiv
@@ -57,13 +56,13 @@ export function InfoButton(_props: InfoButtonProps) {
5756
onMouseLeave={config.hideInfo}
5857
zIndexClass={props.divZIndexClass} /> : null}
5958
</div>
60-
</>
59+
)
6160
}
6261

6362
function RenderDiv({ positionClass, open, content, access, onMouseEnter, onMouseLeave, zIndexClass }: { positionClass: string, open: boolean, content: string | JSX.Element, access: string, onMouseEnter: () => void, onMouseLeave: () => void, zIndexClass: string }) {
6463
const ref = useRef(null);
6564
useOnClickOutside(ref, onMouseLeave);
66-
return (<>
65+
return (
6766
<Transition.Root show={open} as={Fragment} >
6867
<Transition.Child
6968
as={Fragment}
@@ -78,13 +77,12 @@ function RenderDiv({ positionClass, open, content, access, onMouseEnter, onMouse
7877
{typeof content == "string" ?
7978
<div className="flex items-center gap-x-2">
8079
<div className="flex-shrink-0">
81-
<InformationCircleIcon className="h-5 w-5 text-blue-400" aria-hidden="true" />
80+
<IconInfoCircle className="h-5 w-5 text-blue-400" aria-hidden="true" />
8281
</div>
8382
<p className="text-sm text-blue-700 w-max max-w-sm">{content}</p>
8483
</div> : content}
8584
</div>
8685
</Transition.Child>
8786
</Transition.Root>
88-
</>
8987
)
9088
}

hooks/useLocalStorage.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ type ItemWithExpiration<T> = {
66
};
77

88
export function readItemGroupFromLocalStorage(group: string): any {
9-
const itemGroupString = localStorage.getItem(group);
10-
if (itemGroupString) {
11-
return JSON.parse(itemGroupString);
9+
if (typeof localStorage !== 'undefined') {
10+
const itemGroupString = localStorage.getItem(group);
11+
if (itemGroupString) {
12+
return JSON.parse(itemGroupString);
13+
}
1214
}
1315
return {};
1416
}
@@ -28,7 +30,9 @@ export function useLocalStorage<T>(
2830
if (item.expiration && Date.now() > item.expiration) {
2931
// Item has expired, remove it
3032
delete itemGroup[key];
31-
localStorage.setItem(group, JSON.stringify(itemGroup));
33+
if (typeof localStorage !== 'undefined') {
34+
localStorage.setItem(group, JSON.stringify(itemGroup));
35+
}
3236
} else {
3337
return item.value;
3438
}
@@ -45,7 +49,9 @@ export function useLocalStorage<T>(
4549
expiration: timeoutSeconds ? Date.now() + timeoutSeconds * 1000 : null,
4650
};
4751
itemGroup[key] = item;
48-
localStorage.setItem(group, JSON.stringify(itemGroup));
52+
if (typeof localStorage !== 'undefined') {
53+
localStorage.setItem(group, JSON.stringify(itemGroup));
54+
}
4955
}, [state]);
5056

5157
return [state, setState];

0 commit comments

Comments
 (0)