Skip to content

Commit

Permalink
Merge branch 'main' into notesList
Browse files Browse the repository at this point in the history
  • Loading branch information
shvkhzod authored Jan 24, 2024
2 parents da382c2 + 87f6958 commit b9b380a
Show file tree
Hide file tree
Showing 39 changed files with 870 additions and 101 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ on:
branches:
- 'main'
pull_request:
types:
- opened
- synchronize
- edited
types: [opened, synchronize, reopened]

jobs:
build:
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/eslint-check.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
name: Run eslint check
name: ESLint

on:
push:
branches:
- 'main'
pull_request:
types:
- opened
- synchronize
- edited
types: [opened, synchronize, reopened]

jobs:
eslint:
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/send-test-results.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Send check results to CodeX chat

on:
push:
branches:
- 'main'

pull_request:
types: [opened, synchronize, reopened]

jobs:
send-message:
permissions:
actions: write
runs-on: ubuntu-22.04
env:
API_URL: "https://api.github.com/repos/${{ github.repository }}/actions/runs"
steps:
- name: Set commit_sha to pull request head sha
if: ${{ github.event_name == 'pull_request' }}
run: echo "COMMIT_SHA=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV

- name: Set commit_sha to pushed commit sha
if: ${{ github.event_name == 'push' }}
run: echo "COMMIT_SHA=${{ github.sha }}" >> $GITHUB_ENV

- name: Wait for other checks to succeed
uses: lewagon/[email protected]
with:
ref: ${{ env.COMMIT_SHA }}
running-workflow-name: send-message
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 3
allowed-conclusions: success,skipped,cancelled,failure

# Find results of the actions with the same SHA as this action via github api and set them to env variable
- name: Get actions results
run: |
echo 'ACTIONS_RESULTS<<0x0a' >> $GITHUB_ENV
curl -s -X GET -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}"\
"$API_URL" | jq -r '.workflow_runs[] | select(((.head_sha=="${{ env.COMMIT_SHA }}") and (.id != ${{ github.run_id }}))
and ((.conclusion == "success") or (.conclusion == "failure"))) | "\(.conclusion) [\(.name)](\(.html_url))" |
gsub("success"; "✅") | gsub("failure"; "❌")' >> $GITHUB_ENV
echo '0x0a' >> $GITHUB_ENV
# Stop if all checks were skipped/cancelled
- name: Stop this workflow if none of the results have conclusion "success" or "failure"
if: ${{ env.ACTIONS_RESULTS == '' }}
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
${{ env.API_URL }}/${{ github.run_id }}/cancel
- name: Send a message
uses: codex-team/action-codexbot-notify@v1
with:
webhook: ${{ secrets.CODEX_BOT_NOTIFY_NOTES_CHAT }}
message: "${{ env.ACTIONS_RESULTS }}"
parse_mode: 'markdown'
disable_web_page_preview: true
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"jwt-decode": "^3.1.2",
"normalize.css": "^8.0.1",
"typescript-cookie": "^1.0.6",
"unhead": "^1.8.3",
"vue": "^3.3.4",
"vue-i18n": "^9.2.2",
"vue-router": "^4.2.4"
Expand Down
23 changes: 18 additions & 5 deletions src/application/i18n/messages/en.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
{
"appTitle": "NoteX",
"auth": {
"login": "Login"
},
"settings": {
"title": "Settings",
"changeTheme": "Change theme"
"login": "Login",
"logout": "Logout"
},
"header": {
"buttons": {
"home": "Home",
"noteSettings": "Settings"
}
},
"userSettings": {
"title": "User Settings",
"changeTheme": "Change theme",
"userEditorTools": "User editor tools"
},
"noteSettings": {
"title": "Note Settings"
},
"note": {
"new": "New Note"
},
"home": {
"title": "Recent Notes"
},
"errors": {
"404": "Page not found",
"500": "Unknown error happened",
"default": "Something went wrong"
},
"marketplace": {
"title": "Marketplace",
"listOfTools": "Tools"
}
}
5 changes: 5 additions & 0 deletions src/application/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Landing from '@/presentation/pages/Landing.vue';
import Settings from '@/presentation/pages/Settings.vue';
import NoteSettings from '@/presentation/pages/NoteSettings.vue';
import ErrorPage from '@/presentation/pages/Error.vue';
import Marketplace from '@/presentation/pages/Marketplace.vue';
import type { RouteRecordRaw } from 'vue-router';

// Default production hostname for homepage. If different, then custom hostname used
Expand Down Expand Up @@ -55,6 +56,10 @@ const routes: RouteRecordRaw[] = [
id: String(route.params.id),
}),
},
{
path: `/marketplace`,
component: Marketplace,
},
/**
* 404 page
*/
Expand Down
19 changes: 17 additions & 2 deletions src/application/services/useAppState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AppStateController } from '@/domain';
import type EditorTool from '@/domain/entities/EditorTool';
import type { User } from '@/domain/entities/User';
import { createSharedComposable } from '@vueuse/core';
import { type Ref, ref } from 'vue';
Expand All @@ -11,6 +12,11 @@ interface UseAppStateComposable {
* Current authenticated user
*/
user: Ref<User | null>;

/**
* User editor tools that are used in notes creation
*/
userEditorTools: Ref<EditorTool[]>
}

