]> Untitled Git - lemmy-ui.git/commitdiff
Merge branch 'main' into nicer-error-hnadling
authorabias <abias1122@gmail.com>
Tue, 16 May 2023 00:34:45 +0000 (20:34 -0400)
committerabias <abias1122@gmail.com>
Tue, 16 May 2023 00:34:45 +0000 (20:34 -0400)
1  2 
package.json
src/shared/components/app/navbar.tsx
src/shared/components/person/inbox.tsx
src/shared/components/person/registration-applications.tsx
src/shared/components/person/reports.tsx
src/shared/utils.ts
yarn.lock

diff --combined package.json
index 0315416027d1af803bd2bd8fdc3ccdb315d5cdb3,2f16b8d3797fc72970f25074a864492d7645fc61..8ad258d8cb3a3c0890ed5bcc5e09b31d53d4a4bb
@@@ -60,8 -60,7 +60,8 @@@
      "inferno-server": "^8.1.1",
      "isomorphic-cookie": "^1.2.4",
      "jwt-decode": "^3.1.2",
-     "lemmy-js-client": "0.17.2-rc.15",
+     "lemmy-js-client": "0.17.2-rc.17",
 +    "lodash": "^4.17.21",
      "markdown-it": "^13.0.1",
      "markdown-it-container": "^3.0.0",
      "markdown-it-emoji": "^2.0.2",
@@@ -78,7 -77,6 +78,7 @@@
      "sass": "^1.62.1",
      "sass-loader": "^13.2.2",
      "serialize-javascript": "^6.0.1",
 +    "service-worker-webpack": "^1.0.0",
      "sharp": "^0.32.1",
      "tippy.js": "^6.3.7",
      "toastify-js": "^1.12.0",
      "prettier-plugin-organize-imports": "^3.2.2",
      "prettier-plugin-packagejson": "^2.4.3",
      "rimraf": "^5.0.0",
 -    "service-worker-webpack": "^1.0.0",
      "sortpack": "^2.3.4",
      "style-loader": "^3.3.2",
      "terser": "^5.17.3",
index 981d6413429f89d4c5c408c331673dd9aceb6cb9,128d40238cebd9695004476939660b4904692859..d92ec259443f144987968190c81e3d56514a030f
@@@ -35,14 -35,14 +35,14 @@@ import { Icon } from "../common/icon"
  import { PictrsImage } from "../common/pictrs-image";
  
  interface NavbarProps {
 -  siteRes: GetSiteResponse;
 +  siteRes?: GetSiteResponse;
  }
  
  interface NavbarState {
    expanded: boolean;
-   unreadInboxCount: bigint;
-   unreadReportCount: bigint;
-   unreadApplicationCount: bigint;
+   unreadInboxCount: number;
+   unreadReportCount: number;
+   unreadApplicationCount: number;
    showDropdown: boolean;
    onSiteBanner?(url: string): any;
  }
