-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix bold text regex * Restructure the bookwork listing to maintain 1 responsibility principle * Add button for deleting a bookwork item
- Loading branch information
1 parent
4103452
commit 7f22068
Showing
9 changed files
with
200 additions
and
118 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
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,59 @@ | ||
import components from '@core/components'; | ||
import Row from '@core/components/row'; | ||
import { common } from '@core/modules'; | ||
import { storages } from '@core/handlers/state'; | ||
import { commonStyles } from '@core/stylesheet'; | ||
import { AnswerProps } from '@azalea/bookwork'; | ||
import { styles } from './bookwork.styles'; | ||
|
||
const { React } = common; | ||
const { bookwork } = storages; | ||
|
||
export default function Answer({ index, store, array, code, plural, answers, forceRender }: AnswerProps) { | ||
const { textAnswers, imageAnswers } = answers; | ||
|
||
return <React.Fragment key={index}> | ||
<Row | ||
label={'Question:'} | ||
sublabel={store.id} | ||
trailing={<div style={commonStyles.merge(x => [x.flex, x.row])}> | ||
<div | ||
style={{ | ||
marginTop: '0.5em', | ||
marginRight: '0.5em' | ||
}} | ||
> | ||
<h6 style={{ color: 'var(--palette-dark-blue-90)'}}>Date stored:</h6> | ||
<h4 style={{ fontWeight: 'normal' }}> | ||
{new Date(store.date).toLocaleString()} | ||
</h4> | ||
</div> | ||
<components.SolidButton | ||
text={'✖'} | ||
style={styles.delete} | ||
onClick={() => { | ||
bookwork.set(code, bookwork.get(code).filter(item => item.id !== store.id)); | ||
forceRender({}); | ||
}} | ||
/> | ||
</div>} | ||
centerTrailing={false} | ||
/> | ||
<components.Dividers.Small /> | ||
<Row | ||
label={`Answer${plural}:`} | ||
sublabel={<div> | ||
{imageAnswers.length > 0 && ( | ||
<div style={commonStyles.merge(x => [x.flex, x.row, styles.images])}> | ||
{imageAnswers.map((answer, idx) => <img src={answer} key={idx} />)} | ||
</div> | ||
)} | ||
{textAnswers.length > 0 && <components.TextWithMaths | ||
text={textAnswers.join('$,\\;\\;$')} | ||
style={{ margin: 0, padding: 0 }} | ||
/>} | ||
</div>} | ||
/> | ||
{index !== array.length - 1 && <components.Dividers.Large />} | ||
</React.Fragment>; | ||
} |
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,36 @@ | ||
import { common } from '@core/modules'; | ||
import { Section } from '@core/components/section'; | ||
import { AnswerSectionProps } from '@azalea/bookwork'; | ||
import Answer from './Answer'; | ||
|
||
const { React } = common; | ||
|
||
export default function AnswerSection({ code, value, forceRender }: AnswerSectionProps) { | ||
return <Section title={code} key={code}> | ||
{value | ||
.filter(store => Array.isArray(store.answers) && store.answers.length > 0) | ||
.sort((a, b) => b.date - a.date) | ||
.map((store, index, array) => { | ||
// Add 's' to the word 'Answer' if the amount of answers is more than 1 | ||
// You will never have 0 or -1 answers due to the filter above | ||
// Therefore 'len > 1' is valid for this use case | ||
const plural = store.answers.length > 1 ? 's' : ''; | ||
|
||
// Convert plain numbers to latex formatting | ||
const answers = store.answers.map(answer => isNaN(+answer) ? answer : `$${answer}$`); | ||
const imageAnswers = answers.filter(answer => answer.includes('assets.sparxhomework.uk')); | ||
const textAnswers = answers.filter(answer => !answer.includes('assets.sparxhomework.uk')); | ||
|
||
return <Answer | ||
key={index} | ||
code={code} | ||
store={store} | ||
index={index} | ||
array={array} | ||
plural={plural} | ||
forceRender={forceRender} | ||
answers={{ imageAnswers, textAnswers }} | ||
/>; | ||
})} | ||
</Section>; | ||
} |
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,67 @@ | ||
import { createStyleSheet } from '@core/stylesheet'; | ||
|
||
export const { merge, styles } = createStyleSheet({ | ||
common: { | ||
marginLeft: '1em' | ||
}, | ||
|
||
input: { | ||
borderRadius: '10em', | ||
height: 'auto' | ||
}, | ||
|
||
message: { | ||
marginInline: '2em', | ||
background: 'var(--palette-light-blue-20)' | ||
}, | ||
|
||
navigation: { | ||
marginBlock: '1em' | ||
}, | ||
|
||
collapsable: { | ||
overflow: 'hidden', | ||
transition: 'max-height 300ms ease, opacity 300ms ease' | ||
}, | ||
|
||
answers: { | ||
fontSize: '1.25rem', | ||
justifyContent: 'end', | ||
marginRight: '2em' | ||
}, | ||
|
||
actions: { | ||
justifyContent: 'start', | ||
marginInline: '2em', | ||
gap: '0.5em', | ||
flexGrow: 1 | ||
}, | ||
|
||
paragraph: { | ||
marginBlock: 0, | ||
marginRight: '0.25em' | ||
}, | ||
|
||
delete: { | ||
width: 'fit-content', | ||
height: 'fit-content', | ||
aspectRatio: 1, | ||
borderRadius: '100000px', | ||
transform: 'scale(0.5)', | ||
marginTop: '0.125em', | ||
marginRight: '-0.25em', | ||
fontSize: '1.5rem' | ||
}, | ||
|
||
fallback: { | ||
marginInline: '2em', | ||
paddingBlock: '1em', | ||
background: 'var(--palette-light-blue-20)', | ||
}, | ||
|
||
images: { | ||
maxWidth: '20%', | ||
gap: '1em', | ||
marginBlock: '0.5em' | ||
} | ||
}); |
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