From f1b4dc97edf83ea0730ae5c3f2b2856f1541d52f Mon Sep 17 00:00:00 2001 From: Minh Nguyen <64875104+MinhxNguyen7@users.noreply.github.com> Date: Thu, 19 Oct 2023 22:41:25 +0000 Subject: [PATCH] Consistently dosable gpa column on added tab --- apps/antalmanac/src/stores/ColumnStore.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/antalmanac/src/stores/ColumnStore.ts b/apps/antalmanac/src/stores/ColumnStore.ts index 78707c3ca..b16376a19 100644 --- a/apps/antalmanac/src/stores/ColumnStore.ts +++ b/apps/antalmanac/src/stores/ColumnStore.ts @@ -1,5 +1,6 @@ import { create } from 'zustand'; import analyticsEnum, { logAnalytics } from '$lib/analytics'; +import useTabStore from './TabStore'; /** * Search results are displayed in a tabular format. @@ -50,14 +51,24 @@ interface ColumnStore { setColumnEnabled: (column: SectionTableColumn, state: boolean) => void; } +// Don't enable GPA column if the user is on the Added tab +const enabledColumnsInitial = SECTION_TABLE_COLUMNS.map( + (col) => !(window.location.pathname.split('/').slice(1)[0] === 'added' && col === 'gpa') +); +console.log(window.location.pathname.split('/').slice(1)[0] === 'added') +const selectedColumnsInitial = SECTION_TABLE_COLUMNS.map(() => true); +const activeColumnsInitial = SECTION_TABLE_COLUMNS.filter( + (_, index) => enabledColumnsInitial[index] && selectedColumnsInitial[index] +); + /** * Store of columns that are currently being displayed in the search results. */ export const useColumnStore = create((set, get) => { return { - enabledColumns: SECTION_TABLE_COLUMNS.map(() => true), - selectedColumns: SECTION_TABLE_COLUMNS.map(() => true), - activeColumns: Array.from(SECTION_TABLE_COLUMNS), + enabledColumns: enabledColumnsInitial, + selectedColumns: selectedColumnsInitial, + activeColumns: activeColumnsInitial, setSelectedColumns: (columns: SectionTableColumn[]) => { set(() => { const selectedColumns = SECTION_TABLE_COLUMNS.map((column) => columns.includes(column));