Skip to content

Commit cfdb9a6

Browse files
committed
Use GraphQL queries in UI, remove HTTP controllers
Now the UI updates itself when the GraphQL query is run, and the GraphQL cache is automatically updated with the correct values.
1 parent e9f56d0 commit cfdb9a6

File tree

3 files changed

+99
-67
lines changed

3 files changed

+99
-67
lines changed

backend/LexBoxApi/Controllers/ProjectController.cs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -232,68 +232,6 @@ private async Task StreamHttpResponse(HttpContent hgResult)
232232
await hgResult.CopyToAsync(writer.AsStream());
233233
}
234234

235-
[HttpPost("updateLexEntryCount/{code}")]
236-
[ProducesResponseType(StatusCodes.Status200OK)]
237-
[ProducesResponseType(StatusCodes.Status404NotFound)]
238-
[ProducesDefaultResponseType]
239-
public async Task<ActionResult<int>> UpdateLexEntryCount(string code)
240-
{
241-
var result = await projectService.UpdateLexEntryCount(code);
242-
return result is null ? NotFound() : result;
243-
}
244-
245-
[HttpPost("updateLanguageList/{code}")]
246-
[ProducesResponseType(StatusCodes.Status200OK)]
247-
[ProducesResponseType(StatusCodes.Status404NotFound)]
248-
[ProducesDefaultResponseType]
249-
public async Task UpdateLanguageList(string code)
250-
{
251-
var projectId = await projectService.LookupProjectId(code);
252-
await projectService.UpdateProjectLangTags(projectId);
253-
}
254-
255-
[HttpPost("updateMissingLanguageList")]
256-
public async Task<ActionResult<string[]>> UpdateMissingLanguageList(int limit = 10)
257-
{
258-
var projects = lexBoxDbContext.Projects
259-
.Include(p => p.FlexProjectMetadata)
260-
.Where(p => p.Type == ProjectType.FLEx && p.LastCommit != null && p.FlexProjectMetadata!.WritingSystems == null)
261-
.Take(limit)
262-
.AsAsyncEnumerable();
263-
var codes = new List<string>(limit);
264-
await foreach (var project in projects)
265-
{
266-
codes.Add(project.Code);
267-
project.FlexProjectMetadata ??= new FlexProjectMetadata();
268-
project.FlexProjectMetadata.WritingSystems = await hgService.GetProjectWritingSystems(project.Code);
269-
}
270-
271-
await lexBoxDbContext.SaveChangesAsync();
272-
273-
return Ok(codes);
274-
}
275-
276-
[HttpPost("updateMissingLangProjectId")]
277-
public async Task<ActionResult<string[]>> UpdateMissingLangProjectId(int limit = 10)
278-
{
279-
var projects = lexBoxDbContext.Projects
280-
.Include(p => p.FlexProjectMetadata)
281-
.Where(p => p.Type == ProjectType.FLEx && p.LastCommit != null && p.FlexProjectMetadata!.LangProjectId == null)
282-
.Take(limit)
283-
.AsAsyncEnumerable();
284-
var codes = new List<string>(limit);
285-
await foreach (var project in projects)
286-
{
287-
codes.Add(project.Code);
288-
project.FlexProjectMetadata ??= new FlexProjectMetadata();
289-
project.FlexProjectMetadata.LangProjectId = await hgService.GetProjectIdOfFlexProject(project.Code);
290-
}
291-
292-
await lexBoxDbContext.SaveChangesAsync();
293-
294-
return Ok(codes);
295-
}
296-
297235
[HttpPost("queueUpdateProjectMetadataTask")]
298236
public async Task<ActionResult> QueueUpdateProjectMetadataTask(string projectCode)
299237
{

frontend/src/routes/(authenticated)/project/[project_code]/+page.svelte

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
_changeProjectName,
1414
_deleteProjectUser,
1515
_leaveProject,
16+
_updateProjectLanguageList,
17+
_updateProjectLexEntryCount,
1618
type ProjectUser,
1719
} from './+page';
1820
import AddProjectMember from './AddProjectMember.svelte';
@@ -63,7 +65,6 @@
6365
return a.user.name.localeCompare(b.user.name);
6466
});
6567
66-
let lexEntryCount: number | string | null | undefined = undefined;
6768
$: lexEntryCount = project.flexProjectMetadata?.lexEntryCount;
6869
$: vernacularLangTags = project.flexProjectMetadata?.writingSystems?.vernacularWss;
6970
$: analysisLangTags = project.flexProjectMetadata?.writingSystems?.analysisWss;
@@ -75,17 +76,15 @@
7576
let loadingEntryCount = false;
7677
async function updateEntryCount(): Promise<void> {
7778
loadingEntryCount = true;
78-
const response = await fetch(`/api/project/updateLexEntryCount/${project.code}`, {method: 'POST'});
79-
lexEntryCount = await response.text();
79+
await _updateProjectLexEntryCount(project.code);
8080
loadingEntryCount = false;
8181
}
8282
8383
let loadingLanguageList = false;
8484
async function updateLanguageList(): Promise<void> {
8585
loadingLanguageList = true;
86-
await fetch(`/api/project/updateLanguageList/${project.code}`, {method: 'POST'});
86+
await _updateProjectLanguageList(project.code);
8787
loadingLanguageList = false;
88-
await invalidate(`project:${project.code}`);
8988
}
9089
9190
let resetProjectModal: ResetProjectModal;

