-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): add problem status display (#86)
- Loading branch information
Showing
13 changed files
with
193 additions
and
81 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,2 @@ | ||
declined: | ||
- "@aoi-js/frontend" |
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
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,22 @@ | ||
<template> | ||
<div v-if="status" class="u-flex u-gap-2 u-items-center"> | ||
<SolutionStatusChip | ||
:status="status.lastSolutionStatus" | ||
abbrev | ||
:score="status.lastSolutionScore" | ||
:to="`/org/${orgId}/problem/${problemId}/solution/${status.lastSolutionId}`" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import SolutionStatusChip from '../solution/SolutionStatusChip.vue' | ||
import type { IProblemStatusDTO } from './types' | ||
defineProps<{ | ||
orgId: string | ||
problemId: string | ||
status?: IProblemStatusDTO | ||
}>() | ||
</script> |
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,33 @@ | ||
import { computed } from 'vue' | ||
|
||
export interface ISolutionStatusProps { | ||
status: string | ||
to?: string | ||
abbrev?: boolean | ||
score?: number | ||
} | ||
|
||
export function useSolutionStatus(props: ISolutionStatusProps) { | ||
const knownStatus: Record<string, [string, string]> = { | ||
Accepted: ['mdi-check', 'success'], | ||
Success: ['mdi-check', 'info'], | ||
'Memory Limit Exceeded': ['mdi-database-alert-outline', 'error'], | ||
'Time Limit Exceeded': ['mdi-timer-alert-outline', 'error'], | ||
'Wrong Answer': ['mdi-close', 'error'], | ||
'Compile Error': ['mdi-code-braces', 'error'], | ||
'Internal Error': ['mdi-help-circle-outline', ''], | ||
'Runtime Error': ['mdi-alert-decagram-outline', 'error'], | ||
Running: ['mdi-play', 'indigo'], | ||
Queued: ['mdi-timer-sand', 'indigo'] | ||
} | ||
const display = computed(() => knownStatus[props.status] ?? ['mdi-circle-outline', 'warning']) | ||
const status = computed(() => { | ||
if (!props.abbrev) return props.status | ||
const abbrev = props.status | ||
.split(' ') | ||
.map((word) => word[0].toUpperCase()) | ||
.join('') | ||
return abbrev.length > 1 ? abbrev : props.status.slice(0, 2).toUpperCase() | ||
}) | ||
return { display, status } | ||
} |
35 changes: 12 additions & 23 deletions
35
apps/frontend/src/components/solution/SolutionStatusChip.vue
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 |
---|---|---|
@@ -1,34 +1,23 @@ | ||
<template> | ||
<VChip | ||
:text="status" | ||
:prepend-icon="display[0]" | ||
:color="display[1]" | ||
variant="outlined" | ||
:variant="abbrev ? 'text' : 'outlined'" | ||
:to="to" | ||
v-if="to" | ||
/> | ||
<VChip :text="status" :prepend-icon="display[0]" :color="display[1]" variant="outlined" v-else /> | ||
> | ||
{{ status }} | ||
<span v-if="score !== undefined"> | ||
(<code :style="{ color: palette(score) }" v-text="score" />) | ||
</span> | ||
</VChip> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed } from 'vue' | ||
import { useSolutionStatus, type ISolutionStatusProps } from './SolutionStatus' | ||
const props = defineProps<{ | ||
status: string | ||
to?: string | ||
}>() | ||
import { palette } from '@/utils/colors' | ||
const knownStatus: Record<string, [string, string]> = { | ||
Accepted: ['mdi-check', 'success'], | ||
Success: ['mdi-check', 'info'], | ||
'Memory Limit Exceeded': ['mdi-database-alert-outline', 'error'], | ||
'Time Limit Exceeded': ['mdi-timer-alert-outline', 'error'], | ||
'Wrong Answer': ['mdi-close', 'error'], | ||
'Compile Error': ['mdi-code-braces', 'error'], | ||
'Internal Error': ['mdi-help-circle-outline', ''], | ||
'Runtime Error': ['mdi-alert-decagram-outline', 'error'], | ||
Running: ['mdi-play', 'indigo'], | ||
Queued: ['mdi-timer-sand', 'indigo'] | ||
} | ||
const display = computed(() => knownStatus[props.status] ?? ['mdi-circle-outline', 'warning']) | ||
const props = defineProps<ISolutionStatusProps>() | ||
const { display, status } = useSolutionStatus(props) | ||
</script> |
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 |
---|---|---|
@@ -1,15 +1,30 @@ | ||
<template> | ||
<VBadge :icon="icons[accessLevel]" :color="colors[accessLevel]" v-bind="$attrs"> | ||
<VChip | ||
v-if="variant === 'chip'" | ||
variant="tonal" | ||
rounded | ||
:prepend-icon="icons[accessLevel]" | ||
:color="colors[accessLevel]" | ||
v-bind="$attrs" | ||
> | ||
{{ t(`access-level.${names[accessLevel]}`) }} | ||
</VChip> | ||
<VBadge v-else :icon="icons[accessLevel]" :color="colors[accessLevel]" v-bind="$attrs"> | ||
<slot /> | ||
</VBadge> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useI18n } from 'vue-i18n' | ||
defineProps<{ | ||
accessLevel: number | ||
variant?: 'chip' | ||
}>() | ||
const icons = ['mdi-earth', 'mdi-shield-outline', 'mdi-lock-outline'] | ||
const { t } = useI18n() | ||
const icons = ['mdi-earth', 'mdi-shield-outline', 'mdi-lock-outline'] | ||
const colors = ['success', 'info', 'primary'] | ||
const names = ['public', 'restricted', 'private'] | ||
</script> |
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.