@@@ -54,9 -54,9 +54,9 @@@ export class Navbar extends Component<N
    private unreadReportCountSub: Subscription;
    private unreadApplicationCountSub: Subscription;
    state: NavbarState = {
-     unreadInboxCount: 0n,
-     unreadReportCount: 0n,
-     unreadApplicationCount: 0n,
+     unreadInboxCount: 0,
+     unreadReportCount: 0,
+     unreadApplicationCount: 0,
      expanded: false,
      showDropdown: false,
    };
  
    // TODO class active corresponding to current page
    navbar() {
 -    let siteView = this.props.siteRes.site_view;
 +    let siteView = this.props.siteRes?.site_view;
      let person = UserService.Instance.myUserInfo?.local_user_view.person;
      return (
        <nav className="navbar navbar-expand-md navbar-light shadow-sm p-0 px-3">
            <NavLink
              to="/"
              onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
 -            title={siteView.site.description ?? siteView.site.name}
 +            title={siteView?.site.description ?? siteView?.site.name ?? "Lemmy"}
              className="d-flex align-items-center navbar-brand mr-md-3"
            >
 -            {siteView.site.icon && showAvatars() && (
 +            {siteView?.site.icon && showAvatars() && (
                <PictrsImage src={siteView.site.icon} icon />
              )}
 -            {siteView.site.name}
 +            {siteView?.site.name ?? "Lemmy"}
            </NavLink>
            {UserService.Instance.myUserInfo && (
              <>
                    {i18n.t("create_post")}
                  </NavLink>
                </li>
 -              {canCreateCommunity(this.props.siteRes) && (
 +              {this.props.siteRes && canCreateCommunity(this.props.siteRes) && (
                  <li className="nav-item">
                    <NavLink
                      to="/create_community"
          unreadReportCount:
            data.post_reports +
            data.comment_reports +
-           (data.private_message_reports ?? 0n),
+           (data.private_message_reports ?? 0),
        });
        this.sendReportUnread();
      } else if (op == UserOperation.GetUnreadRegistrationApplicationCount) {
          data.recipient_ids.includes(mui.local_user_view.local_user.id)
        ) {
          this.setState({
-           unreadInboxCount: this.state.unreadInboxCount + 1n,
+           unreadInboxCount: this.state.unreadInboxCount + 1,
          });
          this.sendUnreadCount();
          notifyComment(data.comment_view, this.context.router);
          UserService.Instance.myUserInfo?.local_user_view.person.id
        ) {
          this.setState({
-           unreadInboxCount: this.state.unreadInboxCount + 1n,
+           unreadInboxCount: this.state.unreadInboxCount + 1,
          });
          this.sendUnreadCount();
          notifyPrivateMessage(data.private_message_view, this.context.router);
index 3c3e9484db5de5dfd6d8ced0547211750377dd5e,a39977917480aa13c8713abc0ff2fa8e12d65338..8145ab62af58a5c109fef7a96c4460ad42a8dff4
@@@ -84,7 -84,7 +84,7 @@@ interface InboxState 
    messages: PrivateMessageView[];
    combined: ReplyType[];
    sort: CommentSortType;
-   page: bigint;
+   page: number;
    siteRes: GetSiteResponse;
    loading: boolean;
  }
@@@ -100,7 -100,7 +100,7 @@@ export class Inbox extends Component<an
      messages: [],
      combined: [],
      sort: "New",
-     page: 1n,
+     page: 1,
      siteRes: this.isoData.site_res,
      loading: true,
    };
      this.handleSortChange = this.handleSortChange.bind(this);
      this.handlePageChange = this.handlePageChange.bind(this);
  
 -    if (!UserService.Instance.myUserInfo && isBrowser()) {
 -      toast(i18n.t("not_logged_in"), "danger");
 -      this.context.router.history.push(`/login`);
 -    }
 -
      this.parseMessage = this.parseMessage.bind(this);
      this.subscription = wsSubscribe(this.parseMessage);
  
      );
    }
  
-   handlePageChange(page: bigint) {
+   handlePageChange(page: number) {
      this.setState({ page });
      this.refetch();
    }
  
    handleUnreadOrAllChange(i: Inbox, event: any) {
-     i.setState({ unreadOrAll: Number(event.target.value), page: 1n });
+     i.setState({ unreadOrAll: Number(event.target.value), page: 1 });
      i.refetch();
    }
  
    handleMessageTypeChange(i: Inbox, event: any) {
-     i.setState({ messageType: Number(event.target.value), page: 1n });
+     i.setState({ messageType: Number(event.target.value), page: 1 });
      i.refetch();
    }
  
        let repliesForm: GetReplies = {
          sort: "New",
          unread_only: true,
-         page: 1n,
+         page: 1,
          limit: fetchLimit,
          auth,
        };
        let personMentionsForm: GetPersonMentions = {
          sort,
          unread_only: true,
-         page: 1n,
+         page: 1,
          limit: fetchLimit,
          auth,
        };
  
        let privateMessagesForm: GetPrivateMessages = {
          unread_only: true,
-         page: 1n,
+         page: 1,
          limit: fetchLimit,
          auth,
        };
    }
  
    handleSortChange(val: CommentSortType) {
-     this.setState({ sort: val, page: 1n });
+     this.setState({ sort: val, page: 1 });
      this.refetch();
    }
  
        );
        i.setState({ replies: [], mentions: [], messages: [] });
        i.setState({ combined: i.buildCombined() });
-       UserService.Instance.unreadInboxCountSub.next(0n);
+       UserService.Instance.unreadInboxCountSub.next(0);
        window.scrollTo(0, 0);
        i.setState(i.state);
      }
    sendUnreadCount(read: boolean) {
      let urcs = UserService.Instance.unreadInboxCountSub;
      if (read) {
-       urcs.next(urcs.getValue() - 1n);
+       urcs.next(urcs.getValue() - 1);
      } else {
-       urcs.next(urcs.getValue() + 1n);
+       urcs.next(urcs.getValue() + 1);
      }
    }
  
index b25c406a4e5d893aec287326b551f4e380ac1aa6,181674121ba1cd81b73ff1820e31e544cb889784..39b659000c940e188acc4fc98386716d4a48f046
@@@ -37,7 -37,7 +37,7 @@@ interface RegistrationApplicationsStat
    listRegistrationApplicationsResponse?: ListRegistrationApplicationsResponse;
    siteRes: GetSiteResponse;
    unreadOrAll: UnreadOrAll;
-   page: bigint;
+   page: number;
    loading: boolean;
  }
  
@@@ -50,7 -50,7 +50,7 @@@ export class RegistrationApplications e
    state: RegistrationApplicationsState = {
      siteRes: this.isoData.site_res,
      unreadOrAll: UnreadOrAll.Unread,
-     page: 1n,
+     page: 1,
      loading: true,
    };
  
  
      this.handlePageChange = this.handlePageChange.bind(this);
  
 -    if (!UserService.Instance.myUserInfo && isBrowser()) {
 -      toast(i18n.t("not_logged_in"), "danger");
 -      this.context.router.history.push(`/login`);
 -    }
 -
      this.parseMessage = this.parseMessage.bind(this);
      this.subscription = wsSubscribe(this.parseMessage);
  
    }
  
    handleUnreadOrAllChange(i: RegistrationApplications, event: any) {
-     i.setState({ unreadOrAll: Number(event.target.value), page: 1n });
+     i.setState({ unreadOrAll: Number(event.target.value), page: 1 });
      i.refetch();
    }
  
