Skip to content
Draft
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
97 changes: 97 additions & 0 deletions lib/nivoTheme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
const nivoTheme = {
background: "transparent",
textColor: "var(--theme-ui-colors-text)",
fontSize: 11,
axis: {
domain: {
line: {
stroke: "#777777",
strokeWidth: 1,
},
},
legend: {
text: {
fontSize: 12,
fill: "var(--theme-ui-colors-text)",
},
},
ticks: {
line: {
stroke: "#777777",
strokeWidth: 1,
},
text: {
fontSize: 11,
fill: "var(--theme-ui-colors-text)",
},
},
},
grid: {
line: {
stroke: "#dddddd",
strokeWidth: 1,
},
},
legends: {
title: {
text: {
fontSize: 11,
fill: "var(--theme-ui-colors-text)",
},
},
text: {
fontSize: 11,
fill: "var(--theme-ui-colors-text)",
},
ticks: {
line: {},
text: {
fontSize: 10,
fill: "var(--theme-ui-colors-text)",
},
},
},
annotations: {
text: {
fontSize: 13,
fill: "var(--theme-ui-colors-text)",
outlineWidth: 2,
outlineColor: "var(--theme-ui-colors-background)",
outlineOpacity: 1,
},
link: {
stroke: "var(--theme-ui-colors-text)",
strokeWidth: 1,
outlineWidth: 2,
outlineColor: "var(--theme-ui-colors-background)",
outlineOpacity: 1,
},
outline: {
stroke: "var(--theme-ui-colors-text)",
strokeWidth: 2,
outlineWidth: 2,
outlineColor: "var(--theme-ui-colors-background)",
outlineOpacity: 1,
},
symbol: {
fill: "var(--theme-ui-colors-text)",
outlineWidth: 2,
outlineColor: "var(--theme-ui-colors-background)",
outlineOpacity: 1,
},
},
tooltip: {
container: {
background: "var(--theme-ui-colors-background)",
color: "var(--theme-ui-colors-text)",
fontSize: 12,
},
basic: {},
chip: {},
table: {},
tableCell: {},
tableCellValue: {},
},
};

