-
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
1 parent
f43906b
commit e0f538f
Showing
17 changed files
with
520 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from "react" | ||
import { Row, Col, Avatar } from "antd" | ||
import styled from "styled-components" | ||
import Title from "antd/lib/typography/Title" | ||
import { color } from "../../utils/colors" | ||
const StyledUsernameWrapper = styled.div` | ||
display: flex; | ||
margin-bottom: 3vh; | ||
` | ||
const StyledAvatar = styled(Avatar)` | ||
margin-right: 10px; | ||
` | ||
interface AvatarProps { | ||
value: string | ||
size: 2 | 5 | 1 | 3 | 4 | undefined | ||
} | ||
export const AvatarWithTitle = (props: AvatarProps): JSX.Element => { | ||
const { value, size } = props | ||
return ( | ||
<Row> | ||
<Col offset={2} span={18}> | ||
<StyledUsernameWrapper> | ||
<StyledAvatar style={{ backgroundColor: color(value) }}>{value[0]}</StyledAvatar> | ||
<Title level={size}>{value}</Title> | ||
</StyledUsernameWrapper> | ||
</Col> | ||
</Row> | ||
) | ||
} |
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,55 @@ | ||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
import { observable, IObservableValue } from "mobx" | ||
|
||
export type StatusType = "idle" | "pending" | "done" | "error" | ||
|
||
/** | ||
* Adds a status field to the model often for tracking api access. | ||
* | ||
* This property is a string which can be observed, but will not | ||
* participate in any serialization. | ||
* | ||
* Use this to extend your models: | ||
* | ||
* ```ts | ||
* types.model("MyModel") | ||
* .props({}) | ||
* .actions(self => ({})) | ||
* .extend(withStatus) // <--- time to shine baby!!! | ||
* ``` | ||
* | ||
* This will give you these 3 options: | ||
* | ||
* .status // returns a string | ||
* .status = "done" // change the status directly | ||
* .setStatus("done") // change the status and trigger an mst action | ||
*/ | ||
export const withStatus = () => { | ||
/** | ||
* The observable backing store for the status field. | ||
*/ | ||
const status: IObservableValue<string> = observable.box("idle") | ||
|
||
return { | ||
views: { | ||
// a getter | ||
get status() { | ||
return status.get() as StatusType | ||
}, | ||
// as setter | ||
set status(value: StatusType) { | ||
status.set(value) | ||
}, | ||
}, | ||
actions: { | ||
/** | ||
* Set the status to something new. | ||
* | ||
* @param value The new status. | ||
*/ | ||
setStatus(value: StatusType) { | ||
status.set(value) | ||
}, | ||
}, | ||
} | ||
} |
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,66 @@ | ||
import { applySnapshot, flow, Instance, SnapshotOut, types } from "mobx-state-tree" | ||
import { GetSignedUrl, GetSingleProposal, PutFile } from "../../services/api-types" | ||
import { withEnvironment } from "../extensions/with-environment" | ||
import { withStatus } from "../extensions/with-status" | ||
import { UserModel } from "../user-model/user-model" | ||
import { ProposalModel } from "./proposal-model" | ||
|
||
export const ProposalDetailModel = types | ||
.model("ProposalDetailModel") | ||
.props({ | ||
proposal: types.maybeNull(ProposalModel), | ||
}) | ||
.extend(withEnvironment) | ||
.extend(withStatus) | ||
.actions((self) => { | ||
return { | ||
getProposal: flow(function* (id: string) { | ||
self.setStatus("pending") | ||
try { | ||
const response: GetSingleProposal = yield self.environment.api.getProposal(id) | ||
if (response.kind !== "ok") { | ||
throw response | ||
} | ||
|
||
self.proposal = response.proposal as any | ||
self.setStatus("idle") | ||
} catch (err) { | ||
self.setStatus("error") | ||
} | ||
}), | ||
putFile: flow(function* (fileName: string, file: File, progress: (event: any) => void) { | ||
self.setStatus("pending") | ||
try { | ||
const response: PutFile = yield self.environment.api.submitFile(fileName, file, progress) | ||
if (response.kind !== "ok") { | ||
throw response | ||
} | ||
self.setStatus("idle") | ||
return response | ||
} catch (err) { | ||
console.log(err) | ||
self.setStatus("error") | ||
} | ||
}), | ||
getSignedUrl: flow(function* (fileName: string) { | ||
self.setStatus("pending") | ||
try { | ||
const response: GetSignedUrl = yield self.environment.api.getSignedUrl(fileName) | ||
console.log(response) | ||
if (response.kind !== "ok") { | ||
throw response | ||
} | ||
self.setStatus("idle") | ||
return response.url | ||
} catch (err) { | ||
console.log(err) | ||
self.setStatus("error") | ||
} | ||
}), | ||
} | ||
}) | ||
|
||
type ProposalDetailModelType = Instance<typeof ProposalDetailModel> | ||
export interface ProposalDetailModel extends ProposalDetailModelType {} | ||
type ProposalDetailModelSnapshotType = SnapshotOut<typeof ProposalDetailModel> | ||
export interface ProposalDetailModelSnapshot extends ProposalDetailModelSnapshotType {} |
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.