Skip to content

Conversation

@maiano
Copy link
Owner

@maiano maiano commented Jul 27, 2025

  1. Task: link
  2. Screen
Screenshot 2025-07-28 at 02 13 32 shot:
  1. Deploy: link
  2. Done 28.07.2025 / deadline 28.07.2025
  3. Score: 60 / 100
  • Custom hook to restore search query from LS - 20
  • Pagination is present in both URL and on the page - 20
  • Upon clicking, open details panel on the right side of the page: - 5
  • Use router outlet, left side of the page should continue displaying the list of results - 10
  • Initiate an additional API call, display a loader, and update the URL - 10
  • Details panel should be closed either on the "close" button click or on the main panel click - 10
  • About page is implemented with author information and a link to the RS School React course - 5
  • 404 is implemented - 5
  • New tests are added for the new functionality - 15

@maiano maiano requested a review from kosmodromm July 31, 2025 20:04
Copy link
Collaborator

@kosmodromm kosmodromm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Comment on lines +39 to +47
onKeyDown={
isClickable
? (e) => {
if (e.key === 'Enter' || e.key === ' ') {
onClick?.(id);
}
}
: undefined
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вынеси в handleKeyDown()

export class Card extends Component<CardProps> {
getValue(key: string, value: string): string {
export const Card = ({ character, onClick, variant = 'list' }: CardProps) => {
const { id, name, status, species, gender, image, origin, location } =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше сделать enum в character.ts для status, gender и variant. типа такого enum CharacterGender {
FEMALE = 'Female',
MALE = 'Male',
GENDERLESS = 'Genderless',
UNKNOWN = 'unknown',
}

type CardProps = {
character: Character;
onClick?: (id: number) => void;
variant?: 'list' | 'details';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

будет прозрачнее, если variant будет обязательный

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

да. конечно

element: <Navigate to={PATHS.CHARACTER} replace />,
},
{
path: '/character',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему не используются пути из paths.ts?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

пропустил, когда рефакторил

path: PATHS.NOT_FOUND,
element: <ErrorLayout />,
errorElement: <FallBack />,
children: [{ path: PATHS.NOT_FOUND, element: <NotFoundPage /> }],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем здесь дублирование пути?


export const useCharactersQuery = (query: string, page: number) =>
useQuery({
queryKey: ['characters', { query, page }],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вынести в QUERY_KEYS объект

Comment on lines +4 to +18
const get = (): T => {
try {
const item = localStorage.getItem(key);
if (item === null) return defaultValue;

if (typeof defaultValue === 'string') {
return item as T;
}
return JSON.parse(item) as T;
} catch {
return defaultValue;
}
};

const [value, setValue] = useState<T>(get);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сейчас get вызывается при каждом ререндере, нужно ли это?
можно поменять на const [value, setValue] = useState(() => get()); и тогда выхов get будет только при маунте

Comment on lines +3 to +32
export function useLocalStorage<T>(key: string, defaultValue: T) {
const get = (): T => {
try {
const item = localStorage.getItem(key);
if (item === null) return defaultValue;

if (typeof defaultValue === 'string') {
return item as T;
}
return JSON.parse(item) as T;
} catch {
return defaultValue;
}
};

const [value, setValue] = useState<T>(get);

const set = useCallback(
(value: T) => {
try {
if (typeof value === 'string') {
localStorage.setItem(key, value);
} else {
localStorage.setItem(key, JSON.stringify(value));
}
setValue(value);
} catch {}
},
[key],
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше всегда сериализовать/десериализовать JSON.stringify и JSON.parse. попробуй переделай. код станет проще и будет меньше потенциальных ошибок

Comment on lines +24 to +25
const searchQueryFromURL = searchParams.get('name') || '';
const pageFromURL = Number(searchParams.get('page') || 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почитай про ?? оператор. тут нужен он

componentDidMount(): void {
this.fetchCharacters(this.state.searchQuery);
}
const searchQuery = searchQueryFromURL || '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем? это уже делается в searchQueryFromURL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants