-
Notifications
You must be signed in to change notification settings - Fork 5
Add Write Form Feature #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
34 changes: 34 additions & 0 deletions
34
Modules/Sources/APIClient/Requests/ForumTemplateRequest.swift
This file contains hidden or 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,34 @@ | ||
| // | ||
| // ForumTemplateRequest.swift | ||
| // ForPDA | ||
| // | ||
| // Created by Xialtal on 15.03.25. | ||
| // | ||
|
|
||
| import PDAPI | ||
|
|
||
| public struct ForumTemplateRequest { | ||
| public let id: Int | ||
| public let action: TemplateAction | ||
|
|
||
| public enum TemplateAction { | ||
| case get | ||
| case send([Any]) | ||
| case preview([Any]) | ||
| } | ||
|
|
||
| public init(id: Int, action: TemplateAction) { | ||
| self.id = id | ||
| self.action = action | ||
| } | ||
| } | ||
|
|
||
| extension ForumTemplateRequest.TemplateAction { | ||
| var transferType: ForumCommand.TemplateAction { | ||
| switch self { | ||
| case .get: return .get | ||
| case .preview(let data): return .preview(data) | ||
| case .send(let data): return .send(data) | ||
| } | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
Modules/Sources/APIClient/Requests/PostPreviewRequest.swift
This file contains hidden or 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,21 @@ | ||
| // | ||
| // PostPreviewRequest.swift | ||
| // ForPDA | ||
| // | ||
| // Created by Xialtal on 15.03.25. | ||
| // | ||
|
|
||
| import PDAPI | ||
|
|
||
| public struct PostPreviewRequest: Sendable { | ||
| public let id: Int | ||
| public let post: PostRequest | ||
|
|
||
| public init( | ||
| id: Int, | ||
| post: PostRequest | ||
| ) { | ||
| self.id = id | ||
| self.post = post | ||
| } | ||
| } |
This file contains hidden or 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,25 @@ | ||
| // | ||
| // PostRequest.swift | ||
| // ForPDA | ||
| // | ||
| // Created by Xialtal on 18.03.25. | ||
| // | ||
|
|
||
| public struct PostRequest: Sendable { | ||
| public let topicId: Int | ||
| public let content: String | ||
| public let flag: Int | ||
| public let attachments: [Int] | ||
|
|
||
| public init( | ||
| topicId: Int, | ||
| content: String, | ||
| flag: Int, | ||
| attachments: [Int] | ||
| ) { | ||
| self.topicId = topicId | ||
| self.content = content | ||
| self.flag = flag | ||
| self.attachments = attachments | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,80 @@ | ||
| // | ||
| // WriteFormFieldType.swift | ||
| // ForPDA | ||
| // | ||
| // Created by Xialtal on 14.03.25. | ||
| // | ||
|
|
||
| public enum WriteFormFieldType: Sendable, Equatable, Hashable { | ||
| case title(String) | ||
| case text(FormField) | ||
| case editor(FormField) | ||
| case dropdown(FormField, _ options: [String]) | ||
| case uploadbox(FormField, _ extens: [String]) | ||
| case checkboxList(FormField, _ options: [String]) | ||
|
|
||
| public struct FormField: Sendable, Equatable, Hashable { | ||
| public let name: String | ||
| public let description: String | ||
| public let example: String | ||
| public let flag: Int | ||
| public let defaultValue: String | ||
|
|
||
| public var isRequired: Bool { | ||
| return flag & 1 != 0 | ||
| } | ||
|
|
||
| public var isVisible: Bool { | ||
| return flag & 2 != 0 | ||
| } | ||
|
|
||
| public init( | ||
| name: String, | ||
| description: String, | ||
| example: String, | ||
| flag: Int, | ||
| defaultValue: String | ||
| ) { | ||
| self.name = name | ||
| self.description = description | ||
| self.example = example | ||
| self.flag = flag | ||
| self.defaultValue = defaultValue | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public extension WriteFormFieldType { | ||
| static let mockTitle: WriteFormFieldType = | ||
| .title("[b]This is absolute simple title[/b]") | ||
|
|
||
| static let mockText: WriteFormFieldType = .text( | ||
| FormField( | ||
| name: "Topic name", | ||
| description: "Enter topic name.", | ||
| example: "Starting from For, ends with PDA", | ||
| flag: 1, | ||
| defaultValue: "" | ||
| ) | ||
| ) | ||
|
|
||
| static let mockEditor: WriteFormFieldType = .editor( | ||
| FormField( | ||
| name: "Topic content", | ||
| description: "This field contains topic [color=red]hat[/color] content.", | ||
| example: "ForPDA Forever!", | ||
| flag: 1, | ||
| defaultValue: "" | ||
| ) | ||
| ) | ||
|
|
||
| static let mockEditorSimple: WriteFormFieldType = .editor( | ||
| FormField( | ||
| name: "", | ||
| description: "", | ||
| example: "Post text...", | ||
| flag: 0, | ||
| defaultValue: "" | ||
| ) | ||
| ) | ||
| } | ||
This file contains hidden or 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,25 @@ | ||
| // | ||
| // WriteFormForType.swift | ||
| // ForPDA | ||
| // | ||
| // Created by Xialtal on 14.03.25. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| public enum WriteFormForType: Sendable, Equatable { | ||
| case topic(forumId: Int, content: [String]) | ||
| case post(topicId: Int, content: PostContentType) | ||
| case report(id: Int, content: String, type: ReportType) | ||
|
|
||
| public enum PostContentType: Sendable, Equatable { | ||
| case template([String]) | ||
| case simple(String, [Int]) | ||
| } | ||
|
|
||
| public enum ReportType: Sendable, Equatable { | ||
| case post | ||
| case comment | ||
| case reputation | ||
| } | ||
| } |
This file contains hidden or 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,10 @@ | ||
| // | ||
| // WriteFormSend.swift | ||
| // ForPDA | ||
| // | ||
| // Created by Xialtal on 18.03.25. | ||
| // | ||
|
|
||
| public enum WriteFormSend: Sendable { | ||
| case post(PostSend) | ||
| } |
This file contains hidden or 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,19 @@ | ||
| // | ||
| // PostPreview.swift | ||
| // ForPDA | ||
| // | ||
| // Created by Xialtal on 15.03.25. | ||
| // | ||
|
|
||
| public struct PostPreview: Sendable { | ||
| public let content: String | ||
| public let attachmentIds: [Int] | ||
|
|
||
| public init( | ||
| content: String, | ||
| attachmentIds: [Int] | ||
| ) { | ||
| self.content = content | ||
| self.attachmentIds = attachmentIds | ||
| } | ||
| } |
This file contains hidden or 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,23 @@ | ||
| // | ||
| // PostSend.swift | ||
| // ForPDA | ||
| // | ||
| // Created by Xialtal on 18.03.25. | ||
| // | ||
|
|
||
| public struct PostSend: Sendable { | ||
| public let id: Int | ||
| public let topicId: Int | ||
| public let offset: Int | ||
|
|
||
| public init( | ||
| id: Int, | ||
| topicId: Int, | ||
| offset: Int | ||
| ) { | ||
| self.id = id | ||
| self.topicId = topicId | ||
| self.offset = offset | ||
| } | ||
| } | ||
|
|
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.