Skip to content

Commit

Permalink
added users navigator support
Browse files Browse the repository at this point in the history
  • Loading branch information
Andcool-Systems committed Nov 25, 2024
1 parent d0ea660 commit f0f4af9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/app/styles/navigator.module.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-items: center;
gap: 8px;
Expand Down
19 changes: 15 additions & 4 deletions src/app/workshop/[id]/client_code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ export const rgbToHex = (r: number, g: number, b: number) => {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}

const generatePath = (external_id: string, referrer_str: string | null) => {
const generatePath = (
external_id: string,
referrer_str: string | null,
author: string | undefined
) => {
const names: { [key: string]: { name: string, url: string } } = {
workshop: { name: 'Мастерская', url: '/workshop' },
me: { name: 'Личный кабинет', url: '/me' },
Expand All @@ -79,8 +83,15 @@ const generatePath = (external_id: string, referrer_str: string | null) => {
if (!referrer || referrer === window.location.pathname) {
return default_path;
}
const result = referrer.split('/').slice(1).map(page => names[page]);
if (result.some(page => !page)) return default_path;

let result;
if (referrer.startsWith('/users') && !!author) {
const username = referrer.split('/').reverse()[0];
result = [{ name: author, url: `/users/${username}` }];
} else {
result = referrer.split('/').slice(1).map(page => names[page]);
if (result.some(page => !page)) return default_path;
}

return [...result, { name: external_id, url: `/workshop/${external_id}` }];
}
Expand Down Expand Up @@ -120,7 +131,7 @@ export default function Home({ data, referrer }: { data: Interfaces.Bandage, ref
}

useEffect(() => {
setNavPath(generatePath(data.external_id, referrer));
setNavPath(generatePath(data.external_id, referrer, data.author?.name));
client.current = new Client();
client.current.addEventListener('skin_changed', (event: { skin: string, cape: string }) => {
setSkin(event.skin);
Expand Down

0 comments on commit f0f4af9

Please sign in to comment.