Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanticD committed Sep 9, 2023
2 parents 69e3e33 + 368a9bb commit ddf9152
Show file tree
Hide file tree
Showing 41 changed files with 3,282 additions and 1,744 deletions.
76 changes: 60 additions & 16 deletions FlarumiOSApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
17 changes: 13 additions & 4 deletions LiangJianForum/Localization/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@
"🎊 Username: " = "🎊 Username:";
"🏖️ Discussion Count: " = "🏖️ Discussion Count:";
"🧬 Comment Count: " = "🧬 Comment Count:";
"comment_sector" = "🍿Comment";
"like_sector" = "🍺Like";
"follow_sector" = "⛳️Follow";
"comment_sector" = "Comment";
"like_sector" = "Like";
"money_sector" = "Asset History Record";
"Information has been hidden" = "Information has been hidden";
"Earned Badges" = "Earned Badges";
"No Badges Earned Yet" = "No Badges Earned Yet";
"🍾 In" = "🍾 In";
"username" = "username";
"password" = "password";
"Copy" = "Copy";
"copy_in_contextMenu" = "Copy the comment";
"Text Copied" = "Text Copied";
"post_tags_exceed_limit" = "Selected tags exceed the limit!";
"latest_sort_discussion" = "Latest discussions";
Expand All @@ -83,3 +83,12 @@
"hours later" = "%d hours later";
"minutes later" = "%d minutes later";
"very soon" = "very soon";
"like_in_contextMenu" = "Like the comment";
"pay_to_read_message" = "pay flarum money to read";
"tabbar_operations" = "Options";
"choose_to_quit" = "Sign out";
"start_new_discussion_message" = "New Discussion";
"profile_operations" = "Options";
"hot_discussions" = "Hot Discussions";
"old_discussions" = "Old Discussions";
"frontPage_discussions" = "Frontpage Discussions";
19 changes: 14 additions & 5 deletions LiangJianForum/Localization/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@
"Information has been hidden" = "信息已隐藏";
"Earned Badges" = "获得徽章";
"No Badges Earned Yet" = "还没有获得的徽章哦";
"comment_sector" = "🍿 评论";
"like_sector" = "🍺 点赞";
"follow_sector" = "⛳️ 关注";
"comment_sector" = "评论";
"like_sector" = "点赞";
"money_sector" = "资产记录";
"🍾 In" = "🍾 于";
"username" = "用户名";
"password" = "密码";
"Copy" = "复制回复内容";
"copy_in_contextMenu" = "复制评论";
"Text Copied" = "复制成功!";
"post_tags_exceed_limit" = "至多一个主标签与一个副标签!";
"latest_sort_discussion" = "最新帖子";
Expand All @@ -82,4 +82,13 @@
"days later" = "%d 天后";
"hours later" = "%d 小时后";
"minutes later" = "%d 分钟后";
"very soon" = "马上";
"very soon" = "几秒后";
"like_in_contextMenu" = "点赞这条评论";
"pay_to_read_message" = "支付量见币购买";
"tabbar_operations" = "选项";
"choose_to_quit" = "退出登录";
"start_new_discussion_message" = "发表新帖";
"profile_operations" = "选项";
"hot_discussions" = "热门帖子";
"old_discussions" = "陈年旧帖";
"frontPage_discussions" = "精华帖子";
2 changes: 1 addition & 1 deletion LiangJianForum/Model/DiscussionData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct DatumAttributes: Codable, Hashable {
let isSticky: Bool
let isLocked: Bool
let hasPoll: Bool?
let hasBestAnswer: HasBestAnswer
let hasBestAnswer: HasBestAnswer?
let frontpage: Bool?
// let canReply, canRename, canDelete, canHide: Bool
// let isApproved: Bool
Expand Down
38 changes: 38 additions & 0 deletions LiangJianForum/Model/MoneyData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse the JSON, add this file to your project and do:
//
// let moneyData = try? JSONDecoder().decode(MoneyData.self, from: jsonData)

import Foundation

// MARK: - MoneyData
struct MoneyData: Codable, Hashable {
let data: [Datum10]
}

// MARK: - Datum
struct Datum10: Codable, Hashable {
let type: String
let id: String
let attributes: Attributes10
}

// MARK: - Attributes
struct Attributes10: Codable, Hashable {
let id: Int
let money: Double
let userID: Int
let createTime: String
let targetID, actorID: Int
let data, reason: String

enum CodingKeys: String, CodingKey {
case id, money
case userID = "user_id"
case createTime = "create_time "
case targetID = "target_id"
case actorID = "actor_id"
case data, reason
}
}

20 changes: 10 additions & 10 deletions LiangJianForum/Model/TagsData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct Datum6: Codable, Hashable {
let type: String
let id: String
let attributes: Attributes6
// let relationships: Relationships6?
let relationships: Relationships6?
}

// MARK: - Attributes
Expand All @@ -34,15 +34,15 @@ struct Attributes6: Codable, Hashable {
}
}

