Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
P-man2976 committed Nov 26, 2024
1 parent 646da6b commit 813700a
Show file tree
Hide file tree
Showing 23 changed files with 695 additions and 192 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@typescript-eslint/no-use-before-define": "off",
"no-underscore-dangle": "off",
"no-console": "warn",
"no-nested-ternary": "warn",
"no-nested-ternary": "off",
"import/extensions": "off",
"import/prefer-default-export": "off"
}
Expand Down
10 changes: 10 additions & 0 deletions src/@types/transit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ interface DiaInfo {
description: string;
updatedAt: string;
}

interface TransitTimetable {
starting: string;
destination: string;
stations: {
name: string;
arriveAt?: string;
departAt?: string;
}[];
}
2 changes: 1 addition & 1 deletion src/components/calendar/AddEventDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ const AddEventDrawer = React.memo(
}),
}}
options={searchRes}
loadOptions={(value) => searchTags(value)}
loadOptions={(value) => searchTags(value || '*')}
isLoading={searchPending}
value={tags}
onChange={(e: readonly Tag[]) => setTags(e as Tag[])}
Expand Down
8 changes: 0 additions & 8 deletions src/components/calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,13 @@ const Calendar = React.memo(
>
<Text
color={
/* eslint-disable no-nested-ternary */
isSameMonth(date, day)
? isSaturday(day)
? 'blue.400'
: isSunday(day)
? 'red.400'
: 'title'
: 'description'
/* eslint-enable no-nested-ternary */
}
textStyle="title"
fontSize="xs"
Expand Down Expand Up @@ -141,37 +139,31 @@ const Calendar = React.memo(
px={{ base: 0, md: '2px' }}
py={{ base: 0, md: '1px' }}
bg={
/* eslint-disable no-nested-ternary */
event.external
? event.isAllDay
? 'green.400'
: 'green.50'
: event.isAllDay
? 'blue.400'
: 'blue.50'
/* eslint-enable no-nested-ternary */
}
color={
/* eslint-disable no-nested-ternary */
event.external
? event.isAllDay
? 'white'
: 'green.400'
: event.isAllDay
? 'white'
: 'blue.400'
/* eslint-enable no-nested-ternary */
}
_hover={{
/* eslint-disable no-nested-ternary */
bg: event.external
? event.isAllDay
? 'green.500'
: 'green.100'
: event.isAllDay
? 'blue.500'
: 'blue.100',
/* eslint-enable no-nested-ternary */
}}
transition="all .2s ease"
as={RouterLink}
Expand Down
1 change: 0 additions & 1 deletion src/components/cards/Timetable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ function Timetable() {
) : (
<Error type="userScheduleNotSet" />
)}
{/* eslint-enable no-nested-ternary */}
</VStack>
<DivisionEditor date={date} isOpen={isOpen} onClose={onClose} />
</>
Expand Down
101 changes: 14 additions & 87 deletions src/components/cards/Transit.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
import React from 'react';
import {
Box,
Center,
Collapse,
Heading,
HStack,
Icon,
LinkBox,
Skeleton,
Spacer,
StackDivider,
Text,
useDisclosure,
VStack,
} from '@chakra-ui/react';
import { Link as RouterLink } from 'react-router-dom';
import { TbChevronRight } from 'react-icons/tb';
import { differenceInMinutes, differenceInSeconds, format } from 'date-fns/esm';
import { useSeconds } from 'use-seconds';
import DiaStatus from '../transit/DiaStatus';
import { useTransit } from '@/services/transit';

const formatTimeDifference = (dateLeft: Date, dateRight: Date) => {
const diffSec = differenceInSeconds(dateLeft, dateRight);
const diffMin = differenceInMinutes(dateLeft, dateRight);

return `${diffMin}:${Math.abs(diffSec - 60 * diffMin)
.toString()
.padStart(2, '0')}`;
};
import { useDiainfo } from '@/services/transit';
import StatusAlert from '../transit/StatusAlert';
import Error from './Error';

export default function Transit() {
const { data, isPending } = useTransit();
// const { data, isPending } = useTransit();
const { data: diaInfo, status, error } = useDiainfo();

return (
<VStack spacing={4} w="100%" align="flex-start">
Expand All @@ -48,85 +34,26 @@ export default function Transit() {
</HStack>
</LinkBox>
<VStack p={2} align="flex-start" w="100%">
<DiaStatus />
{status === 'error' ? (
<Error error={error} />
) : (
<Skeleton w="full" rounded="xl" isLoaded={status !== 'pending'}>
<StatusAlert lines={diaInfo} />
</Skeleton>
)}
<Text textStyle="title" fontSize="lg">
長野方面
</Text>
<Skeleton w="100%" rounded="xl" isLoaded={!isPending}>
{/* <Skeleton w="100%" rounded="xl" isLoaded={!isPending}>
<TransitButton transits={data?.nagano} />
</Skeleton>
<Text textStyle="title" fontSize="lg">
上田方面
</Text>
<Skeleton w="100%" rounded="xl" isLoaded={!isPending}>
<TransitButton transits={data?.ueda} />
</Skeleton>
</Skeleton> */}
</VStack>
</VStack>
);
}

const TransitButton = React.memo(
({ transits }: { transits?: TransitInfo[] }) => {
const { isOpen, onToggle } = useDisclosure();
const [date] = useSeconds();
const upcomingTransit = transits?.filter(
(transit) => new Date(transit.leaveAt).valueOf() > Date.now(),
);

return upcomingTransit?.length ? (
<VStack w="100%" spacing={0} rounded="xl" layerStyle="button">
<HStack w="100%" p={2} onClick={onToggle}>
<StackDivider borderWidth={2} borderColor="blue.400" rounded="full" />
<VStack spacing={0} align="flex-start">
<Text textStyle="title" fontSize="xl">
{format(new Date(upcomingTransit[0].leaveAt), 'HH:mm')}
</Text>
<Text textStyle="description">
{upcomingTransit[0].destination}
</Text>
</VStack>
<Spacer />
<Text textStyle="title" fontSize="3xl">
{formatTimeDifference(new Date(upcomingTransit[0].leaveAt), date)}
</Text>
</HStack>
<Box w="100%">
<Collapse in={isOpen}>
{upcomingTransit.slice(1).map((transit) => (
<TransitQueue
key={transit.leaveAt}
date={date}
transit={transit}
/>
))}
</Collapse>
</Box>
</VStack>
) : (
<Center w="100%" py={2}>
<Text textStyle="description" fontWeight="bold">
次の電車はありません
</Text>
</Center>
);
},
);

const TransitQueue = React.memo(
({ date, transit }: { date: Date; transit: TransitInfo }) => (
<HStack w="100%" p={2} pl={6}>
<StackDivider borderWidth={1} borderColor="blue.400" rounded="full" />
<VStack spacing={0} align="flex-start">
<Text fontSize="md">{format(new Date(transit.leaveAt), 'HH:mm')}</Text>
<Text textStyle="description" fontSize="2xs">
{transit.destination}
</Text>
</VStack>
<Spacer />
<Text textStyle="title">
{formatTimeDifference(new Date(transit.leaveAt), date)}
</Text>
</HStack>
),
);
5 changes: 0 additions & 5 deletions src/components/classmatch/MetaEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ function MetaEditor({
<Text textStyle="description" fontWeight="bold" fontSize="xs">
試合結果
</Text>
{/* eslint-disable no-nested-ternary */}
<Box w="full" pos="relative">
{!isParticipantsEditable && (
<Center
Expand Down Expand Up @@ -238,13 +237,11 @@ function ClassSelectMenu({
rightIcon={<Icon as={TbChevronDown} />}
textStyle={currentClass?.from ? 'title' : 'description'}
>
{/* eslint-disable no-nested-ternary */}
{currentClass?.from
? currentClass.type === 'teacher'
? '職員'
: `${currentClass.grade}-${currentClass.class}`
: 'クラス'}
{/* eslint-enable no-nested-ternary */}
</MenuButton>
<Box>
<MenuList rounded="xl" shadow="xl">
Expand Down Expand Up @@ -300,15 +297,13 @@ function ClassSelectMenuItem({
})
}
>
{/* eslint-disable no-nested-ternary */}
{tournament.class
? tournament.class.type === 'teacher'
? '職員'
: `${tournament.class.grade}-${tournament.class.class}`
: winner.type === 'teacher'
? '職員'
: `${winner.grade}-${winner.class}`}
{/* eslint-enable no-nested-ternary */}
</MenuItem>
);
}
Expand Down
11 changes: 7 additions & 4 deletions src/components/common/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { AnimatePresence } from 'framer-motion';
import { MotionCenter } from '../motion';

const tips = [
'Classroomの読み込みは時間がかかる場合があります\nその間はTipsをお楽しみください',
'Classroomの読み込みは時間がかかる場合があります',
'Hatoはオープンソースです。ぜひ貢献してください!',
'Hatoは多くの方の協力で成り立っています\n皆さんの協力に感謝します',
'時間割は有志の方が手動で設定しています\nあなたも協力してみませんか?',
'はとボードの新着投稿は5分以内に反映されます',
'年間行事予定は生徒の協力により反映されています\nぜひ協力をお願いします',
// 'はとボードの新着投稿は5分以内に反映されます',
'交通情報は5分ごとに更新しています',
'時刻表では各駅停車時刻・行先と接続を確認できます',
'Classroomの課題と資料はブックマークできます',
'3棟前モニター用の理科室割表示サイトを作ったのですが却下されました\nhttps://srtable-viewer.vercel.app/',
];

const Loading = React.memo(
Expand All @@ -21,7 +24,7 @@ const Loading = React.memo(
}: { withTips?: boolean; initialTip?: number } & SpinnerProps) => {
const [tipsShowed, setTipsShowed] = useState(false);
const [tip, setTip] = useState(
tips[initialTip ?? Math.floor(Math.random() * tips.length)]
tips[initialTip ?? Math.floor(Math.random() * tips.length)],
);

useEffect(() => {
Expand Down Expand Up @@ -53,7 +56,7 @@ const Loading = React.memo(
)}
</VStack>
);
}
},
);

export const GlobalLoading = React.memo(() => (
Expand Down
11 changes: 11 additions & 0 deletions src/components/layout/SharePopover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Popover, PopoverContent, PopoverTrigger } from '@chakra-ui/react';
import { ReactNode } from 'react';

export default function SharePopover({ children }: { children: ReactNode }) {
return (
<Popover>
<PopoverTrigger>{children}</PopoverTrigger>
<PopoverContent />
</Popover>
);
}
2 changes: 0 additions & 2 deletions src/components/library/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ const SearchResult = React.memo(
}) => (
<Box w="100%" h="100%">
<Collapse in={!!result || isLoading}>
{/* eslint-disable no-nested-ternary */}
{isLoading ? (
<Loading />
) : result?.count ? (
Expand Down Expand Up @@ -178,7 +177,6 @@ const SearchResult = React.memo(
</Text>
</VStack>
)}
{/* eslint-enable no-nested-ternary */}
</Collapse>
</Box>
),
Expand Down
Loading

0 comments on commit 813700a

Please sign in to comment.