Skip to content

Commit

Permalink
Merge pull request #449 from MissAllSunday/pest
Browse files Browse the repository at this point in the history
Remove prophecy package
  • Loading branch information
MissAllSunday authored Sep 23, 2024
2 parents b40af89 + d2705eb commit 2bc71e9
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 247 deletions.
2 changes: 1 addition & 1 deletion Sources/Breeze/Breeze.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Breeze
public const SUPPORT_URL = 'https://missallsunday.com';
public const REACT_DOM_VERSION = '18.2.0';
public const REACT_VERSION = '18.2.0';
public const REACT_HASH = 'f427d2ac';
public const REACT_HASH = '31135802';
public const ACTIONS = [
'breezeStatus',
'breezeComment',
Expand Down
3 changes: 2 additions & 1 deletion Sources/Breeze/Controller/API/LikesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public function like(): void
$this->data[LikeEntity::COLUMN_TYPE],
$this->data[LikeEntity::COLUMN_ID],
$this->data[LikeEntity::COLUMN_ID_MEMBER]
)
),
Response::CREATED
);
} catch (InvalidDataException $invalidDataException) {
$this->response->error($invalidDataException->getMessage(), $invalidDataException->getResponseCode());
Expand Down
19 changes: 18 additions & 1 deletion Themes/default/css/breeze.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ div.link_compact{
display: inline-block;
}

div.avatar_compact img.avatar {
div.avatar_compact img {
width: 30px;
height: 30px;
vertical-align:middle;
Expand All @@ -64,6 +64,23 @@ div.avatar_compact img.avatar {

.post_content {
min-width: 70%;
padding-bottom: 5px;
}

.post_content textarea {
outline: none;
min-height: 45px;
width: calc(100% - 45px);
resize: none;
}

.comment_posting img {
min-height: 35px;
max-height: 45px;
float: left;
max-width: 40px;
margin-right: 5px;
vertical-align: middle;
}

.pointer_cursor {
Expand Down
9 changes: 3 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@
},
"require-dev": {
"roave/security-advisories": "dev-latest",
"phpunit/phpunit": "^11.1",
"phpspec/prophecy": "^1.18",
"friendsofphp/php-cs-fixer": "^3.50",
"phpstan/phpstan": "^1.10.0",
"phpstan/phpstan-phpunit": "^1.3.0",
"phpspec/prophecy-phpunit": "^2.1.0"
"friendsofphp/php-cs-fixer": "^3.50",
"phpstan/phpstan": "^1.10.0",
"phpunit/phpunit": "^11.1"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 4 additions & 8 deletions src/Wall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StatusListType, StatusType } from 'breezeTypesStatus';
import React, { useCallback, useEffect, useState } from 'react';
import { Toaster } from 'react-hot-toast';

import { IServerFetchResponse } from './api/Api';
import { IFetchStatus } from './api/Api';
import {
deleteStatus,
getStatus, postStatus,
Expand All @@ -15,7 +15,7 @@ import Status from './components/Status';
import { PermissionsContext } from './context/PermissionsContext';
import PermissionsDefault from './DataSource/Permissions';
import smfTextVars from './DataSource/Txt';
import { showError, showInfo } from './utils/tooltip';
import { showInfo } from './utils/tooltip';

export default function Wall(props: WallProps): React.JSX.Element {
const [statusList, setStatusList] = useState<StatusListType>([]);
Expand All @@ -29,11 +29,7 @@ export default function Wall(props: WallProps): React.JSX.Element {

useEffect(() => {
getStatus(props.wallType, 0)
.then((statusListResponse: IServerFetchResponse) => {
if (typeof statusListResponse === 'undefined') {
return;
}

.then((statusListResponse: IFetchStatus) => {
const fetchedStatusList: StatusListType = Object.values(statusListResponse.data);
setStatusList(fetchedStatusList);
setPermissions(statusListResponse.permissions);
Expand All @@ -53,7 +49,7 @@ export default function Wall(props: WallProps): React.JSX.Element {
setIsLoading(true);

getStatus(props.wallType, statusList.length)
.then((statusListResponse: IServerFetchResponse) => {
.then((statusListResponse: IFetchStatus) => {
setStatusList(statusList.concat(Object.values(statusListResponse.data)));
}).finally(() => {
setIsLoading(false);
Expand Down
26 changes: 12 additions & 14 deletions src/api/Api.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { CommentListType } from 'breezeTypesComments';
import { LikeInfoState, LikeType } from 'breezeTypesLikes';
import { PermissionsContextType } from 'breezeTypesPermissions';
import { StatusListType } from 'breezeTypesStatus';

import SmfVars from '../DataSource/SMF';
import { showErrorMessage, showInfo } from '../utils/tooltip';
import { showError, showInfo } from '../utils/tooltip';

export const baseUrl = (action: string, subAction: string, additionalParams: object[] = []): string => {
const url = new URL(SmfVars.scriptUrl);
Expand All @@ -29,26 +31,22 @@ export const baseConfig = (params: object = {}): object => ({
},
});

export interface IServerFetchResponse {

export interface IFetchStatus {
data: StatusListType,
permissions: PermissionsContextType,
total: number
}
export interface IServerPostResponse {
content: StatusListType
message: string
type: string
}

export const safeFetch = async (response: Response):Promise<IServerFetchResponse | void> => {
export const safeFetch = async (response: Response):Promise<IFetchStatus | Array<LikeInfoState> | void> => {
const { content, message } = await response.json();

if (response.ok && response.status === 200) {
return content;
if (message.length) {
showError(message);
}

if (message.length) {
showErrorMessage(message);
if (response.ok && response.status === 200) {
return content;
}
};

Expand All @@ -58,15 +56,15 @@ export const safeDelete = async (response: Response, successMessage: string):Pro

if (!deleted) {
const { message } = await response.json();
showErrorMessage(message);
showError(message);
} else {
showInfo(successMessage);
}

return deleted;
};

export const safePost = async (response: Response):Promise<IServerPostResponse | void> => {
export const safePost = async (response: Response):Promise<StatusListType | CommentListType | LikeType | void> => {
const { content, message } = await response.json();

if (response.ok && response.status === 201) {
Expand Down
38 changes: 16 additions & 22 deletions src/api/CommentApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,25 @@ import { CommentListType } from 'breezeTypesComments';
import { IServerActions } from '../customTypings/actions';
import smfVars from '../DataSource/SMF';
import smfTextVars from '../DataSource/Txt';
import { showError, showErrorMessage, showInfo } from '../utils/tooltip';
import { baseConfig, baseUrl, safeDelete } from './Api';

export interface ServerCommentData {
message: string
content: CommentListType
}

interface ServerDeleteComment {
message: string
content: object
}
import { showError } from '../utils/tooltip';
import { baseConfig, baseUrl, safeDelete, safePost } from './Api';

const action:IServerActions = 'breezeComment';

export const postComment = async (commentParams: object): Promise<ServerCommentData> => {
const postCommentResults = await fetch(baseUrl(action, 'postComment'), {
method: 'POST',
body: JSON.stringify(baseConfig({
...commentParams,
userId: smfVars.userId,
})),
});

return postCommentResults.ok ? postCommentResults.json() : showError(postCommentResults);
export const postComment = async (commentParams: object): Promise<CommentListType> => {
try {
const postCommentResults = await fetch(baseUrl(action, 'postComment'), {
method: 'POST',
body: JSON.stringify(baseConfig({
...commentParams,
userId: smfVars.userId,
})),
});

return await safePost(postCommentResults);
} catch (error:unknown) {
showError(smfTextVars.error.generic);
}
};

export const deleteComment = async (commentId: number): Promise<boolean> => {
Expand Down
68 changes: 42 additions & 26 deletions src/api/LikeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { LikeInfoState, LikeType } from 'breezeTypesLikes';

import { IServerActions } from '../customTypings/actions';
import SmfVars from '../DataSource/SMF';
import smfTextVars from '../DataSource/Txt';
import { showError } from '../utils/tooltip';
import { baseConfig, baseUrl } from './Api';
import { baseConfig, baseUrl, safeFetch, safePost } from './Api';

export interface ServerLikeData {
content: LikeType
Expand All @@ -15,33 +16,48 @@ export interface ServerLikeInfoData {
content: LikeInfoState[]
}

const action:IServerActions = 'breezeLike';

export const postLike = async (likeData: LikeType): Promise<ServerLikeData> => {
const params = {
id_member: SmfVars.userId,
content_type: likeData.type,
content_id: likeData.contentId,
};
export interface IPostLikeParams {
id_member: number;
content_type: string;
content_id: number;
}

const likeResults = await fetch(baseUrl(action, 'like'), {
method: 'POST',
body: JSON.stringify(baseConfig(params)),
});
const action:IServerActions = 'breezeLike';

return likeResults.json();
export const postLike = async (likeData: LikeType): Promise<any> => {
try {
const params:IPostLikeParams = {
id_member: SmfVars.userId,
content_type: likeData.type,
content_id: likeData.contentId,
};

const likeResults = await fetch(baseUrl(action, 'like'), {
method: 'POST',
body: JSON.stringify(baseConfig(params)),
});

return await safePost(likeResults);
} catch (error:unknown) {
showError(smfTextVars.error.generic);
}
};

export const getLikeInfo = async (like: LikeType): Promise<ServerLikeInfoData> => {
const params = {
content_type: like.type,
content_id: like.contentId,
};

const likeInfoResults = await fetch(baseUrl(action, 'info'), {
method: 'POST',
body: JSON.stringify(baseConfig(params)),
});

return likeInfoResults.ok ? likeInfoResults.json() : showError(likeInfoResults);
export const getLikeInfo = async (like: LikeType):Promise<any> => {
try {
const params = {
content_type: like.type,
content_id: like.contentId,
};
const response = await fetch(baseUrl(action, 'info', [ params ]), {
method: 'GET',
headers: {
'X-SMF-AJAX': '1',
},
});

return await safeFetch(response);
} catch (error:unknown) {
showError(smfTextVars.error.generic);
}
};
9 changes: 4 additions & 5 deletions src/api/StatusApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { StatusListType } from 'breezeTypesStatus';
import { IServerActions } from '../customTypings/actions';
import smfVars from '../DataSource/SMF';
import smfTextVars from '../DataSource/Txt';
import { showError, showErrorMessage, showInfo } from '../utils/tooltip';
import { showError } from '../utils/tooltip';
import { baseConfig, baseUrl, safeDelete, safeFetch, safePost } from './Api';

const action:IServerActions = 'breezeStatus';

export const getStatus = async (type: string, start: number): Promise<StatusListType> => {
export const getStatus = async (type: string, start: number): Promise<any | void> => {
try {
const response = await fetch(baseUrl(action, type, [ { start: start, wallId: smfVars.wallId } ]), {
method: 'GET',
Expand All @@ -18,9 +18,8 @@ export const getStatus = async (type: string, start: number): Promise<StatusList
});

return await safeFetch(response);

} catch (error:unknown) {
showErrorMessage(smfTextVars.error.generic);
showError(smfTextVars.error.generic);
}
};

Expand Down Expand Up @@ -49,6 +48,6 @@ export const postStatus = async (content: string): Promise<StatusListType> => {

return await safePost(response);
} catch (error:unknown) {
showErrorMessage(smfTextVars.error.generic);
showError(smfTextVars.error.generic);
}
};
6 changes: 3 additions & 3 deletions src/components/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { createElement, ReactElement, useCallback, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';

import smfVars from '../DataSource/SMF';
import smfTextVars from '../DataSource/Txt';
import { showErrorMessage } from '../utils/tooltip';
import { showError } from '../utils/tooltip';

const Editor: React.FunctionComponent<any> = (props: { saveContent: (content: string) => boolean, isFull: boolean }) => {
const [content, setContent] = useState('');
Expand Down Expand Up @@ -34,7 +34,7 @@ const Editor: React.FunctionComponent<any> = (props: { saveContent: (content: st
const toSave = props.isFull ? smfVars.smfEditorHandler.instance(textArea.current).val() : content;

if (toSave.length === 0) {
showErrorMessage(smfTextVars.error.errorEmpty);
showError(smfTextVars.error.errorEmpty);

return;
}
Expand Down
Loading

0 comments on commit 2bc71e9

Please sign in to comment.