Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(GameList): Fix multiple sessions expanding #1540

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ tech changes will usually be stripped from release notes for the public
- Moving composites to a different location could sometimes lead to errors on the client even though the moves were succesful serverside
- Select Tool:
- Snapping an existing shape point to some other point could be overriden with a snap to the grid
- Game Listing:
- Clicking on a session that shares a name with another session would foldout both

## [2024.3.1] - 2024-11-12

Expand Down
23 changes: 13 additions & 10 deletions client/src/dashboard/games/GameList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ const route = useRoute();
const router = useRouter();
const { t } = useI18n();

type RoomInfoWithId = RoomInfo & { id: number };

interface SessionState {
owned: RoomInfo[];
joined: RoomInfo[];
owned: RoomInfoWithId[];
joined: RoomInfoWithId[];
error: string;
focussed?: RoomInfo;
focussed?: RoomInfoWithId;
}

const state: SessionState = reactive({
Expand All @@ -37,7 +39,7 @@ watch(sort, () => {
sortData(state.joined);
});

function sortData(data: RoomInfo[]): void {
function sortData(data: RoomInfoWithId[]): void {
data.sort((a, b) => {
if (sort.value === "clock") {
if (a.last_played === null) return 1;
Expand All @@ -61,17 +63,18 @@ onMounted(async () => {
const response = await http.get("/api/rooms");
if (response.ok) {
const data = (await response.json()) as { owned: RoomInfo[]; joined: RoomInfo[] };
state.owned = data.owned;
state.joined = data.joined;
// Add an arbitrary id to each one to do some checks that survive sorting
state.owned = data.owned.map((r, i) => ({ ...r, id: i }));
state.joined = data.joined.map((r, i) => ({ ...r, id: -i - 1 }));
sortData(state.owned);
sortData(state.joined);
} else {
state.error = await getErrorReason(response);
}
});

function focus(session: RoomInfo): void {
if (state.focussed?.name === session.name) {
function focus(session: RoomInfoWithId): void {
if (state.focussed?.id === session.id) {
state.focussed = undefined;
} else {
state.focussed = session;
Expand Down Expand Up @@ -225,8 +228,8 @@ async function exportCampaign(): Promise<void> {
<div class="sessions">
<div
v-for="session of state.joined"
:key="session.creator + '-' + session.name"
:class="{ focus: state.focussed?.name === session.name }"
:key="session.id"
:class="{ focus: state.focussed?.id === session.id }"
@click="focus(session)"
>
<img
Expand Down