//// MARK: - Relationships
//struct Relationships6: Codable {
// let parent: Parent6
//}
//
//// MARK: - Parent
//struct Parent6: Codable {
// let data: DataClass6
//}
// MARK: - Relationships
struct Relationships6: Codable, Hashable {
let parent: Parent6
}

// MARK: - Parent
struct Parent6: Codable, Hashable {
let data: DataClass6
}

// MARK: - DataClass
struct DataClass6: Codable, Hashable {
Expand Down
5 changes: 3 additions & 2 deletions LiangJianForum/Model/UserData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ struct Attributes2: Codable {
}

// MARK: - UserInclude
struct UserInclude: Codable {
struct UserInclude: Codable, Hashable {
let type, id: String
let attributes: Attributes
}

// MARK: - Attributes
struct Attributes: Codable {
struct Attributes: Codable, Hashable {
let nameSingular, namePlural, color, icon: String?
let isHidden: Int?
let name: String?
let description: String?
let backgroundColor: String?
}

32 changes: 29 additions & 3 deletions LiangJianForum/View/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,46 @@ struct ContentView: View {

NoticeView()
.tabItem { Label("Message", systemImage: "bell.fill") }
.tag(Tab.notice)

ProfileView()
.tabItem { Label("Me", systemImage: "person.crop.rectangle.stack") }
.tag(Tab.profile)
}
.onAppear{
Task{
await retrieveCurrentUserInformation()
}
}
.environmentObject(appsettings)
} else {
LoginPageView()
.environmentObject(appsettings)
}
}

private func retrieveCurrentUserInformation() async {
guard let url = URL(string: "\(appsettings.FlarumUrl)/api/users/\(appsettings.userId)") else{
print("Invalid URL")
return
}
print("Fetching User Info : id \(appsettings.userId) at: \(url)")

do{
let (data, _) = try await URLSession.shared.data(from: url)

if let decodedResponse = try? JSONDecoder().decode(UserData.self, from: data){
appsettings.username = decodedResponse.data.attributes.username
appsettings.displayName = decodedResponse.data.attributes.displayName

if let avatarUrl = decodedResponse.data.attributes.avatarURL{
appsettings.avatarUrl = avatarUrl
}
}
} catch {
print("Invalid user Data!" ,error)
}
}
}

//#Preview {
// ContentView()
//}

7 changes: 7 additions & 0 deletions LiangJianForum/View/Helper/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ class AppSettings: ObservableObject {
@Published var FlarumName = "量见"
@Published var token = ""
@Published var username = ""
@Published var displayName = ""
@Published var avatarUrl = ""
@Published var userId = 0
@Published var vipUsernames: [String] = []

init() {
vipUsernames.append(contentsOf: ["RomanticD"])
}

func refreshPost() {
refreshPostView.toggle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,53 @@ public func removeFirstCharacter(from colorString: String) -> String {
let index = colorString.index(after: colorString.startIndex)
return String(colorString[index...])
}

func getParentTagsFromFetching(from tags : [Datum6]) -> [Datum6]{
var parentTags = [Datum6]()

for item in tags{
if !item.attributes.isChild{
parentTags.append(item)
}
}
return parentTags
}

func getChildTags(parentTag : Datum6, dataFetched: [Datum6]) -> [Datum6]{
var childTags = [Datum6]()
let parentTagId = parentTag.id

for item in getChildTagsFromFetching(from: dataFetched){
if let targetTagId = item.relationships?.parent.data.id{
if targetTagId == parentTagId{
childTags.append(item)
}
}
}
return childTags
}

func getChildTagsFromFetching(from tags : [Datum6]) -> [Datum6]{
var childTags = [Datum6]()

for item in tags{
if item.attributes.isChild{
childTags.append(item)
}
}
return childTags
}

func getChildTagsId(parentTag : Datum6, dataFetched : [Datum6]) -> [String]? {
var childTagsIds = [String]()
let parentTagId = parentTag.id

for childTag in getChildTagsFromFetching(from: dataFetched){
if let targetTagId = childTag.relationships?.parent.data.id{
if targetTagId == parentTagId{
childTagsIds.append(childTag.id)
}
}
}
return childTagsIds
}
9 changes: 4 additions & 5 deletions LiangJianForum/View/Login/LoginPageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@ struct LoginPageView: View {
}) {
Text("Sign in")
.fontWeight(.bold)
.foregroundColor(.white)
.frame(width: 350, height: 50)
.background(Color.blue)
.cornerRadius(10)
}

.foregroundColor(.white)
.frame(width: 350, height: 50)
.background(Color.blue)
.cornerRadius(10)
.opacity(isAnimating ? 0.9 : 0)
.animation(.easeInOut(duration: 1.5), value: isAnimating)
.onDisappear {
Expand Down
Loading

0 comments on commit ddf9152

Please sign in to comment.