/**
Expand All @@ -22,17 +28,26 @@ export const useAppState = createSharedComposable((): UseAppStateComposable => {
*/
const user = ref<User | null>(null);

/**
* User editor tools that are used in notes creation
*/
const userEditorTools = ref<EditorTool[]>([]);

/**
* Subscribe to user changes in the App State
*/
AppStateController.user((prop: 'user', value: User | null) => {
AppStateController.user((prop: 'user' | 'editorTools', value: User | EditorTool[] | null) => {
if (prop === 'user') {
user.value = value;
user.value = value as User;
}
if (prop === 'editorTools') {
userEditorTools.value = value as EditorTool[];
}
});


return {
user,
userEditorTools,
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ interface UseOAuthComposableState {
* Shows a popup window with google authorization
*/
showGoogleAuthPopup: () => void;
/**
* Logs out the user
*/
logout: () => Promise<void>;
}

/**
* Methods for working with OAuth (Google)
* Methods for working with Auth
*/
export default function useOAuth(): UseOAuthComposableState {
export default function useAuth(): UseOAuthComposableState {
/**
* Google OAuth URL
*/
Expand Down Expand Up @@ -54,8 +58,16 @@ export default function useOAuth(): UseOAuthComposableState {
}
});
}
/**
*Logs out the user by deleting the refresh token in local strorage
*/
async function logout(): Promise<void> {
await authService.logout();
}

return {
showGoogleAuthPopup,
logout,
};
}

35 changes: 35 additions & 0 deletions src/application/services/useMarketplace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type EditorTool from '@/domain/entities/EditorTool';
import { type Ref, ref, onMounted } from 'vue';
import { marketplaceService } from '@/domain';

/**
* Composable for the application state
*/
interface UseMarketplaceComposable {
/**
* All editor tools that are used in notes creation
*/
tools: Ref<EditorTool[]>
}

/**
* Application service for working with the Editor Tools
*/
export default function (): UseMarketplaceComposable {
/**
* All editor tools
*/
const tools = ref<EditorTool[]>([]);

/**
* Get list of all tools
*/
onMounted(async () => {
tools.value = await marketplaceService.getAllTools();
});


return {
tools: tools,
};
}
43 changes: 40 additions & 3 deletions src/application/services/useNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ interface UseNoteComposableState {
* Load note by custom hostname
*/
resolveHostname: () => Promise<void>;

/**
* Defines if user can edit note
*/
canEdit: Ref<boolean>;

/**
* Title for bookmarks in the browser
*/
noteTitle: Ref<string>;
}

interface UseNoteComposableOptions {
Expand Down Expand Up @@ -87,6 +97,27 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
*/
const router = useRouter();

/**
* Note Title identifier
*/
const limitCharsForNoteTitle = 50;
const noteTitle = computed(() => {
const firstNoteBlock = note.value?.content.blocks[0];

if (!firstNoteBlock || !(Boolean(firstNoteBlock.data.text))) {
return 'Note';
} else {
return firstNoteBlock.data.text.slice(0, limitCharsForNoteTitle);
}
});

/**
* Editing rights for the currently opened note
*
* true by default
*/
const canEdit = ref<boolean>(true);

/**
* Load note by id
*
Expand All @@ -96,8 +127,11 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
/**
* @todo try-catch domain errors
*/
note.value = await noteService.getNoteById(id);
};
const response = await noteService.getNoteById(id);

note.value = response.note;
canEdit.value = response.accessRights.canEdit;
}

/**
* Saves the note
Expand Down Expand Up @@ -136,7 +170,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
* Get note by custom hostname
*/
const resolveHostname = async (): Promise<void> => {
note.value = await noteService.getNoteByHostname(location.hostname);
note.value = (await noteService.getNoteByHostname(location.hostname)).note;
};

onMounted(() => {
Expand All @@ -155,6 +189,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
*/
if (newId === null) {
note.value = createDraft();
canEdit.value = true;

return;
}
Expand All @@ -172,6 +207,8 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt

return {
note,
noteTitle,
canEdit,
resolveHostname,
save,
};
Expand Down
30 changes: 30 additions & 0 deletions src/application/services/useUserSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { userService } from '@/domain';

/**
* User settings hook state
*/
interface UseUserSettingsComposableState {
/**
* Add tool to the user settings
*/
addTool(id: string): void
}


/**
* Methods for working with user settings
*/
export function useUserSettings(): UseUserSettingsComposableState {
/**
* Add tool to the user settings
*
* @param id - Tool identifier
*/
function addTool(id: string): void {
userService.addTool(id);
}

return {
addTool,
};
}
Loading

0 comments on commit b9b380a

Please sign in to comment.