export default nivoTheme;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"dependencies": {
"@badrap/bar-of-progress": "^0.1.2",
"@emotion/react": "^11.8.2",
"@nivo/calendar": "^0.79.1",
"@nivo/core": "^0.79.0",
"@nivo/radar": "^0.79.1",
"@tailwindcss/forms": "^0.5.0",
"@theme-ui/presets": "^0.13.1",
"kbar": "0.1.0-beta.31",
Expand Down
27 changes: 25 additions & 2 deletions pages/users/[login]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import Loading from "ui/Loading";
import useAPI from "lib/useAPI";
import UserHeader from "ui/headers/UserHeader";
import sortCursus from "lib/sortCursus";
import { ResponsiveRadar } from "@nivo/radar";
import nivoTheme from "lib/nivoTheme";
// import getCampusFromId from "lib/getCampusFromId";

function getCurrentLocation(locations: any): string {
Expand All @@ -44,7 +46,7 @@ function getLastSeen(locations: any): string {

const None = () => <i className="opacity-75">none</i>;

const OverviewCard = ({ children, title, href = null }) => {
const OverviewCard = ({ children, title, href = null, heigth = null }) => {
const link = href
? (el) => (
<Link href={href} passHref>
Expand All @@ -56,11 +58,29 @@ const OverviewCard = ({ children, title, href = null }) => {
return link(
<Card bg="muted" p={3} as={href ? "a" : null} sx={{ borderRadius: 5 }}>
<Heading mb={2}>{title}</Heading>
<Box>{children}</Box>
<Box sx={{ height: heigth }}>{children}</Box>
</Card>
);
};

const MyResponsiveRadar = ({ data }) => (
<ResponsiveRadar
data={data}
theme={nivoTheme}
keys={["level"]}
indexBy="name"
valueFormat=">-.2f"
margin={{ top: 40, right: 80, bottom: 40, left: 80 }}
maxValue={21}
// borderColor="white"
// gridLabelOffset={36}
// dotSize={10}
// dotColor="white"
// dotBorderWidth={2}
colors={{ scheme: "blues" }}
/>
);

export default function UserOverview() {
const router = useRouter();
const { login } = router.query;
Expand Down Expand Up @@ -309,6 +329,9 @@ export default function UserOverview() {
<None />
)}
</OverviewCard>
<OverviewCard title="Skills" heigth={300}>
<MyResponsiveRadar data={user.cursus_users[0].skills} />
</OverviewCard>
</Grid>
</>
);
Expand Down
131 changes: 90 additions & 41 deletions pages/users/[login]/locations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import groupBy from "lib/groupBy";
import Loading from "ui/Loading";
import useAPI from "lib/useAPI";
import UserHeader from "ui/headers/UserHeader";
import { ResponsiveCalendar } from "@nivo/calendar";
import nivoTheme from "lib/nivoTheme";

const prettyOptions = { secondsDecimalDigits: 0 };

Expand All @@ -30,13 +32,42 @@ function rawDuration(location) {
return end - start;
}

const MyResponsiveCalendar = ({ data /* see data tab */ }) => (
<ResponsiveCalendar
data={data}
theme={nivoTheme}
from="2015-03-01"
to="2016-07-12"
emptyColor="var(--theme-ui-colors-muted)"
// colors={{ scheme: "blues" }}
margin={{ top: 40, right: 40, bottom: 40, left: 40 }}
yearSpacing={40}
monthBorderColor="#333"
dayBorderWidth={2}
dayBorderColor="#222"
legends={[
{
anchor: "bottom-right",
direction: "row",
translateY: 36,
itemCount: 4,
itemWidth: 42,
itemHeight: 36,
itemsSpacing: 14,
itemDirection: "right-to-left",
},
]}
/>
);

export default function UserLocations() {
const router = useRouter();
const { login } = router.query;

const { data: locations, isLoading } = useAPI(
`/v2/users/${login}/locations`
);
const { data: stats } = useAPI(`/v2/users/${login}/locations_stats`);

if (isLoading) return <Loading />;
if (!locations) return <>Error</>;
Expand All @@ -47,50 +78,68 @@ export default function UserLocations() {
new Date(l.begin_at).toDateString()
);

return byDay.map((day) => (
<Box key={day.name} as="section" my={2}>
<Heading>{day.name} </Heading>
<Text>
{getDayDuration(day)}
{day.value[0].end_at ? "" : " ++"}
</Text>
{day.value.map((location) => (
<Box
key={location.id}
my={3}
sx={{ fontFeatureSettings: "'tnum'" }}
>
<h4>
<b>{location.host}</b>
<Text opacity="50%">
{" "}
@{" "}
<Link href={`/campus/${location.campus_id}`}>
<a>{location.campus_id}</a>
</Link>
</Text>
</h4>
<small>
<time dateTime={location.begin_at}>
{new Date(location.begin_at).toLocaleTimeString(
locale
)}
</time>{" "}
–{" "}
{location.end_at ? (
<time dateTime={location.end_at}>
{new Date(location.end_at).toLocaleTimeString(
locale
const locs = [];

console.log(byDay);

// byDay.forEach((day) => {
// let sum;
// day.forEach((location) => console.log(location));
// });

return (
<>
<Box sx={{ height: 300 }}>
<MyResponsiveCalendar data={locs} />
</Box>
{byDay.map((day) => (
<Box key={day.name} as="section" my={2}>
<Heading>{day.name} </Heading>
<Text>
{getDayDuration(day)}
{day.value[0].end_at ? "" : " ++"}
</Text>
{day.value.map((location) => (
<Box
key={location.id}
my={3}
sx={{ fontFeatureSettings: "'tnum'" }}
>
<h4>
<b>{location.host}</b>
<Text opacity="50%">
{" "}
@{" "}
<Link
href={`/campus/${location.campus_id}`}
>
<a>{location.campus_id}</a>
</Link>
</Text>
</h4>
<small>
<time dateTime={location.begin_at}>
{new Date(
location.begin_at
).toLocaleTimeString(locale)}
</time>{" "}
–{" "}
{location.end_at ? (
<time dateTime={location.end_at}>
{new Date(
location.end_at
).toLocaleTimeString(locale)}
</time>
) : (
<Text color="#01FF70">active</Text>
)}
</time>
) : (
<Text color="#01FF70">active</Text>
)}
</small>
</small>
</Box>
))}
</Box>
))}
</Box>
));
</>
);
}

UserLocations.header = UserHeader;
Loading