-   handlePageChange(page: bigint) {
+   handlePageChange(page: number) {
      this.setState({ page });
      this.refetch();
    }
      if (auth) {
        let form: ListRegistrationApplications = {
          unread_only: true,
-         page: 1n,
+         page: 1,
          limit: fetchLimit,
          auth,
        };
        );
        let uacs = UserService.Instance.unreadApplicationCountSub;
        // Minor bug, where if the application switches from deny to approve, the count will still go down
-       uacs.next(uacs.getValue() - 1n);
+       uacs.next(uacs.getValue() - 1);
        this.setState(this.state);
      }
    }
index f4fc5a1c016c8dc2d57691e911af58fd2f8f01f3,0af56b53bf13809dad421ebb798b109a09f5338a..3c00f545484b8b1faa288c0e04dc6352870f1013
@@@ -75,7 -75,7 +75,7 @@@ interface ReportsState 
    messageType: MessageType;
    combined: ItemType[];
    siteRes: GetSiteResponse;
-   page: bigint;
+   page: number;
    loading: boolean;
  }
  
@@@ -86,7 -86,7 +86,7 @@@ export class Reports extends Component<
      unreadOrAll: UnreadOrAll.Unread,
      messageType: MessageType.All,
      combined: [],
-     page: 1n,
+     page: 1,
      siteRes: this.isoData.site_res,
      loading: true,
    };
  
      this.handlePageChange = this.handlePageChange.bind(this);
  
 -    if (!UserService.Instance.myUserInfo && isBrowser()) {
 -      toast(i18n.t("not_logged_in"), "danger");
 -      this.context.router.history.push(`/login`);
 -    }
 -
      this.parseMessage = this.parseMessage.bind(this);
      this.subscription = wsSubscribe(this.parseMessage);
  
      );
    }
  
