-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
299 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function getTimestamp(id: string): Date { | ||
const parts = id.split('_'); | ||
if (parts.length !== 2) { | ||
throw new Error('Invalid ID format'); | ||
} | ||
|
||
const timestampBase36 = parts[1].slice(0, -6); | ||
const timestamp = parseInt(timestampBase36, 36); | ||
return new Date(timestamp); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { SocketHandler } from "../../backendTypes"; | ||
import { getFeaturedGraphs } from "../../db/operations/graphOperations"; | ||
import { GraphData } from "../../.shared/types"; | ||
|
||
interface GetFeaturedGraphsResponse { | ||
graphs: GraphData[] | ||
} | ||
|
||
export const handleGetFeaturedGraphs: SocketHandler<{}, GetFeaturedGraphsResponse> = async (socket, io, { }) => { | ||
const graphs = await getFeaturedGraphs(); | ||
return { | ||
success: true, | ||
data: { graphs } | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { SocketHandler } from "../../backendTypes"; | ||
import { getUserGraphs } from "../../db/operations/graphOperations"; | ||
import { GraphData } from "../../.shared/types"; | ||
|
||
interface GetMyGraphsResponse { | ||
graphs: GraphData[] | ||
} | ||
|
||
export const handleGetMyGraphs: SocketHandler<{}, GetMyGraphsResponse> = async (socket, io, { }) => { | ||
if (!socket.data.user) { | ||
return { | ||
success: false, | ||
error: 'Authentication required' | ||
}; | ||
} | ||
const graphs = await getUserGraphs(socket.data.user.id); | ||
return { | ||
success: true, | ||
data: { graphs } | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { useWebSocket } from '../contexts/WebSocketContext'; | ||
import { GraphData } from '../shared/types'; | ||
import { GraphsList } from './GraphsList'; | ||
|
||
|
||
export const FeaturedGraphsList = () => { | ||
const { socket } = useWebSocket(); | ||
const [graphs, setGraphs] = useState<GraphData[]>([]); | ||
|
||
useEffect(() => { | ||
socket?.emit('get featured graphs', {}, (response: any) => { | ||
if (response.success) { | ||
setGraphs(response.data.graphs); | ||
} | ||
}); | ||
}, [socket]); | ||
|
||
return ( | ||
<div className="flex flex-col mx-auto my-4"> | ||
<h2>Featured graphs</h2> | ||
<GraphsList graphs={graphs} /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Link } from 'react-router-dom'; | ||
import { GraphData } from '../shared/types'; | ||
import { formatDate } from '../utils/time'; | ||
|
||
export const GraphInfoBox = ({ id, name, argumentCount, lastActivity }: GraphData) => { | ||
return ( | ||
<Link to={`/graph/${id}`} className="block"> | ||
<div className="py-4 bg-white hover:bg-stone-50 transition-colors duration-100 text-stone-700 border-t border-stone-200"> | ||
<h4 className="m-0 text-base">{name}</h4> | ||
<div className="text-sm text-stone-500 flex justify-between"> | ||
<span> | ||
{argumentCount} argument{argumentCount !== 1 ? 's' : ''} | ||
</span> | ||
<span> | ||
Last activity: {lastActivity ? formatDate(lastActivity) : 'never'} | ||
</span> | ||
</div> | ||
</div> | ||
</Link> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { GraphData } from '../shared/types'; | ||
import { GraphInfoBox } from './GraphInfoBox'; | ||
import LoadingSpinner from './LoadingSpinner'; | ||
|
||
interface GraphsListProps { | ||
graphs: GraphData[]; | ||
} | ||
|
||
export const GraphsList = ({ graphs }: GraphsListProps) => { | ||
return ( | ||
<div className="flex flex-col mx-auto w-full"> | ||
{graphs.length > 0 ? ( | ||
<div className="border-b border-stone-200"> | ||
{graphs.map(graph => ( | ||
<GraphInfoBox key={graph.id} {...graph} /> | ||
))} | ||
</div> | ||
) : ( | ||
<LoadingSpinner className="mt-4" /> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { useWebSocket } from '../contexts/WebSocketContext'; | ||
import { GraphData } from '../shared/types'; | ||
import { GraphsList } from './GraphsList'; | ||
|
||
|
||
export const MyGraphsList = () => { | ||
const { socket } = useWebSocket(); | ||
const [graphs, setGraphs] = useState<GraphData[]>([]); | ||
|
||
useEffect(() => { | ||
socket?.emit('get my graphs', {}, (response: any) => { | ||
if (response.success) { | ||
setGraphs(response.data.graphs); | ||
} | ||
}); | ||
}, [socket]); | ||
|
||
return ( | ||
<div className="flex flex-col mx-auto mt-4"> | ||
<h2>My graphs</h2> | ||
<GraphsList graphs={graphs} /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.