Skip to content

Commit c8f37f8

Browse files
authored
refactor: dashboard (#422)
1 parent 794c0f8 commit c8f37f8

File tree

3 files changed

+306
-467
lines changed

3 files changed

+306
-467
lines changed

api/src/resolver_repo.ts

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,22 @@ async function ensurePodEditAccess({ id, userId }) {
4141
}
4242
}
4343

44-
async function myRepos(_, __, { userId }) {
44+
async function getDashboardRepos(_, __, { userId }) {
4545
if (!userId) throw Error("Unauthenticated");
4646
const repos = await prisma.repo.findMany({
4747
where: {
48-
owner: {
49-
id: userId,
50-
},
48+
OR: [
49+
{
50+
owner: {
51+
id: userId,
52+
},
53+
},
54+
{
55+
collaborators: {
56+
some: { id: userId },
57+
},
58+
},
59+
],
5160
},
5261
include: {
5362
UserRepoData: {
@@ -58,46 +67,17 @@ async function myRepos(_, __, { userId }) {
5867
stargazers: true,
5968
},
6069
});
61-
// Sort by last access time.
62-
repos.sort((a, b) => {
63-
if (a.UserRepoData.length > 0) {
64-
if (b.UserRepoData.length > 0) {
65-
return (
66-
b.UserRepoData[0].accessedAt.valueOf() -
67-
a.UserRepoData[0].accessedAt.valueOf()
68-
);
69-
}
70-
return -1;
71-
}
72-
return a.updatedAt.valueOf() - b.updatedAt.valueOf();
73-
});
74-
// Re-use updatedAt field (this is actually the lastviewed field).
7570
return repos.map((repo) => {
7671
return {
7772
...repo,
78-
updatedAt:
73+
accessedAt:
7974
repo.UserRepoData.length > 0
8075
? repo.UserRepoData[0].accessedAt
8176
: repo.updatedAt,
8277
};
8378
});
8479
}
8580

86-
async function myCollabRepos(_, __, { userId }) {
87-
if (!userId) throw Error("Unauthenticated");
88-
const repos = await prisma.repo.findMany({
89-
where: {
90-
collaborators: {
91-
some: { id: userId },
92-
},
93-
},
94-
include: {
95-
stargazers: true,
96-
},
97-
});
98-
return repos;
99-
}
100-
10181
async function updateUserRepoData({ userId, repoId }) {
10282
// FIXME I should probably rename this from query to mutation?
10383
//
@@ -609,9 +589,8 @@ async function copyRepo(_, { repoId }, { userId }) {
609589

610590
export default {
611591
Query: {
612-
myRepos,
613592
repo,
614-
myCollabRepos,
593+
getDashboardRepos,
615594
getVisibility,
616595
},
617596
Mutation: {

api/src/typedefs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const typeDefs = gql`
3131
public: Boolean
3232
createdAt: String
3333
updatedAt: String
34+
accessedAt: String
3435
}
3536
3637
type Edge {
@@ -105,11 +106,10 @@ export const typeDefs = gql`
105106
repos: [Repo]
106107
repo(id: String!): Repo
107108
pod(id: ID!): Pod
108-
myRepos: [Repo]
109+
getDashboardRepos: [Repo]
109110
activeSessions: [String]
110111
getVisibility(repoId: String!): Visibility
111112
listAllRuntimes: [RuntimeInfo]
112-
myCollabRepos: [Repo]
113113
infoRuntime(sessionId: String!): RuntimeInfo
114114
}
115115

0 commit comments

Comments
 (0)