Skip to content

Commit

Permalink
Merge branch 'main' into css-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
EricPedley authored Oct 23, 2023
2 parents 9db17e1 + 570bf94 commit ec16298
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import AppStore from '$stores/AppStore';
import { isDarkMode, queryWebsoc, queryWebsocMultiple } from '$lib/helpers';
import Grades from '$lib/grades';
import analyticsEnum from '$lib/analytics';
import { openSnackbar } from '$actions/AppStoreActions';

function flattenSOCObject(SOCObject: WebsocAPIResponse): (WebsocSchool | WebsocDepartment | AACourse)[] {
const courseColors = AppStore.getAddedCourses().reduce((accumulator, { section }) => {
Expand Down Expand Up @@ -196,7 +197,9 @@ export function CourseRenderPane() {
setError(false);
setCourseData(flattenSOCObject(websocJsonResp));
} catch (error) {
console.error(error);
setError(true);
openSnackbar('error', 'We ran into an error while looking up class info');
} finally {
setLoading(false);
}
Expand Down
16 changes: 13 additions & 3 deletions apps/antalmanac/src/stores/ColumnStore.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -50,14 +51,23 @@ 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')
);
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<ColumnStore>((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));
Expand Down

0 comments on commit ec16298

Please sign in to comment.