Skip to content
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

Test sit #49

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"useTabs": false,
"tabWidth": 2,
"trailingComma": "es5",
"semi": true,
"singleQuote": true,
"vueIndentScriptAndStyle": true,
"printWidth": 80,
"singleAttributePerLine": true,
"bracketSameLine": false,
"endOfLine": "lf"
}
24 changes: 24 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Nuxt dev/build outputs
.output
.data
.nuxt
.nitro
.cache
dist

# Node dependencies
node_modules

# Logs
logs
*.log

# Misc
.DS_Store
.fleet
.idea

# Local env files
.env
.env.*
!.env.example
75 changes: 75 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Nuxt Minimal Starter

Look at the [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.

## Setup

Make sure to install dependencies:

```bash
# npm
npm install

# pnpm
pnpm install

# yarn
yarn install

# bun
bun install
```

## Development Server

Start the development server on `http://localhost:3000`:

```bash
# npm
npm run dev

# pnpm
pnpm dev

# yarn
yarn dev

# bun
bun run dev
```

## Production

Build the application for production:

```bash
# npm
npm run build

# pnpm
pnpm build

# yarn
yarn build

# bun
bun run build
```

Locally preview production build:

```bash
# npm
npm run preview

# pnpm
pnpm preview

# yarn
yarn preview

# bun
bun run preview
```

Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.
3 changes: 3 additions & 0 deletions test/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<NuxtLayout />
</template>
47 changes: 47 additions & 0 deletions test/components/ItemList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script setup lang="ts">
import { defineProps } from 'vue';

const props = defineProps({
items: {
type: Array,
required: true,
},
title: {
type: String,
required: true,
},
onSelect: {
type: Function,
required: true,
},
});
</script>

<template>
<div>
<h3>{{ title }}</h3>
<div class="items">
<button
v-for="item in items"
:key="item.id"
@click="onSelect(item)"
class="item-button"
>
{{ item.name }}
</button>
</div>
</div>
</template>

<style scoped>
.items {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.item-button {
border: 1px solid #ccc;
padding: 10px;
cursor: pointer;
}
</style>
3 changes: 3 additions & 0 deletions test/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<NuxtPage />
</template>
6 changes: 6 additions & 0 deletions test/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2024-04-03',
modules: ['@pinia/nuxt'],
devtools: { enabled: true }
})
19 changes: 19 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "nuxt-app",
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
},
"dependencies": {
"@pinia/nuxt": "^0.7.0",
"nuxt": "^3.14.159",
"vue": "latest",
"vue-router": "latest"
},
"packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
}
51 changes: 51 additions & 0 deletions test/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script setup lang="ts">
import { useItemsStore } from '~/store/items';
import ItemList from '~/components/ItemList.vue';

const itemsStore = useItemsStore();
</script>

<template>
<div>
<div class="top-blocks">
<div>
<h2>Выбранные вещи пользователя</h2>
<div>
<p
v-for="item in itemsStore.selectedUserItems"
:key="item.id"
>
{{ item.name }}
</p>
</div>
</div>
<div>
<h2>Выбранная вещь</h2>
<p v-if="itemsStore.selectedSelectableItem">
{{ itemsStore.selectedSelectableItem.name }}
</p>
</div>
</div>
<div class="bottom-blocks">
<ItemList
:title="'User Items'"
:items="itemsStore.userItems"
:onSelect="itemsStore.selectUserItem"
/>
<ItemList
:title="'Selectable Items'"
:items="itemsStore.selectableItems"
:onSelect="itemsStore.selectSelectableItem"
/>
</div>
</div>
</template>

<style scoped>
.top-blocks,
.bottom-blocks {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}
</style>
Binary file added test/public/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions test/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions test/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../.nuxt/tsconfig.server.json"
}
59 changes: 59 additions & 0 deletions test/store/items.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { defineStore } from 'pinia';

interface Item {
id: number;
name: string;
}

export const useItemsStore = defineStore('items', {
state: () => ({
userItems: [
{ id: 1, name: 'Shoes 1' },
{ id: 2, name: 'Shoes 2' },
{ id: 3, name: 'Shoes 3' },
{ id: 4, name: 'Shoes 4' },
{ id: 5, name: 'T-shirt 1' },
{ id: 6, name: 'T-shirt 2' },
{ id: 7, name: 'T-shirt 3' },
{ id: 8, name: 'T-shirt 4' },
] as Item[],
selectableItems: [
{ id: 11, name: 'Jacket 1' },
{ id: 12, name: 'Jacket 2' },
{ id: 13, name: 'Jacket 3' },
{ id: 14, name: 'Jacket 4' },
{ id: 15, name: 'Hoodie 1' },
{ id: 16, name: 'Hoodie 2' },
{ id: 17, name: 'Hoodie 3' },
{ id: 18, name: 'Hoodie 4' },
] as Item[],
selectedUserItems: [] as Item[],
selectedSelectableItem: null as Item | null,
}),

actions: {
selectUserItem(item: Item) {
const itemExists = this.selectedUserItems.find(
(selected) => selected.id === item.id
);

if (!itemExists) {
// Если длина больше 6, удаляем первый элемент
if (this.selectedUserItems.length >= 6) {
this.selectedUserItems.shift();
}
this.selectedUserItems.push(item);
}
},

deselectUserItem(item: Item) {
this.selectedUserItems = this.selectedUserItems.filter(
(selected) => selected.id !== item.id
);
},

selectSelectableItem(item: Item) {
this.selectedSelectableItem = item;
},
},
});
4 changes: 4 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}
Loading