π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat(calendar): add channel multi-select filter above the calendar
Gilad Resisi9bf96ebcaf26
diff --git a/apps/frontend/src/components/launches/calendar.context.tsx b/apps/frontend/src/components/launches/calendar.context.tsxindex 6aadce580..ab26d0f33 100644--- a/apps/frontend/src/components/launches/calendar.context.tsx+++ b/apps/frontend/src/components/launches/calendar.context.tsx@@ -84,6 +84,10 @@ export const CalendarContext = createContext({setListState: (state: ListStateFilter) => {/** empty **/},+ selectedChannels: null as string[] | null,+ setSelectedChannels: (channels: string[] | null) => {+ /** empty **/+ },});export interface Integrations {@@ -174,6 +178,10 @@ export const CalendarWeekProvider: FC<{? { startDate: initStartDate, endDate: initEndDate }: getDateRange(display);+ const [selectedChannels, setSelectedChannels] = useState<string[] | null>(+ null+ );+const [filters, setFilters] = useState({startDate: initialRange.startDate,endDate: initialRange.endDate,@@ -181,6 +189,10 @@ export const CalendarWeekProvider: FC<{display,});+ useEffect(() => {+ setSelectedChannels(null);+ }, [filters.customer]);+const params = useMemo(() => {return new URLSearchParams({display: filters.display,@@ -302,11 +314,22 @@ export const CalendarWeekProvider: FC<{[]);+ const filterByChannels = useCallback(+ (list: any[]) =>+ selectedChannels+ ? list.filter((p) => selectedChannels.includes(p.integration.id))+ : list,+ [selectedChannels]+ );+const posts = useMemo(() => calendarData?.posts || [], [calendarData?.posts]);const comments = useMemo(() => calendarData?.comments || [], [calendarData?.comments]);// List view data- const listPosts = useMemo(() => listData?.posts || [], [listData?.posts]);+ const listPosts = useMemo(+ () => filterByChannels(listData?.posts || []),+ [listData?.posts, filterByChannels]+ );const listTotal = listData?.total || 0;const listTotalPages = Math.ceil(listTotal / 100);@@ -348,7 +371,7 @@ export const CalendarWeekProvider: FC<{trendings,reloadCalendarView,...filters,- posts: calendarIsLoading ? [] : internalData,+ posts: calendarIsLoading ? [] : filterByChannels(internalData),loading,integrations,setFilters: setFiltersWrapper,@@ -363,6 +386,8 @@ export const CalendarWeekProvider: FC<{setListPage,listState,setListState,+ selectedChannels,+ setSelectedChannels,}}>{children}diff --git a/apps/frontend/src/components/launches/filters.tsx b/apps/frontend/src/components/launches/filters.tsxindex e0cf58ab7..78e6102dd 100644--- a/apps/frontend/src/components/launches/filters.tsx+++ b/apps/frontend/src/components/launches/filters.tsx@@ -5,6 +5,7 @@ import clsx from 'clsx';import dayjs from 'dayjs';import { useCallback } from 'react';import { SelectCustomer } from '@gitroom/frontend/components/launches/select.customer';+import { SelectChannels } from '@gitroom/frontend/components/launches/select.channels';import { useT } from '@gitroom/react/translation/get.transation.service.client';import i18next from 'i18next';import { newDayjs } from '@gitroom/frontend/components/layout/set.timezone';@@ -431,6 +432,7 @@ export const Filters = () => {onChange={(customer: string) => setCustomer(customer)}integrations={calendar.integrations}/>+ <SelectChannels />{!isListView && (<div className="flex flex-row p-[4px] border border-newTableBorder rounded-[8px] text-[14px] font-[500]"><divdiff --git a/apps/frontend/src/components/launches/select.channels.tsx b/apps/frontend/src/components/launches/select.channels.tsxnew file mode 100644index 000000000..b4c197806--- /dev/null+++ b/apps/frontend/src/components/launches/select.channels.tsx@@ -0,0 +1,109 @@+'use client';++import React, { FC, useCallback, useMemo, useState } from 'react';+import clsx from 'clsx';+import { useClickOutside } from '@mantine/hooks';+import { useCalendar } from '@gitroom/frontend/components/launches/calendar.context';+import { useT } from '@gitroom/react/translation/get.transation.service.client';+import { Checkbox } from '@gitroom/react/form/checkbox';+import { FilterIcon } from '@gitroom/frontend/components/ui/icons';++export const SelectChannels: FC = () => {+ const { integrations, customer, selectedChannels, setSelectedChannels } =+ useCalendar();+ const t = useT();+ const [pos, setPos] = useState<any>({});+ const [open, setOpen] = useState(false);+ const ref = useClickOutside(() => {+ if (open) {+ setOpen(false);+ }+ });++ const channels = useMemo(+ () =>+ integrations.filter((i) => !customer || i.customer?.id === customer),+ [integrations, customer]+ );++ const selectedIds = selectedChannels ?? channels.map((c) => c.id);+ const allSelected = channels.every((c) => selectedIds.includes(c.id));++ const openClose = useCallback(() => {+ if (open) {+ setOpen(false);+ return;+ }++ const { x, y, height } = ref.current?.getBoundingClientRect();+ setPos({ top: y + height, left: Math.min(x, window.innerWidth - 270) });+ setOpen(true);+ }, [open]);++ const toggleAll = useCallback(() => {+ setSelectedChannels(allSelected ? [] : null);+ }, [allSelected]);++ const toggle = useCallback(+ (id: string) => () => {+ const next = selectedIds.includes(id)+ ? selectedIds.filter((s) => s !== id)+ : [...selectedIds, id];+ setSelectedChannels(next.length === channels.length ? null : next);+ },+ [selectedIds, channels]+ );++ if (channels.length <= 1) {+ return null;+ }++ return (+ <div className="relative select-none z-[500]" ref={ref}>+ <div+ data-tooltip-id="tooltip"+ data-tooltip-content={t('select_channels_tooltip', 'Select Channels')}+ onClick={openClose}+ className={clsx(+ 'relative z-[20] cursor-pointer h-[42px] rounded-[8px] px-[12px] border flex items-center',+ open || !allSelected ? 'border-[#612BD3]' : 'border-newColColor'+ )}+ >+ <FilterIcon />+ </div>+ {open && (+ <div+ style={pos}+ className="flex flex-col fixed py-[12px] bg-newBgColorInner menu-shadow min-w-[250px] max-h-[320px] overflow-y-auto"+ >+ <div className="p-[12px] hover:bg-newBgColor text-[14px] font-[600] flex items-center">+ <Checkbox+ disableForm={true}+ checked={allSelected}+ onChange={toggleAll}+ label={t('select_all', 'Select all')}+ />+ </div>+ {channels.map((p) => (+ <div+ key={p.id}+ className="p-[12px] hover:bg-newBgColor text-[14px] font-[500] flex items-center gap-[10px]"+ >+ <Checkbox+ disableForm={true}+ checked={selectedIds.includes(p.id)}+ onChange={toggle(p.id)}+ />+ <img+ className="w-[24px] h-[24px] rounded-full"+ src={p.picture || '/no-picture.jpg'}+ alt=""+ />+ <div className="truncate">{p.name}</div>+ </div>+ ))}+ </div>+ )}+ </div>+ );+};diff --git a/apps/frontend/src/components/ui/icons/index.tsx b/apps/frontend/src/components/ui/icons/index.tsxindex 84a256ac2..83a1f6ef5 100644--- a/apps/frontend/src/components/ui/icons/index.tsx+++ b/apps/frontend/src/components/ui/icons/index.tsx@@ -391,6 +391,27 @@ export const UserIcon: FC<IconProps> = ({ size = 20, className, ...props }) => (</svg>);+// Filter Icon+export const FilterIcon: FC<IconProps> = ({ size = 20, className, ...props }) => (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ width={size}+ height={size}+ viewBox="0 0 20 20"+ fill="none"+ className={className}+ {...props}+ >+ <path+ d="M2.5 4.16667H17.5L11.6667 10.8333V15.8333L8.33333 14.1667V10.8333L2.5 4.16667Z"+ stroke="currentColor"+ strokeWidth="1.5"+ strokeLinecap="round"+ strokeLinejoin="round"+ />+ </svg>+);+// Expand Iconexport const ExpandIcon: FC<IconProps> = ({size = 24,