Skip to content

Commit

Permalink
Rename group route id + refactor to account for it
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis committed Dec 12, 2024
1 parent 39aab66 commit 1d97615
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 54 deletions.
4 changes: 2 additions & 2 deletions frontend/components/card/CardConnect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ const props = defineProps<{
const { userIsSignedIn } = useUser();
const paramsId = useRoute().params.id;
const paramsIdGroup = useRoute().params.groupId;
const paramsGroupId = useRoute().params.groupId;
const id = typeof paramsId === "string" ? paramsId : undefined;
const idGroup = typeof paramsIdGroup === "string" ? paramsIdGroup : undefined;
const idGroup = typeof paramsGroupId === "string" ? paramsGroupId : undefined;
const organizationStore = useOrganizationStore();
const groupStore = useGroupStore();
Expand Down
5 changes: 1 addition & 4 deletions frontend/components/feed/Feed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
v-if="feedItemUrls && feedItemNames"
class="mt-3 flex items-center justify-start space-x-3"
>
<div
v-for="(url, index) in feedItemUrls.slice(0, numberOfFeedItems)"
class="w-full"
>
<div v-for="(url, index) in feedItemUrls" class="w-full">
<FeedItem :name="feedItemNames[index]" :url="url" />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/feed/FeedItem.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<NuxtLink
:to="localePath(url)"
:to="localePath(item.url)"
:aria-label="$t('components._global.navigate_to_group_aria_label')"
>
<div
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/menu/mobile/MenuMobileNavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<script setup lang="ts">
const isActive = (routeUrl: string) => {
return isRouteActive(routeUrl);
return isTopLevelRouteActive(routeUrl);
};
const getSelectorId = (label: string) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/modal/ModalSharePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ const getCurrentUrl = () => {
if (props.organization) {
return `${BASE_FRONTEND_URL}/organizations/${props.organization.id}`;
} else if (props.group) {
return `${BASE_FRONTEND_URL}/organizations/${props.group.organization.id}/groups/${props.group.id}`;
return `${BASE_FRONTEND_URL}/organizations/${props.group.orgId}/groups/${props.group.id}`;
} else if (props.event) {
return `${BASE_FRONTEND_URL}/events/${props.event.id}`;
} else if (props.resource) {
Expand Down
26 changes: 10 additions & 16 deletions frontend/components/page/PageBreadcrumbs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ const { locales } = useI18n();
const localePath = useLocalePath();
const paramsId = useRoute().params.id;
const paramsIdGroup = useRoute().params.groupId;
const paramsGroupId = useRoute().params.groupid;
const id = typeof paramsId === "string" ? paramsId : undefined;
const idGroup = typeof paramsIdGroup === "string" ? paramsIdGroup : undefined;
const groupId = typeof paramsGroupId === "string" ? paramsGroupId : undefined;
const organizationStore = useOrganizationStore();
const groupStore = useGroupStore();
Expand All @@ -96,35 +96,29 @@ const eventStore = useEventStore();
let organization: Organization;
let group: Group;
let event: Event;
const organizationRegex =
/^(http:\/\/localhost:\d+|https?:\/\/[\w.-]+)(\/[a-z]{2})?\/organizations\/[0-9a-fA-F-]+(\/about)?$/;
const groupRegex =
const groupRegex =
/^(http:\/\/localhost:\d+|https?:\/\/[\w.-]+)(\/[a-z]{2})?\/organizations\/[0-9a-fA-F-]+\/groups\/([0-9a-fA-F-]+)(\/about)?$/;
const eventRegex =
const eventRegex =
/^(http:\/\/localhost:\d+|https?:\/\/[\w.-]+)(\/[a-z]{2})?\/events\/([0-9a-fA-F-]+)(\/about)?$/;
if (organizationRegex.test(url)) {
pageType = "organization";
await organizationStore.fetchById(id);
organization = organizationStore.organization;
} else if (groupRegex.test(url)) {
pageType = "group";
const match = url.match(groupRegex);
const groupId = match ? match[4] : null;
if (groupId) {
await groupStore.fetchById(groupId);
group = groupStore.group;
}
await groupStore.fetchById(groupId);
group = groupStore.group;
} else if (eventRegex.test(url)) {
pageType = "event";
const match = url.match(eventRegex);
const eventId = match ? match[3] : null;
if (eventId) {
await eventStore.fetchById(eventId);
event = eventStore.event;
}
await eventStore.fetchById(id);
event = eventStore.event;
}
const breadcrumbs = ref<string[]>([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<script setup lang="ts">
const isActive = (routeUrl: string) => {
return isRouteActive(routeUrl);
return isTopLevelRouteActive(routeUrl);
};
const getSelectorId = (label: string) => {
Expand Down
3 changes: 2 additions & 1 deletion frontend/i18n/check/i18n_check_key_identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def path_to_valid_key(p):
"""
Converts a path to a valid key with period separators and all words being snake case.
Note: [id] is removed in this step as it doesn't add anything to keys.
Note: [id] and [group_id] are removed in this step as it doesn't add anything to keys.
"""
# Insert underscores between words, but only if the word is preceded by a lowercase letter and followed by an uppercase letter (i.e. except for abbreviations).
valid_key = ""
Expand All @@ -101,6 +101,7 @@ def path_to_valid_key(p):
.replace("._", ".")
.replace("-", "_")
.replace(".[id]", "")
.replace(".[group_id]", "")
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Head>
<Title>{{ group.name }}</Title>
</Head>
<HeaderAppPage :group="group">
<HeaderAppPage pageType="group">
<div class="flex space-x-2 pb-3 lg:space-x-3 lg:pb-4">
<BtnRouteExternal
v-if="group.getInvolvedUrl"
Expand Down Expand Up @@ -85,21 +85,19 @@

<script setup lang="ts">
import { BreakpointMap } from "~/types/breakpoint-map";
import type { Group } from "~/types/entities/group";
import { IconMap } from "~/types/icon-map";
import type { Group } from "~/types/entities/group";
import { getGroupSubPages } from "~/utils/groupSubPages";
const aboveLargeBP = useBreakpoint("lg");
const { id } = useRoute().params;
const paramsGroupId = useRoute().params.groupid;
const groupId = typeof paramsGroupId === "string" ? paramsGroupId : undefined;
const [resOrg] = await Promise.all([
useAsyncData(
async () => await fetchWithoutToken(`/entities/groups/${id}`, {})
),
]);
const groupStore = useGroupStore();
await groupStore.fetchById(groupId);
const group = resOrg.data as unknown as Group;
const group: Group = groupStore.group;
const groupSubPages = getGroupSubPages();
Expand Down
35 changes: 35 additions & 0 deletions frontend/pages/organizations/[id]/groups/[group-id]/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<script setup lang="ts">
import { BreakpointMap } from "~/types/breakpoint-map";
import { onMounted } from "vue";
const { id } = useRoute().params;
const { groupid } = useRoute().params;
const windowWidth = ref(window.innerWidth);
const handleResize = () => {
windowWidth.value = window.innerWidth;
if (windowWidth.value > BreakpointMap.SMALL) {
const { locale } = useI18n();
const currentRoute = useRoute();
if (
currentRoute.path !==
`/${locale.value}/organizations/${id}/groups/${groupid}/about` ||
currentRoute.path === `/${locale.value}/organizations/${id}/`
) {
navigateTo(
`/${locale.value}/organizations/${id}/groups/${groupid}/about`
);
}
}
};
onMounted(() => {
// Add event listener to handle resizing.
window.addEventListener("resize", handleResize);
// Verify that the user is on a mobile device.
handleResize();
});
</script>
18 changes: 0 additions & 18 deletions frontend/pages/organizations/[id]/groups/[id]/index.vue

This file was deleted.

19 changes: 19 additions & 0 deletions frontend/utils/routeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ export function isRouteActive(routePath: string): boolean {
);
}

export function isTopLevelRouteActive(routePath: string): boolean {
const route = useRoute();

const currentPath = normalizePath(route.path);
const targetPath = normalizePath(routePath);

let currentSegments = currentPath.split("/");
let targetSegments = targetPath.split("/");

// Remove locale segments from both current and target paths.
currentSegments = removeLocaleSegment(currentSegments);
targetSegments = removeLocaleSegment(targetSegments);

console.log(`currentSegments: ${currentSegments}`);
console.log(`targetSegments: ${targetSegments}`);

return currentSegments[0] === targetSegments[0];
}

export function isCurrentRoutePathSubpageOf(path: string, routeName: string) {
// The first split is to remove the localization path.
const segments = routeName.split("___")[0].split(path + "-");
Expand Down

0 comments on commit 1d97615

Please sign in to comment.