frontend/src/routes/(authenticated)/project/[project_code]/+page.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import type {
1818
ProjectPageQuery,
1919
SetProjectConfidentialityInput,
2020
SetProjectConfidentialityMutation,
21+
UpdateLangProjectIdMutation,
22+
UpdateProjectLanguageListMutation,
23+
UpdateProjectLexEntryCountMutation,
2124
} from '$lib/gql/types';
2225
import { getClient, graphql } from '$lib/gql';
2326

@@ -266,6 +269,98 @@ export async function _bulkAddProjectMembers(input: BulkAddProjectMembersInput):
266269
return result;
267270
}
268271

272+
export async function _updateProjectLexEntryCount(code: string): $OpResult<UpdateProjectLexEntryCountMutation> {
273+
//language=GraphQL
274+
const result = await getClient()
275+
.mutation(
276+
graphql(`
277+
mutation UpdateProjectLexEntryCount($input: UpdateProjectLexEntryCountInput!) {
278+
updateProjectLexEntryCount(input: $input) {
279+
project {
280+
id
281+
flexProjectMetadata {
282+
lexEntryCount
283+
}
284+
}
285+
errors {
286+
__typename
287+
... on Error {
288+
message
289+
}
290+
}
291+
}
292+
}
293+
`),
294+
{ input: { code } },
295+
);
296+
return result;
297+
}
298+
299+
export async function _updateLangProjectId(code: string): $OpResult<UpdateLangProjectIdMutation> {
300+
//language=GraphQL
301+
const result = await getClient()
302+
.mutation(
303+
graphql(`
304+
mutation UpdateLangProjectId($input: UpdateLangProjectIdInput!) {
305+
updateLangProjectId(input: $input) {
306+
project {
307+
id
308+
flexProjectMetadata {
309+
langProjectId
310+
}
311+
}
312+
errors {
313+
__typename
314+
... on Error {
315+
message
316+
}
317+
}
318+
}
319+
}
320+
`),
321+
{ input: { code } },
322+
);
323+
return result;
324+
}
325+
326+
export async function _updateProjectLanguageList(code: string): $OpResult<UpdateProjectLanguageListMutation> {
327+
//language=GraphQL
328+
const result = await getClient()
329+
.mutation(
330+
graphql(`
331+
mutation UpdateProjectLanguageList($input: UpdateProjectLanguageListInput!) {
332+
updateProjectLanguageList(input: $input) {
333+
project {
334+
id
335+
flexProjectMetadata {
336+
writingSystems {
337+
analysisWss {
338+
tag
339+
isActive
340+
isDefault
341+
}
342+
vernacularWss {
343+
tag
344+
isActive
345+
isDefault
346+
}
347+
}
348+
}
349+
}
350+
errors {
351+
__typename
352+
... on Error {
353+
message
354+
}
355+
}
356+
}
357+
}
358+
`),
359+
{ input: { code } },
360+
);
361+
return result;
362+
}
363+
269364
export async function _changeProjectMemberRole(input: ChangeProjectMemberRoleInput): $OpResult<ChangeProjectMemberRoleMutation> {
270365
//language=GraphQL
271366
const result = await getClient()

0 commit comments

Comments
 (0)