Skip to content

Commit

Permalink
fix: lints with library component
Browse files Browse the repository at this point in the history
  • Loading branch information
PThorpe92 committed Oct 17, 2024
1 parent 7be139e commit 37e2b48
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
12 changes: 6 additions & 6 deletions frontend/src/Components/LibraryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState } from 'react';
import VisibleHiddenToggle from './VisibleHiddenToggle';
import {
Library,
ServerResponse,
ServerResponseMany,
ToastProps,
ToastState,
UserRole
Expand All @@ -20,15 +20,15 @@ export default function LibraryCard({
}: {
library: Library;
setToast: React.Dispatch<React.SetStateAction<ToastProps>>;
mutate: KeyedMutator<ServerResponse<Library[]>>;
role: string;
mutate: KeyedMutator<ServerResponseMany<Library>>;
role: UserRole;
}) {
const [visible, setVisible] = useState<boolean>(library.visibility_status);

function changeVisibility(visibilityStatus: boolean) {
if (visibilityStatus == !visible) {
setVisible(visibilityStatus);
handleToggleVisibility();
void handleToggleVisibility();
}
}

Expand All @@ -39,7 +39,7 @@ export default function LibraryCard({
state: ToastState.success,
message: response.message
});
mutate();
await mutate();
} else {
setToast({
state: ToastState.error,
Expand Down Expand Up @@ -72,7 +72,7 @@ export default function LibraryCard({
<p className="body-small h-[40px] leading-5 line-clamp-2">
{library?.description}
</p>
{role == UserRole.Admin && (
{role === UserRole.Admin && (
<VisibleHiddenToggle
visible={visible}
changeVisibility={changeVisibility}
Expand Down
54 changes: 31 additions & 23 deletions frontend/src/Components/LibraryLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
FilterLibrariesAdmin,
Library,
OpenContentProvider,
ServerResponse,
ServerResponseMany,
Tab,
ToastProps,
UserRole
Expand All @@ -23,39 +23,46 @@ export default function LibaryLayout({
setToast?: React.Dispatch<React.SetStateAction<ToastProps>>;
studentView?: boolean;
}) {
const { user } = useAuth();
if (!user) {
return null;
}
const [searchTerm, setSearchTerm] = useState<string>('');
const allLibrariesTab: Tab = {
name: 'All',
value: 'all'
};
const [activeTab, setActiveTab] = useState<Tab>(allLibrariesTab);
const [filterLibraries, setFilterLibraries] = useState<FilterLibraries>(
const [filterLibraries, setFilterLibraries] = useState<string>(
FilterLibraries['All Libraries']
);
const [filterLibrariesAdmin, setFilterLibrariesAdmin] =
useState<FilterLibrariesAdmin>(FilterLibrariesAdmin['All Libraries']);
let role = useAuth().user.role;
const [filterLibrariesAdmin, setFilterLibrariesAdmin] = useState<string>(
FilterLibrariesAdmin['All Libraries']
);
let role = user.role;
if (studentView) {
role = UserRole.Student;
}

const { data: libraries, mutate: mutateLibraries } = useSWR<
ServerResponse<Library[]>
ServerResponseMany<Library>
>(
`/api/libraries?${role == UserRole.Admin ? filterLibrariesAdmin : filterLibraries}&search=${searchTerm}`
);
const { data: openContentProviders } =
useSWR<ServerResponse<OpenContentProvider[]>>('/api/open-content');
useSWR<ServerResponseMany<OpenContentProvider>>('/api/open-content');

const openContentTabs = useMemo(() => {
return [
allLibrariesTab,
...(openContentProviders?.data?.map((provider) => ({
name: provider.name,
value: provider.id
})) ?? [])
...(openContentProviders?.data?.map(
(provider: OpenContentProvider) => ({
name: provider.name,
value: provider.id
})
) ?? [])
];
}, [openContentProviders]); //eslint-disable-line
}, [openContentProviders]);

return (
<div className="pt-6 space-y-6">
Expand All @@ -73,26 +80,27 @@ export default function LibaryLayout({
<DropdownControl
label="Filter by"
enumType={FilterLibrariesAdmin}
callback={setFilterLibrariesAdmin}
setState={setFilterLibrariesAdmin}
/>
) : (
<DropdownControl
label="Filter by"
enumType={FilterLibraries}
callback={setFilterLibraries}
setState={setFilterLibraries}
/>
)}
</div>
<div className="grid grid-cols-4 gap-6">
{libraries?.data.map((library) => (
<LibraryCard
key={library.id}
library={library}
setToast={setToast}
mutate={mutateLibraries}
role={role}
/>
))}
{setToast &&
libraries?.data.map((library) => (
<LibraryCard
key={library.id}
library={library}
setToast={setToast}
mutate={mutateLibraries}
role={role}
/>
))}
</div>
</div>
);
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,6 @@ export interface Milestone {
}

export interface ProviderPlatform {
[key: string]:
| string
| number
| ProviderPlatformState
| ProviderPlatformType;
access_key: string;
account_id: string;
base_url: string;
Expand Down Expand Up @@ -621,6 +616,7 @@ export interface Library {
}

export interface OpenContentProvider {
id: number;
name: string;
url: string;
provider_platform_id: number | null;
Expand Down

0 comments on commit 37e2b48

Please sign in to comment.