-   handlePageChange(page: bigint) {
+   handlePageChange(page: number) {
      this.setState({ page });
      this.refetch();
    }
  
    handleUnreadOrAllChange(i: Reports, event: any) {
-     i.setState({ unreadOrAll: Number(event.target.value), page: 1n });
+     i.setState({ unreadOrAll: Number(event.target.value), page: 1 });
      i.refetch();
    }
  
    handleMessageTypeChange(i: Reports, event: any) {
-     i.setState({ messageType: Number(event.target.value), page: 1n });
+     i.setState({ messageType: Number(event.target.value), page: 1 });
      i.refetch();
    }
  
      let promises: Promise<any>[] = [];
  
      let unresolved_only = true;
-     let page = 1n;
+     let page = 1;
      let limit = fetchLimit;
      let auth = req.auth;
  
        );
        let urcs = UserService.Instance.unreadReportCountSub;
        if (data.post_report_view.post_report.resolved) {
-         urcs.next(urcs.getValue() - 1n);
+         urcs.next(urcs.getValue() - 1);
        } else {
-         urcs.next(urcs.getValue() + 1n);
+         urcs.next(urcs.getValue() + 1);
        }
        this.setState(this.state);
      } else if (op == UserOperation.ResolveCommentReport) {
        );
        let urcs = UserService.Instance.unreadReportCountSub;
        if (data.comment_report_view.comment_report.resolved) {
-         urcs.next(urcs.getValue() - 1n);
+         urcs.next(urcs.getValue() - 1);
        } else {
-         urcs.next(urcs.getValue() + 1n);
+         urcs.next(urcs.getValue() + 1);
        }
        this.setState(this.state);
      } else if (op == UserOperation.ResolvePrivateMessageReport) {
        );
        let urcs = UserService.Instance.unreadReportCountSub;
        if (data.private_message_report_view.private_message_report.resolved) {
-         urcs.next(urcs.getValue() - 1n);
+         urcs.next(urcs.getValue() - 1);
        } else {
-         urcs.next(urcs.getValue() + 1n);
+         urcs.next(urcs.getValue() + 1);
        }
        this.setState(this.state);
      }
diff --combined src/shared/utils.ts
index 5a39b94c5b8a4e29beb8e9130181fab98e794005,b5b39c4f9a507e1cd2d2cbd67291d9b43e03daf1..54002ec2bc55695c1681c6f9cf0bf2e56548111f
@@@ -70,12 -70,12 +70,12 @@@ export const webArchiveUrl = "https://w
  export const elementUrl = "https://element.io";
  
  export const postRefetchSeconds: number = 60 * 1000;
- export const fetchLimit = 40n;
- export const trendingFetchLimit = 6n;
+ export const fetchLimit = 40;
+ export const trendingFetchLimit = 6;
  export const mentionDropdownFetchLimit = 10;
  export const commentTreeMaxDepth = 8;
  export const markdownFieldCharacterLimit = 50000;
- export const maxUploadImages = 20n;
+ export const maxUploadImages = 20;
  export const concurrentImageUpload = 4;
  
  export const relTags = "noopener nofollow";
@@@ -105,12 -105,6 +105,12 @@@ export type ThemeColor 
    | "gray"
    | "gray-dark";
  
 +export interface ErrorPageData {
 +  type: "error";
 +  error?: string;
 +  adminMatrixIds?: string[];
 +}
 +
  let customEmojis: EmojiMartCategory[] = [];
  export let customEmojisLookup: Map<string, CustomEmojiView> = new Map<
    string,
@@@ -128,8 -122,8 +128,8 @@@ export function getIdFromString(id?: st
    return id && id !== "0" && !Number.isNaN(Number(id)) ? Number(id) : undefined;
  }
  
