Skip to content

Add star button to activity description #132

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions src/components/ActivityButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { Class, LockOption, SectionLockOption, Sections } from "../lib/class";
import { WEEKDAY_STRINGS, TIMESLOT_STRINGS, Slot } from "../lib/dates";
import { State } from "../lib/state";
import { LuCheck as CheckIcon, LuX as CloseIcon } from "react-icons/lu";
import { StarButton } from "./ClassTable";

/**
* A button that toggles the active value, and is outlined if active, solid
Expand Down Expand Up @@ -240,6 +241,14 @@ export function ClassButtons(props: { cls: Class; state: State }) {
return (
<Flex direction="column" gap={2}>
<ButtonGroup wrap="wrap">
<StarButton
cls={cls}
state={state}
onStarToggle={() => {
const event = new CustomEvent("refreshStarCells");
window.dispatchEvent(event);
}}
/>
<Button onClick={() => state.toggleActivity(cls)}>
{isSelected ? "Remove class" : "Add class"}
</Button>
Expand Down
13 changes: 12 additions & 1 deletion src/components/ClassTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ function ClassFlags(props: {
);
}

const StarButton = ({
export const StarButton = ({
cls,
state,
onStarToggle,
Expand Down Expand Up @@ -416,6 +416,17 @@ export function ClassTable(props: {
const { classes, state } = props;
const gridRef = useRef<AgGridReact>(null);

useEffect(() => {
const refreshCells = () => {
gridRef.current?.api?.refreshCells({
force: true,
columns: ["number"],
});
};
window.addEventListener("refreshStarCells", refreshCells);
return () => window.removeEventListener("refreshStarCells", refreshCells);
Comment on lines +420 to +427
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: this is very cursed but i'm not sure what else can be done about it

maybe just add a comment on both sides...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could pass gridRef up into App and back down into ClassTable?

}, []);

// Setup table columns
const columnDefs: ColDef<ClassTableRow, string>[] = useMemo(() => {
const initialSort = "asc" as const;
Expand Down