- export function getPageFromString(page?: string): bigint {
-   return page && !Number.isNaN(Number(page)) ? BigInt(page) : BigInt(1);
+ export function getPageFromString(page?: string): number {
+   return page && !Number.isNaN(Number(page)) ? Number(page) : 1;
  }
  
  export function randomStr(
@@@ -191,14 -185,14 +191,14 @@@ export function hotRankPost(post_view: 
    return hotRank(post_view.counts.score, post_view.post.published);
  }
  
- export function hotRank(score: bigint, timeStr: string): number {
+ export function hotRank(score: number, timeStr: string): number {
    // Rank = ScaleFactor * sign(Score) * log(1 + abs(Score)) / (Time + 2)^Gravity
    let date: Date = new Date(timeStr + "Z"); // Add Z to convert from UTC date
    let now: Date = new Date();
    let hoursElapsed: number = (now.getTime() - date.getTime()) / 36e5;
  
    let rank =
-     (10000 * Math.log10(Math.max(1, Number(3n + score)))) /
+     (10000 * Math.log10(Math.max(1, 3 + Number(score)))) /
      Math.pow(hoursElapsed + 2, 1.8);
  
    // console.log(`Comment: ${comment.content}\nRank: ${rank}\nScore: ${comment.score}\nHours: ${hoursElapsed}`);
@@@ -218,16 -212,14 +218,14 @@@ export function mdToHtmlInline(text: st
    return { __html: md.renderInline(text) };
  }
  
- export function getUnixTime(text?: string): bigint | undefined {
-   return text ? BigInt(new Date(text).getTime() / 1000) : undefined;
+ export function getUnixTime(text?: string): number | undefined {
+   return text ? new Date(text).getTime() / 1000 : undefined;
  }
  
- export function futureDaysToUnixTime(days?: number): bigint | undefined {
+ export function futureDaysToUnixTime(days?: number): number | undefined {
    return days
-     ? BigInt(
-         Math.trunc(
-           new Date(Date.now() + 1000 * 60 * 60 * 24 * days).getTime() / 1000
-         )
+     ? Math.trunc(
+         new Date(Date.now() + 1000 * 60 * 60 * 24 * days).getTime() / 1000
        )
      : undefined;
  }
@@@ -1364,7 -1356,7 +1362,7 @@@ export async function fetchCommunities(
      type_: "Communities",
      sort: "TopAll",
      listing_type: "All",
-     page: 1n,
+     page: 1,
      limit: fetchLimit,
      auth: myAuth(false),
    };
@@@ -1378,7 -1370,7 +1376,7 @@@ export async function fetchUsers(q: str
      type_: "Users",
      sort: "TopAll",
      listing_type: "All",
-     page: 1n,
+     page: 1,
      limit: fetchLimit,
      auth: myAuth(false),
    };
@@@ -1399,12 -1391,10 +1397,12 @@@ export function personSelectName(
    return local ? pName : `${hostname(actor_id)}/${pName}`;
  }
  
 -export function initializeSite(site: GetSiteResponse) {
 -  UserService.Instance.myUserInfo = site.my_user;
 +export function initializeSite(site?: GetSiteResponse) {
 +  UserService.Instance.myUserInfo = site?.my_user;
    i18n.changeLanguage(getLanguages()[0]);
 -  setupEmojiDataModel(site.custom_emojis);
 +  if (site) {
 +    setupEmojiDataModel(site.custom_emojis);
 +  }
    setupMarkdown();
  }
  
@@@ -1415,7 -1405,7 +1413,7 @@@ const SHORTNUM_SI_FORMAT = new Intl.Num
    compactDisplay: "short",
  });
  
- export function numToSI(value: bigint): string {
+ export function numToSI(value: number): string {
    return SHORTNUM_SI_FORMAT.format(value);
  }
  
diff --combined yarn.lock
index 8291f2808c82e831ec17d3db27349586190f03b7,24b8a351c8b3c6a8616f2158b60152d8584ade4a..7c2a7124c35eddb2c50f0725c19b8c9209c05e20
+++ b/yarn.lock
@@@ -5334,10 -5334,10 +5334,10 @@@ leac@^0.6.0
    resolved "https://registry.yarnpkg.com/leac/-/leac-0.6.0.tgz#dcf136e382e666bd2475f44a1096061b70dc0912"
    integrity sha512-y+SqErxb8h7nE/fiEX07jsbuhrpO9lL8eca7/Y1nuWV2moNlXhyd59iDGcRf6moVyDMbmTNzL40SUyrFU/yDpg==
  
- lemmy-js-client@0.17.2-rc.15:
-   version "0.17.2-rc.15"
-   resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.15.tgz#a3b10227913c4dc12fa7b69cdc777e429d030721"
-   integrity sha512-hnHW/570mQGoGNdnUaNp20+KVkyUnosaFLmWxlZyyhL7fiSbcIXM+GXsjTCqmc1JEnqASc6MdMMpYuZaBKVQtQ==
+ lemmy-js-client@0.17.2-rc.17:
+   version "0.17.2-rc.17"
+   resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.17.tgz#91a167c3b61db39fab2e977685a42a77aeae519a"
+   integrity sha512-DBzQjVRo89co7Wppl72/xlNdJfAnXrUE0UgWZxO3v2I8axK9JUD4XmodpRe33thpfPmsURQ1W7dOUX60rcQPQg==
    dependencies:
      cross-fetch "^3.1.5"
      form-data "^4.0.0"
@@@ -5546,7 -5546,7 +5546,7 @@@ lodash@^3.10.1
    resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
    integrity sha512-9mDDwqVIma6OZX79ZlDACZl8sBm0TEnkf99zV3iMA4GzkIT/9hiqP5mY0HoT1iNLCrKc/R1HByV+yJfRWVJryQ==
  
 -lodash@^4.17.20:
 +lodash@^4.17.20, lodash@^4.17.21:
    version "4.17.21"
    resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
    integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==